Radek Krejci | cb293a3 | 2020-11-13 15:36:29 +0100 | [diff] [blame] | 1 | # yanglint |
| 2 | |
Jan Kundrát | 2e3f935 | 2021-12-11 02:16:27 +0100 | [diff] [blame] | 3 | if(WIN32) |
| 4 | set(YANGLINT_INTERACTIVE OFF) |
| 5 | else() |
| 6 | set(YANGLINT_INTERACTIVE ON) |
| 7 | endif() |
| 8 | |
Radek Krejci | cb293a3 | 2020-11-13 15:36:29 +0100 | [diff] [blame] | 9 | set(lintsrc |
Radek Krejci | cb293a3 | 2020-11-13 15:36:29 +0100 | [diff] [blame] | 10 | main_ni.c |
Radek Krejci | e9f13b1 | 2020-11-09 17:42:04 +0100 | [diff] [blame] | 11 | cmd.c |
| 12 | cmd_add.c |
| 13 | cmd_clear.c |
| 14 | cmd_data.c |
| 15 | cmd_list.c |
Michal Vasko | 538be42 | 2021-10-19 14:06:59 +0200 | [diff] [blame] | 16 | cmd_feature.c |
Radek Krejci | e9f13b1 | 2020-11-09 17:42:04 +0100 | [diff] [blame] | 17 | cmd_load.c |
| 18 | cmd_print.c |
| 19 | cmd_searchpath.c |
| 20 | common.c |
Jan Kundrát | 2e3f935 | 2021-12-11 02:16:27 +0100 | [diff] [blame] | 21 | ) |
| 22 | if(YANGLINT_INTERACTIVE) |
| 23 | set(lintsrc ${lintsrc} |
| 24 | main.c |
| 25 | completion.c |
| 26 | configuration.c |
| 27 | linenoise/linenoise.c) |
| 28 | else() |
| 29 | set(lintsrc ${lintsrc} |
| 30 | main_ni_only.c) |
| 31 | endif() |
Radek Krejci | cb293a3 | 2020-11-13 15:36:29 +0100 | [diff] [blame] | 32 | |
| 33 | set(format_sources |
| 34 | ${format_sources} |
| 35 | ${CMAKE_CURRENT_SOURCE_DIR}/*.c |
| 36 | ${CMAKE_CURRENT_SOURCE_DIR}/*.h |
| 37 | PARENT_SCOPE) |
Michal Vasko | b3b3afc | 2020-11-25 09:52:26 +0100 | [diff] [blame] | 38 | |
Michal Vasko | 1b0b9a1 | 2021-05-06 08:38:34 +0200 | [diff] [blame] | 39 | add_executable(yanglint ${lintsrc} ${compatsrc}) |
Radek Krejci | cb293a3 | 2020-11-13 15:36:29 +0100 | [diff] [blame] | 40 | target_link_libraries(yanglint yang) |
| 41 | install(TARGETS yanglint DESTINATION ${CMAKE_INSTALL_BINDIR}) |
| 42 | install(FILES ${PROJECT_SOURCE_DIR}/tools/lint/yanglint.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) |
| 43 | target_include_directories(yanglint BEFORE PRIVATE ${PROJECT_BINARY_DIR}) |
| 44 | |
Jan Kundrát | f0bd0b6 | 2021-12-11 02:23:51 +0100 | [diff] [blame] | 45 | if(WIN32) |
Jan Kundrát | f0bd0b6 | 2021-12-11 02:23:51 +0100 | [diff] [blame] | 46 | target_include_directories(yanglint PRIVATE ${GETOPT_INCLUDE_DIR}) |
| 47 | target_link_libraries(yanglint ${GETOPT_LIBRARY}) |
| 48 | endif() |
| 49 | |
Radek Krejci | e868acc | 2020-11-13 16:42:58 +0100 | [diff] [blame] | 50 | # |
| 51 | # tests |
| 52 | # |
| 53 | function(add_yanglint_test) |
Jan Kundrát | d4ddd12 | 2022-08-22 19:12:25 +0200 | [diff] [blame] | 54 | cmake_parse_arguments(ADDTEST "" "NAME;VIA;SCRIPT" "" ${ARGN}) |
Radek Krejci | e868acc | 2020-11-13 16:42:58 +0100 | [diff] [blame] | 55 | set(TEST_NAME yanglint_${ADDTEST_NAME}) |
| 56 | |
Jan Kundrát | d4ddd12 | 2022-08-22 19:12:25 +0200 | [diff] [blame] | 57 | if(${ADDTEST_VIA} STREQUAL "bash") |
| 58 | set(WRAPPER /usr/bin/env bash) |
| 59 | elseif(${ADDTEST_VIA} STREQUAL "expect") |
| 60 | set(WRAPPER ${PATH_EXPECT}) |
| 61 | else() |
| 62 | message(FATAL_ERROR "build: unexpected wrapper '${ADDTEST_VIA}'") |
| 63 | endif() |
| 64 | |
| 65 | add_test(NAME ${TEST_NAME} COMMAND ${WRAPPER} ${CMAKE_CURRENT_SOURCE_DIR}/tests/${ADDTEST_SCRIPT}) |
Michal Vasko | b3b3afc | 2020-11-25 09:52:26 +0100 | [diff] [blame] | 66 | set_property(TEST ${TEST_NAME} APPEND PROPERTY ENVIRONMENT "YANGLINT=${PROJECT_BINARY_DIR}/yanglint") |
roman | 300b878 | 2022-08-11 12:49:21 +0200 | [diff] [blame] | 67 | set_property(TEST ${TEST_NAME} APPEND PROPERTY ENVIRONMENT "YANG_MODULES_DIR=${PROJECT_SOURCE_DIR}/tests/modules/yang") |
Radek Krejci | e868acc | 2020-11-13 16:42:58 +0100 | [diff] [blame] | 68 | endfunction(add_yanglint_test) |
| 69 | |
Michal Vasko | cdffdab | 2021-06-23 14:00:10 +0200 | [diff] [blame] | 70 | if(ENABLE_TESTS) |
Radek Iša | 2227c66 | 2020-11-25 16:13:09 +0100 | [diff] [blame] | 71 | # tests of non-interactive mode using shunit2 |
| 72 | find_program(PATH_SHUNIT NAMES shunit2) |
| 73 | if(NOT PATH_SHUNIT) |
| 74 | message(WARNING "'shunit2' not found! The yanglint(1) non-interactive tests will not be available.") |
| 75 | else() |
Jan Kundrát | d4ddd12 | 2022-08-22 19:12:25 +0200 | [diff] [blame] | 76 | add_yanglint_test(NAME ni_list VIA bash SCRIPT shunit2/list.sh) |
| 77 | add_yanglint_test(NAME ni_feature VIA bash SCRIPT shunit2/feature.sh) |
Radek Iša | 2227c66 | 2020-11-25 16:13:09 +0100 | [diff] [blame] | 78 | endif() |
Radek Krejci | e868acc | 2020-11-13 16:42:58 +0100 | [diff] [blame] | 79 | |
Radek Iša | 2227c66 | 2020-11-25 16:13:09 +0100 | [diff] [blame] | 80 | # tests of interactive mode using expect |
| 81 | find_program(PATH_EXPECT NAMES expect) |
| 82 | if(NOT PATH_EXPECT) |
| 83 | message(WARNING "'expect' not found! The yanglint(1) interactive tests will not be available.") |
Jan Kundrát | 2e3f935 | 2021-12-11 02:16:27 +0100 | [diff] [blame] | 84 | elseif(YANGLINT_INTERACTIVE) |
Jan Kundrát | d4ddd12 | 2022-08-22 19:12:25 +0200 | [diff] [blame] | 85 | add_yanglint_test(NAME in_list VIA expect SCRIPT expect/list.exp) |
| 86 | add_yanglint_test(NAME in_feature VIA expect SCRIPT expect/feature.exp) |
Radek Iša | 2227c66 | 2020-11-25 16:13:09 +0100 | [diff] [blame] | 87 | endif() |
Radek Krejci | e868acc | 2020-11-13 16:42:58 +0100 | [diff] [blame] | 88 | endif() |