11include (CTest)
22
33file (GLOB test_sources test -*.cc)
4+ file (GLOB mock_sources mock/*.cc)
45
5- list (APPEND test_sources ${CMAKE_BINARY_DIR} /config.h)
6-
7- if (NOT OS_LINUX)
8- list (FILTER test_sources EXCLUDE REGEX ".*linux.*\. cc?" )
9- endif ()
10-
11- if (NOT OS_DARWIN)
12- list (FILTER test_sources EXCLUDE REGEX ".*darwin.*\. cc?" )
13- endif ()
6+ macro (EXCLUDING_ANY excluded)
7+ set (__condition "${ARGN} " )
8+ string (REGEX MATCH "^\ *IF\ +" __match "${__condition} " )
9+ if (__match STREQUAL "" )
10+ message (FATAL_ERROR "EXCLUDING_ANY call missing IF keyword" )
11+ endif ()
12+ unset (__match)
13+ string (REGEX REPLACE "^\ *IF\ +" "" __condition "${__condition} " )
14+ if (${__condition} )
15+ list (FILTER test_sources EXCLUDE REGEX ".*${excluded} .*\. (cc|hh)" )
16+ list (FILTER mock_sources EXCLUDE REGEX ".*${excluded} .*\. (cc|hh)" )
17+ endif ()
18+ unset (__condition)
19+ endmacro ()
1420
15- if (NOT BUILD_X11)
16- list (FILTER test_sources EXCLUDE REGEX ".*x11.*\. cc?" )
17- endif ()
18-
19- if (NOT BUILD_WAYLAND)
20- list (FILTER test_sources EXCLUDE REGEX ".*wayland.*\. cc?" )
21- endif ()
21+ excluding_any("linux" IF NOT OS_LINUX)
22+ excluding_any("darwin" IF NOT OS_DARWIN)
23+ excluding_any("x11" IF (NOT BUILD_X11) OR OS_DARWIN)
24+ excluding_any("wayland" IF NOT BUILD_WAYLAND)
2225
2326# Mocking works because it's linked before conky_core, so the linker uses mock
2427# implementations instead of those that are linked later.
25- file (GLOB mock_sources mock/*.cc)
26-
28+ add_library (conky-mock OBJECT ${mock_sources} )
2729add_library (Catch2 STATIC catch2/catch_amalgamated.cpp)
2830
2931add_executable (test -conky test -common.cc ${test_sources} )
@@ -33,10 +35,7 @@ target_include_directories(test-conky
3335 ${CMAKE_BINARY_DIR}
3436 ${conky_includes}
3537)
36- target_link_libraries (test -conky
37- PRIVATE Catch2 ${mock_sources}
38- PUBLIC conky_core
39- )
38+ target_link_libraries (test -conky Catch2 conky-mock conky_core)
4039catch_discover_tests(test -conky)
4140
4241if (CODE_COVERAGE)
0 commit comments