Skip to content

Commit

Permalink
GMock: declare it a dependency where used
Browse files Browse the repository at this point in the history
This way other properties such as the list of libraries to link to
transitively and what header files to use get handled automatically by
CMake.
  • Loading branch information
muggenhor committed Mar 13, 2017
1 parent f3d2458 commit ff68d90
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 18 deletions.
11 changes: 7 additions & 4 deletions cmake/modules/FindGMock.cmake
Expand Up @@ -372,6 +372,9 @@ if(NOT (${GMOCK_LIBRARY_EXISTS} AND ${GTEST_LIBRARY_EXISTS}))
mark_as_advanced(GMOCK_INCLUDE_DIR)
mark_as_advanced(GTEST_INCLUDE_DIR)
endif()

# Prevent CMake from complaining about these directories missing when the libgtest/libgmock targets get used as dependencies
file(MAKE_DIRECTORY ${GTEST_INCLUDE_DIR} ${GMOCK_INCLUDE_DIR})
else()
message(STATUS "Building Gmock / Gtest from dir ${GMOCK_SRC_DIR}")

Expand Down Expand Up @@ -466,8 +469,8 @@ set_target_properties(GMock::Main PROPERTIES

if(GTEST_FOUND)
set(GTEST_INCLUDE_DIRS ${GTEST_INCLUDE_DIR})
set(GTEST_LIBRARIES ${GTEST_LIBRARY})
set(GTEST_MAIN_LIBRARIES ${GTEST_MAIN_LIBRARY})
set(GTEST_LIBRARIES GTest::GTest)
set(GTEST_MAIN_LIBRARIES GTest::Main)
set(GTEST_BOTH_LIBRARIES ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES})
if(VERBOSE)
message(STATUS "GTest includes: ${GTEST_INCLUDE_DIRS}")
Expand All @@ -477,8 +480,8 @@ endif()

if(GMOCK_FOUND)
set(GMOCK_INCLUDE_DIRS ${GMOCK_INCLUDE_DIR})
set(GMOCK_LIBRARIES ${GMOCK_LIBRARY})
set(GMOCK_MAIN_LIBRARIES ${GMOCK_MAIN_LIBRARY})
set(GMOCK_LIBRARIES GMock::GMock)
set(GMOCK_MAIN_LIBRARIES GMock::Main)
set(GMOCK_BOTH_LIBRARIES ${GMOCK_LIBRARIES} ${GMOCK_MAIN_LIBRARIES})
if(VERBOSE)
message(STATUS "GMock includes: ${GMOCK_INCLUDE_DIRS}")
Expand Down
1 change: 0 additions & 1 deletion examples/Calc/CMakeLists.txt
Expand Up @@ -5,7 +5,6 @@ include_directories(${CUKE_INCLUDE_DIRS} src)
add_library(Calc src/Calculator)

if(GMOCK_FOUND)
include_directories(${GTEST_INCLUDE_DIRS})
add_executable(GTestCalculatorSteps features/step_definitions/GTestCalculatorSteps)
target_link_libraries(GTestCalculatorSteps Calc ${CUKE_LIBRARIES} ${CUKE_GTEST_LIBRARIES})
endif()
Expand Down
1 change: 0 additions & 1 deletion examples/CalcQt/CMakeLists.txt
Expand Up @@ -37,7 +37,6 @@ if(QT_LIBRARIES)
target_link_libraries(BoostCalculatorQtSteps libcalcqt ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} ${CUKE_LIBRARIES} ${QT_LIBRARIES})
endif()
if(GTEST_FOUND)
include_directories(${GTEST_INCLUDE_DIRS})
add_executable(GTestCalculatorQtSteps features/step_definitions/GTestCalculatorQtSteps)
target_link_libraries(GTestCalculatorQtSteps libcalcqt ${CUKE_LIBRARIES} ${CUKE_GTEST_LIBRARIES} ${QT_LIBRARIES})
endif()
Expand Down
2 changes: 0 additions & 2 deletions examples/FeatureShowcase/CMakeLists.txt
Expand Up @@ -3,8 +3,6 @@ project(FeatureShowcase)
include_directories(${CUKE_INCLUDE_DIRS})

if(GMOCK_FOUND)
include_directories(${GTEST_INCLUDE_DIRS})

function(add_cucumber_executable)
add_executable(FeatureShowcaseSteps ${ARGV})
target_link_libraries(FeatureShowcaseSteps ${CUKE_LIBRARIES} ${CUKE_GTEST_LIBRARIES})
Expand Down
12 changes: 5 additions & 7 deletions src/CMakeLists.txt
Expand Up @@ -16,7 +16,7 @@ set(CUKE_SOURCES
)

if(GTEST_FOUND)
include_directories(${GTEST_INCLUDE_DIRS})
list(APPEND CUKE_DEP_LIBRARIES GTest::GTest)
list(APPEND CUKE_SOURCES drivers/GTestDriver.cpp)
endif()

Expand All @@ -37,10 +37,8 @@ add_library(cucumber-cpp-nomain STATIC ${CUKE_SOURCES})
add_library(cucumber-cpp STATIC ${CUKE_SOURCES} main.cpp)

if(MINGW)
target_link_libraries(cucumber-cpp-nomain
ws2_32
)
target_link_libraries(cucumber-cpp
ws2_32
)
list(APPEND CUKE_DEP_LIBRARIES ws2_32)
endif(MINGW)

target_link_libraries(cucumber-cpp-nomain PRIVATE ${CUKE_DEP_LIBRARIES})
target_link_libraries(cucumber-cpp PRIVATE ${CUKE_DEP_LIBRARIES})
3 changes: 0 additions & 3 deletions tests/CMakeLists.txt
Expand Up @@ -7,9 +7,6 @@ function(cuke_add_driver_test TEST_FILE)
endfunction()

if(GMOCK_FOUND)
include_directories(${GTEST_INCLUDE_DIRS})
include_directories(${GMOCK_INCLUDE_DIRS})

function(cuke_add_test TEST_FILE)
get_filename_component(TEST_NAME ${TEST_FILE} NAME)
message(STATUS "Adding " ${TEST_NAME})
Expand Down

0 comments on commit ff68d90

Please sign in to comment.