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 |
aPiecek | 647f62e | 2023-05-18 10:55:58 +0200 | [diff] [blame] | 20 | cmd_extdata.c |
Radek Krejci | e9f13b1 | 2020-11-09 17:42:04 +0100 | [diff] [blame] | 21 | common.c |
Jan Kundrát | 2e3f935 | 2021-12-11 02:16:27 +0100 | [diff] [blame] | 22 | ) |
| 23 | if(YANGLINT_INTERACTIVE) |
| 24 | set(lintsrc ${lintsrc} |
| 25 | main.c |
| 26 | completion.c |
| 27 | configuration.c |
| 28 | linenoise/linenoise.c) |
| 29 | else() |
| 30 | set(lintsrc ${lintsrc} |
| 31 | main_ni_only.c) |
| 32 | endif() |
Radek Krejci | cb293a3 | 2020-11-13 15:36:29 +0100 | [diff] [blame] | 33 | |
| 34 | set(format_sources |
| 35 | ${format_sources} |
| 36 | ${CMAKE_CURRENT_SOURCE_DIR}/*.c |
| 37 | ${CMAKE_CURRENT_SOURCE_DIR}/*.h |
| 38 | PARENT_SCOPE) |
Michal Vasko | b3b3afc | 2020-11-25 09:52:26 +0100 | [diff] [blame] | 39 | |
Michal Vasko | 1b0b9a1 | 2021-05-06 08:38:34 +0200 | [diff] [blame] | 40 | add_executable(yanglint ${lintsrc} ${compatsrc}) |
Radek Krejci | cb293a3 | 2020-11-13 15:36:29 +0100 | [diff] [blame] | 41 | target_link_libraries(yanglint yang) |
| 42 | install(TARGETS yanglint DESTINATION ${CMAKE_INSTALL_BINDIR}) |
| 43 | install(FILES ${PROJECT_SOURCE_DIR}/tools/lint/yanglint.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) |
| 44 | target_include_directories(yanglint BEFORE PRIVATE ${PROJECT_BINARY_DIR}) |
| 45 | |
Jan Kundrát | f0bd0b6 | 2021-12-11 02:23:51 +0100 | [diff] [blame] | 46 | if(WIN32) |
Jan Kundrát | f0bd0b6 | 2021-12-11 02:23:51 +0100 | [diff] [blame] | 47 | target_include_directories(yanglint PRIVATE ${GETOPT_INCLUDE_DIR}) |
| 48 | target_link_libraries(yanglint ${GETOPT_LIBRARY}) |
| 49 | endif() |
| 50 | |
Radek Krejci | e868acc | 2020-11-13 16:42:58 +0100 | [diff] [blame] | 51 | # |
| 52 | # tests |
| 53 | # |
| 54 | function(add_yanglint_test) |
Jan Kundrát | d4ddd12 | 2022-08-22 19:12:25 +0200 | [diff] [blame] | 55 | cmake_parse_arguments(ADDTEST "" "NAME;VIA;SCRIPT" "" ${ARGN}) |
Radek Krejci | e868acc | 2020-11-13 16:42:58 +0100 | [diff] [blame] | 56 | set(TEST_NAME yanglint_${ADDTEST_NAME}) |
| 57 | |
aPiecek | 266ca76 | 2023-03-22 15:04:59 +0100 | [diff] [blame] | 58 | if(${ADDTEST_VIA} STREQUAL "tclsh") |
| 59 | set(WRAPPER ${PATH_TCLSH}) |
Jan Kundrát | d4ddd12 | 2022-08-22 19:12:25 +0200 | [diff] [blame] | 60 | else() |
| 61 | message(FATAL_ERROR "build: unexpected wrapper '${ADDTEST_VIA}'") |
| 62 | endif() |
| 63 | |
| 64 | add_test(NAME ${TEST_NAME} COMMAND ${WRAPPER} ${CMAKE_CURRENT_SOURCE_DIR}/tests/${ADDTEST_SCRIPT}) |
aPiecek | 266ca76 | 2023-03-22 15:04:59 +0100 | [diff] [blame] | 65 | set_property(TEST ${TEST_NAME} APPEND PROPERTY ENVIRONMENT "TESTS_DIR=${CMAKE_CURRENT_SOURCE_DIR}/tests") |
| 66 | set_property(TEST ${TEST_NAME} APPEND PROPERTY ENVIRONMENT "YANG_MODULES_DIR=${CMAKE_CURRENT_SOURCE_DIR}/tests/modules") |
Michal Vasko | b3b3afc | 2020-11-25 09:52:26 +0100 | [diff] [blame] | 67 | 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] | 68 | endfunction(add_yanglint_test) |
| 69 | |
Michal Vasko | cdffdab | 2021-06-23 14:00:10 +0200 | [diff] [blame] | 70 | if(ENABLE_TESTS) |
aPiecek | 266ca76 | 2023-03-22 15:04:59 +0100 | [diff] [blame] | 71 | # tests of interactive mode using tclsh |
| 72 | find_program(PATH_TCLSH NAMES tclsh) |
| 73 | if(NOT PATH_TCLSH) |
| 74 | message(WARNING "'tclsh' not found! The yanglint(1) interactive tests will not be available.") |
Jan Kundrát | 2e3f935 | 2021-12-11 02:16:27 +0100 | [diff] [blame] | 75 | elseif(YANGLINT_INTERACTIVE) |
aPiecek | 266ca76 | 2023-03-22 15:04:59 +0100 | [diff] [blame] | 76 | add_yanglint_test(NAME interactive VIA tclsh SCRIPT interactive/all.tcl) |
| 77 | add_yanglint_test(NAME non-interactive VIA tclsh SCRIPT non-interactive/all.tcl) |
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 | endif() |