Skip to content

Commit 7714dee

Browse files
committed
Use GMock/GTest targets directly instead of via variables
This makes the dependencies more easy to read via visual inspection. Additionally it also only uses the -main version of the GTest/GMock library when necessary.
1 parent 0632e9d commit 7714dee

File tree

6 files changed

+13
-24
lines changed

6 files changed

+13
-24
lines changed

CMakeLists.txt

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,6 @@ if(NOT CUKE_DISABLE_GTEST)
9898
set(GMOCK_ROOT "${CMAKE_CURRENT_BINARY_DIR}/gmock")
9999
endif()
100100
find_package(GMock REQUIRED)
101-
102-
if(GTEST_FOUND)
103-
set(CUKE_GTEST_LIBRARIES
104-
GTest::GTest
105-
)
106-
endif()
107-
if(GMOCK_FOUND)
108-
set(CUKE_GMOCK_LIBRARIES
109-
GTest::GTest
110-
GMock::GMock
111-
GMock::Main
112-
)
113-
endif()
114101
endif()
115102

116103
#

examples/Calc/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ project(Calc)
33
add_library(Calc src/Calculator)
44
target_include_directories(Calc PUBLIC src)
55

6-
if(GMOCK_FOUND)
6+
if(TARGET GTest::GTest)
77
add_executable(GTestCalculatorSteps features/step_definitions/GTestCalculatorSteps)
8-
target_link_libraries(GTestCalculatorSteps Calc ${CUKE_LIBRARIES} ${CUKE_GTEST_LIBRARIES})
8+
target_link_libraries(GTestCalculatorSteps Calc ${CUKE_LIBRARIES} GTest::GTest)
99

1010
list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_variadic_templates HAS_VARIADIC_TEMPLATES)
1111
if(HAS_VARIADIC_TEMPLATES GREATER -1)
1212
add_executable(FuncArgsCalculatorSteps features/step_definitions/FuncArgsCalculatorSteps)
13-
target_link_libraries(FuncArgsCalculatorSteps Calc ${CUKE_LIBRARIES} ${CUKE_GTEST_LIBRARIES})
13+
target_link_libraries(FuncArgsCalculatorSteps Calc ${CUKE_LIBRARIES} GTest::GTest)
1414

1515
target_compile_features(FuncArgsCalculatorSteps PRIVATE cxx_variadic_templates)
1616
endif()

examples/CalcQt/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ if(QT_LIBRARIES)
1919
target_link_libraries(BoostCalculatorQtSteps libcalcqt ${CUKE_LIBRARIES} ${QT_LIBRARIES} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
2020
endif()
2121

22-
if(GTEST_FOUND)
22+
if(TARGET GTest::GTest)
2323
add_executable(GTestCalculatorQtSteps features/step_definitions/GTestCalculatorQtSteps)
24-
target_link_libraries(GTestCalculatorQtSteps libcalcqt ${CUKE_LIBRARIES} ${CUKE_GTEST_LIBRARIES} ${QT_LIBRARIES})
24+
target_link_libraries(GTestCalculatorQtSteps libcalcqt ${CUKE_LIBRARIES} GTest::GTest ${QT_LIBRARIES})
2525
endif()
2626

2727
endif()

examples/FeatureShowcase/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
project(FeatureShowcase)
22

3-
if(GMOCK_FOUND)
3+
if(TARGET GTest::GTest)
44
function(add_cucumber_executable)
55
add_executable(FeatureShowcaseSteps ${ARGV})
6-
target_link_libraries(FeatureShowcaseSteps ${CUKE_LIBRARIES} ${CUKE_GTEST_LIBRARIES})
6+
target_link_libraries(FeatureShowcaseSteps ${CUKE_LIBRARIES} GTest::GTest)
77
foreach(_arg ${ARGN})
88
get_filename_component(OBJECT_PREFIX ${_arg} NAME_WE)
99
set_source_files_properties(${_arg} PROPERTIES COMPILE_FLAGS "-DCUKE_OBJECT_PREFIX=${OBJECT_PREFIX}")

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ set(CUKE_SOURCES
1717

1818
set(CUKE_DEP_LIBRARIES json_spirit.header)
1919

20-
if(GTEST_FOUND)
20+
if(TARGET GTest::GTest)
2121
list(APPEND CUKE_DEP_LIBRARIES GTest::GTest)
2222
list(APPEND CUKE_SOURCES drivers/GTestDriver.cpp)
2323
endif()

tests/CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ function(cuke_add_driver_test TEST_FILE)
66
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
77
endfunction()
88

9-
if(GMOCK_FOUND)
9+
if(TARGET GMock::Main)
1010
function(cuke_add_test TEST_FILE)
1111
get_filename_component(TEST_NAME ${TEST_FILE} NAME)
1212
message(STATUS "Adding " ${TEST_NAME})
1313
add_executable(${TEST_NAME} ${TEST_FILE}.cpp)
14-
target_link_libraries(${TEST_NAME} cucumber-cpp-nomain ${CUKE_EXTRA_LIBRARIES} ${ARGN} ${CUKE_GMOCK_LIBRARIES})
14+
target_link_libraries(${TEST_NAME} cucumber-cpp-nomain ${CUKE_EXTRA_LIBRARIES} ${ARGN} GMock::Main)
1515
gtest_add_tests(${TEST_NAME} "" ${TEST_FILE}.cpp)
1616
# Run all tests in executable at once too. This ensures that the used fixtures get tested
1717
# properly too. Additionally gather the output in jUnit compatible output for CI.
@@ -35,8 +35,10 @@ if(GMOCK_FOUND)
3535
cuke_add_test(unit/StepManagerTest)
3636
cuke_add_test(unit/TableTest)
3737
cuke_add_test(unit/TagTest)
38+
endif()
3839

39-
cuke_add_driver_test(integration/drivers/GTestDriverTest ${CUKE_GTEST_LIBRARIES})
40+
if(TARGET GTest::Main)
41+
cuke_add_driver_test(integration/drivers/GTestDriverTest GTest::Main)
4042

4143
list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_variadic_templates HAS_VARIADIC_TEMPLATES)
4244
if(HAS_VARIADIC_TEMPLATES GREATER -1)

0 commit comments

Comments
 (0)