Skip to content

Commit 2f41bf3

Browse files
committed
Fix mock linking
- Fix compile issues. Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
1 parent a0c1502 commit 2f41bf3

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

tests/CMakeLists.txt

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
include(CTest)
22

33
file(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})
2729
add_library(Catch2 STATIC catch2/catch_amalgamated.cpp)
2830

2931
add_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)
4039
catch_discover_tests(test-conky)
4140

4241
if(CODE_COVERAGE)

tests/mock/mock.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <memory>
77
#include <optional>
88
#include <stdexcept>
9+
#include <string>
910
#include <type_traits>
1011

1112
namespace mock {

0 commit comments

Comments
 (0)