Debian Codegraph @

tools/CMakeLists.txt

raw
1 include_directories(${CGREEN_PUBLIC_INCLUDE_DIRS} ${PROJECT_BINARY_DIR} ${CURRENT_BINARY_DIR})
2
3 set(RUNNER_SRCS
4 ${CMAKE_CURRENT_SOURCE_DIR}/cgreen-runner.c
5 ${CMAKE_CURRENT_SOURCE_DIR}/gopt.c
6 ${CMAKE_CURRENT_SOURCE_DIR}/gopt-errors.c
7 ${CMAKE_CURRENT_SOURCE_DIR}/runner.c
8 ${CMAKE_CURRENT_SOURCE_DIR}/discoverer.c
9 ${CMAKE_CURRENT_SOURCE_DIR}/test_item.c
10 ${CMAKE_CURRENT_SOURCE_DIR}/io.c
11 )
12 set_source_files_properties(${RUNNER_SRCS} PROPERTIES LANGUAGE C)
13
14 # Do we have an "nm"?
15 include(FindNm)
16
17 if (NM_FOUND)
18 set_source_files_properties(discoverer.c PROPERTIES COMPILE_FLAGS -DNM_EXECUTABLE='\"${NM_EXECUTABLE}\"')
19
20 include(DefineRelativeFilePaths)
21 cmake_define_relative_file_paths("${RUNNER_SRCS}")
22
23 add_executable(cgreen-runner ${RUNNER_SRCS})
24 target_link_libraries(cgreen-runner ${CGREEN_LIBRARY} $<$<BOOL:${CGREEN_WITH_LIBXML2}>:${LIBXML2_LIBRARIES}> ${CMAKE_DL_LIBS})
25
26 if(APPLE)
27 set_target_properties(cgreen-runner PROPERTIES
28 BUILD_RPATH "@loader_path/../src"
29 INSTALL_RPATH "@loader_path/../lib"
30 )
31 elseif(UNIX)
32 set_target_properties(cgreen-runner PROPERTIES
33 BUILD_RPATH "\$ORIGIN/../src"
34 INSTALL_RPATH "\$ORIGIN/../lib"
35 )
36 endif()
37
38 install(TARGETS cgreen-runner
39 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
40 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
41 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
42 DESTINATION ${CMAKE_INSTALL_BINDIR}
43 )
44
45 install(PROGRAMS cgreen-debug
46 DESTINATION ${CMAKE_INSTALL_BINDIR})
47
48 set(CGREEN_RUNNER_TESTS_LIBRARY
49 cgreen_runner_tests
50 CACHE INTERNAL "cgreen-runner tests shared library"
51 )
52 set(RUNNER_TESTS_SRCS
53 runner_unit_tests.c
54 test_item.c
55 )
56 add_library(${CGREEN_RUNNER_TESTS_LIBRARY} SHARED ${RUNNER_TESTS_SRCS})
57 target_link_libraries(${CGREEN_RUNNER_TESTS_LIBRARY} ${CGREEN_LIBRARY})
58
59 # Due to some (of many) CMake irregularities to reference the test libraries
60 # we can't just use its CMake name variable, but have to look it up with
61 # some special attributes of the library:
62 # $<TARGET_FILE_DIR:the_lib>/$<TARGET_FILE_NAME:the_lib>
63 #
64 SET(CGREEN_RUNNER_TESTS_LIBRARY "$<TARGET_FILE_DIR:cgreen_runner_tests>/$<TARGET_FILE_NAME:cgreen_runner_tests>")
65
66 macro_add_test(NAME cgreen_runner_unit_tests
67 COMMAND cgreen-runner ${CGREEN_RUNNER_TESTS_LIBRARY})
68
69 macro_add_test(NAME cgreen_runner_usage
70 COMMAND cgreen-runner --help)
71
72 macro_add_test(NAME cgreen_runner_quiet
73 COMMAND cgreen-runner -q ${CGREEN_RUNNER_TESTS_LIBRARY})
74
75 macro_add_test(NAME cgreen_runner_verbose
76 COMMAND cgreen-runner -v -C ${CGREEN_RUNNER_TESTS_LIBRARY})
77
78 macro_add_test(NAME cgreen_runner_version
79 COMMAND cgreen-runner --version)
80
81 macro_add_test(NAME cgreen_runner_single_explicit_named_test
82 COMMAND cgreen-runner $<TARGET_FILE_DIR:cgreen_runner_tests>/$<TARGET_FILE_NAME:cgreen_runner_tests> Runner:can_match_test_name)
83
84 macro_add_test(NAME cgreen_runner_patternmatched_testnames
85 COMMAND cgreen-runner $<TARGET_FILE_DIR:cgreen_runner_tests>/$<TARGET_FILE_NAME:cgreen_runner_tests> Runner:can*)
86
87 macro_add_test(NAME cgreen_runner_suite_name
88 COMMAND cgreen-runner -s Suite ${CGREEN_RUNNER_TESTS_LIBRARY})
89
90 macro_add_test(NAME cgreen_runner_fail_on_non_existing_library
91 COMMAND cgreen-runner Suite non_existent_library)
92 set_tests_properties(cgreen_runner_fail_on_non_existing_library PROPERTIES WILL_FAIL true)
93
94 macro_add_test(NAME cgreen_runner_fail_on_non_existing_library_with_suite
95 COMMAND cgreen-runner -s Suite non_existent_library
96 WILL_FAIL)
97 set_tests_properties(cgreen_runner_fail_on_non_existing_library_with_suite PROPERTIES WILL_FAIL true)
98
99 macro_add_test(NAME cgreen_runner_patternmatched_testnames_in_patternmatched_context
100 COMMAND cgreen-runner $<TARGET_FILE_DIR:cgreen_runner_tests>/$<TARGET_FILE_NAME:cgreen_runner_tests> Run*:can*)
101
102 macro_add_test(NAME cgreen_runner_wildcarded_tests_in_named_context
103 COMMAND cgreen-runner $<TARGET_FILE_DIR:cgreen_runner_tests>/$<TARGET_FILE_NAME:cgreen_runner_tests> Runner:*)
104
105 macro_add_test(NAME cgreen_runner_wildcarded_tests_in_wildcarded_context
106 COMMAND cgreen-runner $<TARGET_FILE_DIR:cgreen_runner_tests>/$<TARGET_FILE_NAME:cgreen_runner_tests> *:*)
107
108 if (CGREEN_WITH_XML)
109 macro_add_test(NAME cgreen_runner_with_xml_reporter
110 COMMAND cgreen-runner --xml TEST --suite cgreen_runner_tests $<TARGET_FILE_DIR:cgreen_runner_tests>/$<TARGET_FILE_NAME:cgreen_runner_tests>)
111 endif (CGREEN_WITH_XML)
112
113 if (CGREEN_WITH_LIBXML2)
114 macro_add_test(NAME cgreen_runner_with_libxml2_reporter
115 COMMAND cgreen-runner --libxml2 TEST --suite cgreen_runner_tests $<TARGET_FILE_DIR:cgreen_runner_tests>/$<TARGET_FILE_NAME:cgreen_runner_tests>)
116 endif (CGREEN_WITH_LIBXML2)
117
118 macro_add_test(NAME cgreen_runner_multiple_libraries
119 COMMAND cgreen-runner ${CGREEN_RUNNER_TESTS_LIBRARY} ${CGREEN_RUNNER_TESTS_LIBRARY} ${CGREEN_RUNNER_TESTS_LIBRARY})
120
121 else()
122 message("No 'nm' found on this system. 'cgreen-runner' will not be built.")
123 endif()