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) |
| 54 | cmake_parse_arguments(ADDTEST "" "NAME;SCRIPT" "" ${ARGN}) |
| 55 | set(TEST_NAME yanglint_${ADDTEST_NAME}) |
| 56 | |
Michal Vasko | b3b3afc | 2020-11-25 09:52:26 +0100 | [diff] [blame] | 57 | add_test(NAME ${TEST_NAME} COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/${ADDTEST_SCRIPT}) |
| 58 | set_property(TEST ${TEST_NAME} APPEND PROPERTY ENVIRONMENT "YANGLINT=${PROJECT_BINARY_DIR}/yanglint") |
Radek Krejci | e868acc | 2020-11-13 16:42:58 +0100 | [diff] [blame] | 59 | endfunction(add_yanglint_test) |
| 60 | |
Michal Vasko | cdffdab | 2021-06-23 14:00:10 +0200 | [diff] [blame] | 61 | if(ENABLE_TESTS) |
Radek Iša | 2227c66 | 2020-11-25 16:13:09 +0100 | [diff] [blame] | 62 | # tests of non-interactive mode using shunit2 |
| 63 | find_program(PATH_SHUNIT NAMES shunit2) |
| 64 | if(NOT PATH_SHUNIT) |
| 65 | message(WARNING "'shunit2' not found! The yanglint(1) non-interactive tests will not be available.") |
| 66 | else() |
| 67 | add_yanglint_test(NAME ni_list SCRIPT shunit2/list.sh) |
| 68 | endif() |
Radek Krejci | e868acc | 2020-11-13 16:42:58 +0100 | [diff] [blame] | 69 | |
Radek Iša | 2227c66 | 2020-11-25 16:13:09 +0100 | [diff] [blame] | 70 | # tests of interactive mode using expect |
| 71 | find_program(PATH_EXPECT NAMES expect) |
| 72 | if(NOT PATH_EXPECT) |
| 73 | 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] | 74 | elseif(YANGLINT_INTERACTIVE) |
Michal Vasko | f873598 | 2022-08-10 15:25:57 +0200 | [diff] [blame^] | 75 | add_yanglint_test(NAME in_list SCRIPT expect/list.exp) |
Radek Iša | 2227c66 | 2020-11-25 16:13:09 +0100 | [diff] [blame] | 76 | endif() |
Radek Krejci | e868acc | 2020-11-13 16:42:58 +0100 | [diff] [blame] | 77 | endif() |