blob: 87239960280c870c6950eb25a17e566612f175dc [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)
54 cmake_parse_arguments(ADDTEST "" "NAME;SCRIPT" "" ${ARGN})
55 set(TEST_NAME yanglint_${ADDTEST_NAME})
56
Michal Vaskob3b3afc2020-11-25 09:52:26 +010057 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 Krejcie868acc2020-11-13 16:42:58 +010059endfunction(add_yanglint_test)
60
Michal Vaskocdffdab2021-06-23 14:00:10 +020061if(ENABLE_TESTS)
Radek Iša2227c662020-11-25 16:13:09 +010062 # 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 Krejcie868acc2020-11-13 16:42:58 +010069
Radek Iša2227c662020-11-25 16:13:09 +010070 # 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át2e3f9352021-12-11 02:16:27 +010074 elseif(YANGLINT_INTERACTIVE)
Michal Vaskof8735982022-08-10 15:25:57 +020075 add_yanglint_test(NAME in_list SCRIPT expect/list.exp)
Radek Iša2227c662020-11-25 16:13:09 +010076 endif()
Radek Krejcie868acc2020-11-13 16:42:58 +010077endif()