Skip to content

Commit 4db377c

Browse files
authored
Set working directory for tests and allow not linking to mock and main. (#35)
1 parent 0185ac7 commit 4db377c

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

mo2_cpp.cmake

+13-2
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,18 @@ endfunction()
264264
# OFF by default
265265
#
266266
function(mo2_configure_tests TARGET)
267+
cmake_parse_arguments(MO2 "NO_MOCK;NO_MAIN" "" "" ${ARGN})
267268
mo2_configure_target(${TARGET} TRANSLATIONS OFF AUTOMOC OFF ${ARGN})
268269

269270
find_package(GTest REQUIRED)
270-
target_link_libraries(${TARGET} PRIVATE GTest::gtest GTest::gmock GTest::gtest_main)
271+
target_link_libraries(${TARGET} PRIVATE GTest::gtest)
272+
273+
if (NOT MO2_NO_MOCK)
274+
target_link_libraries(${TARGET} GTest::gmock)
275+
endif()
276+
if (NOT MO2_NO_MAIN)
277+
target_link_libraries(${TARGET} GTest::gtest_main)
278+
endif()
271279

272280
# gtest_discover_tests would be nice but it requires Qt DLL, uibase, etc., in the
273281
# path, etc., and is not working right now
@@ -281,7 +289,10 @@ function(mo2_configure_tests TARGET)
281289
# )
282290
#
283291

284-
gtest_add_tests(TARGET ${TARGET} TEST_LIST ${TARGET}_gtests)
292+
gtest_add_tests(
293+
TARGET ${TARGET}
294+
TEST_LIST ${TARGET}_gtests
295+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
285296
set(${TARGET}_gtests ${${TARGET}_gtests} PARENT_SCOPE)
286297

287298
mo2_deploy_qt_for_tests(

0 commit comments

Comments
 (0)