blob: 32cdcbf602c7d5e87e6c55caeee8aab91244ecdb [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
20 common.c
Jan Kundrát2e3f9352021-12-11 02:16:27 +010021)
22if(YANGLINT_INTERACTIVE)
23 set(lintsrc ${lintsrc}
24 main.c
25 completion.c
26 configuration.c
27 linenoise/linenoise.c)
28else()
29 set(lintsrc ${lintsrc}
30 main_ni_only.c)
31endif()
Radek Krejcicb293a32020-11-13 15:36:29 +010032
33set(format_sources
34 ${format_sources}
35 ${CMAKE_CURRENT_SOURCE_DIR}/*.c
36 ${CMAKE_CURRENT_SOURCE_DIR}/*.h
37 PARENT_SCOPE)
Michal Vaskob3b3afc2020-11-25 09:52:26 +010038
Michal Vasko1b0b9a12021-05-06 08:38:34 +020039add_executable(yanglint ${lintsrc} ${compatsrc})
Radek Krejcicb293a32020-11-13 15:36:29 +010040target_link_libraries(yanglint yang)
41install(TARGETS yanglint DESTINATION ${CMAKE_INSTALL_BINDIR})
42install(FILES ${PROJECT_SOURCE_DIR}/tools/lint/yanglint.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
43target_include_directories(yanglint BEFORE PRIVATE ${PROJECT_BINARY_DIR})
44
Jan Kundrátf0bd0b62021-12-11 02:23:51 +010045if(WIN32)
Jan Kundrátf0bd0b62021-12-11 02:23:51 +010046 target_include_directories(yanglint PRIVATE ${GETOPT_INCLUDE_DIR})
47 target_link_libraries(yanglint ${GETOPT_LIBRARY})
48endif()
49
Radek Krejcie868acc2020-11-13 16:42:58 +010050#
51# tests
52#
53function(add_yanglint_test)
Jan Kundrátd4ddd122022-08-22 19:12:25 +020054 cmake_parse_arguments(ADDTEST "" "NAME;VIA;SCRIPT" "" ${ARGN})
Radek Krejcie868acc2020-11-13 16:42:58 +010055 set(TEST_NAME yanglint_${ADDTEST_NAME})
56
Jan Kundrátd4ddd122022-08-22 19:12:25 +020057 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 Vaskob3b3afc2020-11-25 09:52:26 +010066 set_property(TEST ${TEST_NAME} APPEND PROPERTY ENVIRONMENT "YANGLINT=${PROJECT_BINARY_DIR}/yanglint")
roman300b8782022-08-11 12:49:21 +020067 set_property(TEST ${TEST_NAME} APPEND PROPERTY ENVIRONMENT "YANG_MODULES_DIR=${PROJECT_SOURCE_DIR}/tests/modules/yang")
romane84f7dc2022-10-21 10:25:38 +020068 set_property(TEST ${TEST_NAME} APPEND PROPERTY ENVIRONMENT "CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}")
Radek Krejcie868acc2020-11-13 16:42:58 +010069endfunction(add_yanglint_test)
70
Michal Vaskocdffdab2021-06-23 14:00:10 +020071if(ENABLE_TESTS)
Radek Iša2227c662020-11-25 16:13:09 +010072 # tests of non-interactive mode using shunit2
73 find_program(PATH_SHUNIT NAMES shunit2)
74 if(NOT PATH_SHUNIT)
75 message(WARNING "'shunit2' not found! The yanglint(1) non-interactive tests will not be available.")
76 else()
Jan Kundrátd4ddd122022-08-22 19:12:25 +020077 add_yanglint_test(NAME ni_list VIA bash SCRIPT shunit2/list.sh)
78 add_yanglint_test(NAME ni_feature VIA bash SCRIPT shunit2/feature.sh)
Radek Iša2227c662020-11-25 16:13:09 +010079 endif()
Radek Krejcie868acc2020-11-13 16:42:58 +010080
Radek Iša2227c662020-11-25 16:13:09 +010081 # tests of interactive mode using expect
82 find_program(PATH_EXPECT NAMES expect)
83 if(NOT PATH_EXPECT)
84 message(WARNING "'expect' not found! The yanglint(1) interactive tests will not be available.")
Jan Kundrát2e3f9352021-12-11 02:16:27 +010085 elseif(YANGLINT_INTERACTIVE)
Jan Kundrátd4ddd122022-08-22 19:12:25 +020086 add_yanglint_test(NAME in_list VIA expect SCRIPT expect/list.exp)
87 add_yanglint_test(NAME in_feature VIA expect SCRIPT expect/feature.exp)
romane84f7dc2022-10-21 10:25:38 +020088 add_yanglint_test(NAME in_completion VIA expect SCRIPT expect/completion.exp)
Radek Iša2227c662020-11-25 16:13:09 +010089 endif()
Radek Krejcie868acc2020-11-13 16:42:58 +010090endif()