blob: 0fd2fad601f9f194058ee89916f77bf8ded090c8 [file] [log] [blame]
Radek Krejcicb293a32020-11-13 15:36:29 +01001# yanglint
2
Jan Kundrát2e3f9352021-12-11 02:16:27 +01003if(WIN32)
4 set(YANGLINT_INTERACTIVE OFF)
5else()
6 set(YANGLINT_INTERACTIVE ON)
7endif()
8
Radek Krejcicb293a32020-11-13 15:36:29 +01009set(lintsrc
Radek Krejcicb293a32020-11-13 15:36:29 +010010 main_ni.c
Radek Krejcie9f13b12020-11-09 17:42:04 +010011 cmd.c
12 cmd_add.c
13 cmd_clear.c
14 cmd_data.c
15 cmd_list.c
Michal Vasko538be422021-10-19 14:06:59 +020016 cmd_feature.c
Radek Krejcie9f13b12020-11-09 17:42:04 +010017 cmd_load.c
18 cmd_print.c
19 cmd_searchpath.c
aPiecek647f62e2023-05-18 10:55:58 +020020 cmd_extdata.c
Radek Krejcie9f13b12020-11-09 17:42:04 +010021 common.c
Jan Kundrát2e3f9352021-12-11 02:16:27 +010022)
23if(YANGLINT_INTERACTIVE)
24 set(lintsrc ${lintsrc}
25 main.c
26 completion.c
27 configuration.c
28 linenoise/linenoise.c)
29else()
30 set(lintsrc ${lintsrc}
31 main_ni_only.c)
32endif()
Radek Krejcicb293a32020-11-13 15:36:29 +010033
34set(format_sources
35 ${format_sources}
36 ${CMAKE_CURRENT_SOURCE_DIR}/*.c
37 ${CMAKE_CURRENT_SOURCE_DIR}/*.h
38 PARENT_SCOPE)
Michal Vaskob3b3afc2020-11-25 09:52:26 +010039
Michal Vasko1b0b9a12021-05-06 08:38:34 +020040add_executable(yanglint ${lintsrc} ${compatsrc})
Radek Krejcicb293a32020-11-13 15:36:29 +010041target_link_libraries(yanglint yang)
42install(TARGETS yanglint DESTINATION ${CMAKE_INSTALL_BINDIR})
43install(FILES ${PROJECT_SOURCE_DIR}/tools/lint/yanglint.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
44target_include_directories(yanglint BEFORE PRIVATE ${PROJECT_BINARY_DIR})
45
Jan Kundrátf0bd0b62021-12-11 02:23:51 +010046if(WIN32)
Jan Kundrátf0bd0b62021-12-11 02:23:51 +010047 target_include_directories(yanglint PRIVATE ${GETOPT_INCLUDE_DIR})
48 target_link_libraries(yanglint ${GETOPT_LIBRARY})
49endif()
50
Radek Krejcie868acc2020-11-13 16:42:58 +010051#
52# tests
53#
54function(add_yanglint_test)
Jan Kundrátd4ddd122022-08-22 19:12:25 +020055 cmake_parse_arguments(ADDTEST "" "NAME;VIA;SCRIPT" "" ${ARGN})
Radek Krejcie868acc2020-11-13 16:42:58 +010056 set(TEST_NAME yanglint_${ADDTEST_NAME})
57
aPiecek266ca762023-03-22 15:04:59 +010058 if(${ADDTEST_VIA} STREQUAL "tclsh")
59 set(WRAPPER ${PATH_TCLSH})
Jan Kundrátd4ddd122022-08-22 19:12:25 +020060 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})
aPiecek266ca762023-03-22 15:04:59 +010065 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 Vaskob3b3afc2020-11-25 09:52:26 +010067 set_property(TEST ${TEST_NAME} APPEND PROPERTY ENVIRONMENT "YANGLINT=${PROJECT_BINARY_DIR}/yanglint")
Radek Krejcie868acc2020-11-13 16:42:58 +010068endfunction(add_yanglint_test)
69
Michal Vaskocdffdab2021-06-23 14:00:10 +020070if(ENABLE_TESTS)
aPiecek266ca762023-03-22 15:04:59 +010071 # 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át2e3f9352021-12-11 02:16:27 +010075 elseif(YANGLINT_INTERACTIVE)
aPiecek266ca762023-03-22 15:04:59 +010076 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ša2227c662020-11-25 16:13:09 +010078 endif()
Radek Krejcie868acc2020-11-13 16:42:58 +010079endif()