summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEero Aaltonen <eero.aaltonen@iki.fi>2021-10-17 14:13:07 (GMT)
committerBrad King <brad.king@kitware.com>2021-11-22 16:23:39 (GMT)
commit50bf457a0dd857cf976b22c5be7d333493233d1e (patch)
treeee03ca12b04b33a09e78d465a82d375dc04be00f
parenteb9991ad62666649b0349b8c1e88255330c1c05c (diff)
downloadCMake-50bf457a0dd857cf976b22c5be7d333493233d1e.zip
CMake-50bf457a0dd857cf976b22c5be7d333493233d1e.tar.gz
CMake-50bf457a0dd857cf976b22c5be7d333493233d1e.tar.bz2
FindGTest: Add target for gmock library
`googlemock` has been absorbed into the [googletest](https://github.com/google/googletest) project and is built and installed from the same source tree. As GTest may be built with or without GMock, skip GMock if it is not present. Do not provide result variables for GMock. They are not provided by upstream GTest's CMake Package Configuration File. Also update the test case to cover linking to `GTest::gmock`.
-rw-r--r--Help/release/dev/FindGTest-target-for-gmock.rst4
-rw-r--r--Modules/FindGTest.cmake56
-rw-r--r--Tests/FindGTest/Test/CMakeLists.txt4
3 files changed, 63 insertions, 1 deletions
diff --git a/Help/release/dev/FindGTest-target-for-gmock.rst b/Help/release/dev/FindGTest-target-for-gmock.rst
new file mode 100644
index 0000000..f78242c
--- /dev/null
+++ b/Help/release/dev/FindGTest-target-for-gmock.rst
@@ -0,0 +1,4 @@
+FindGTest-target-for-gmock
+--------------------------
+
+* The :module:`FindGTest` module now provides a target for GMock, if found.
diff --git a/Modules/FindGTest.cmake b/Modules/FindGTest.cmake
index 8e22f79..60bb401 100644
--- a/Modules/FindGTest.cmake
+++ b/Modules/FindGTest.cmake
@@ -22,6 +22,14 @@ Imported targets
``GTest::gtest_main``
The Google Test ``gtest_main`` library, if found
+.. versionadded:: 3.23
+
+``GTest::gmock``
+ The Google Mock ``gmock`` library, if found; adds Thread::Thread
+ automatically
+``GTest::gmock_main``
+ The Google Mock ``gmock_main`` library, if found
+
.. deprecated:: 3.20
For backwards compatibility, this module defines additionally the
following deprecated :prop_tgt:`IMPORTED` targets (available since 3.5):
@@ -32,7 +40,6 @@ Imported targets
``GTest::Main``
The Google Test ``gtest_main`` library, if found
-
Result variables
^^^^^^^^^^^^^^^^
@@ -245,15 +252,29 @@ if(MSVC AND GTEST_MSVC_SEARCH STREQUAL "MD")
__gtest_find_library(GTEST_LIBRARY_DEBUG gtest-mdd gtestd)
__gtest_find_library(GTEST_MAIN_LIBRARY gtest_main-md gtest_main)
__gtest_find_library(GTEST_MAIN_LIBRARY_DEBUG gtest_main-mdd gtest_maind)
+ __gtest_find_library(GMOCK_LIBRARY gmock-md gmock)
+ __gtest_find_library(GMOCK_LIBRARY_DEBUG gmock-mdd gmockd)
+ __gtest_find_library(GMOCK_MAIN_LIBRARY gmock_main-md gmock_main)
+ __gtest_find_library(GMOCK_MAIN_LIBRARY_DEBUG gmock_main-mdd gmock_maind)
else()
__gtest_find_library(GTEST_LIBRARY gtest)
__gtest_find_library(GTEST_LIBRARY_DEBUG gtestd)
__gtest_find_library(GTEST_MAIN_LIBRARY gtest_main)
__gtest_find_library(GTEST_MAIN_LIBRARY_DEBUG gtest_maind)
+ __gtest_find_library(GMOCK_LIBRARY gmock)
+ __gtest_find_library(GMOCK_LIBRARY_DEBUG gmockd)
+ __gtest_find_library(GMOCK_MAIN_LIBRARY gmock_main)
+ __gtest_find_library(GMOCK_MAIN_LIBRARY_DEBUG gmock_maind)
endif()
FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTest DEFAULT_MSG GTEST_LIBRARY GTEST_INCLUDE_DIR GTEST_MAIN_LIBRARY)
+if(GMOCK_LIBRARY AND GMOCK_MAIN_LIBRARY)
+ set(GMock_FOUND True)
+else()
+ set(GMock_FOUND False)
+endif()
+
if(GTest_FOUND)
set(GTEST_INCLUDE_DIRS ${GTEST_INCLUDE_DIR})
__gtest_append_debugs(GTEST_LIBRARIES GTEST_LIBRARY)
@@ -292,3 +313,36 @@ if(GTest_FOUND)
__gtest_define_backwards_compatible_library_targets()
endif()
+
+if(GMock_FOUND)
+ if(NOT TARGET GTest::gmock)
+ __gtest_determine_library_type(GMOCK_LIBRARY)
+ add_library(GTest::gmock ${GMOCK_LIBRARY_TYPE} IMPORTED)
+ set(_gmock_link_libraries "GTest::gtest")
+ if(TARGET Threads::Threads)
+ list(APPEND _gmock_link_libraries Threads::Threads)
+ endif()
+ set_target_properties(GTest::gmock PROPERTIES
+ INTERFACE_LINK_LIBRARIES "${_gmock_link_libraries}")
+ if(GMOCK_LIBRARY_TYPE STREQUAL "SHARED")
+ set_target_properties(GTest::gmock PROPERTIES
+ INTERFACE_COMPILE_DEFINITIONS "GMOCK_LINKED_AS_SHARED_LIBRARY=1")
+ endif()
+ if(GTEST_INCLUDE_DIRS)
+ set_target_properties(GTest::gmock PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${GTEST_INCLUDE_DIRS}")
+ endif()
+ __gtest_import_library(GTest::gmock GMOCK_LIBRARY "")
+ __gtest_import_library(GTest::gmock GMOCK_LIBRARY "RELEASE")
+ __gtest_import_library(GTest::gmock GMOCK_LIBRARY "DEBUG")
+ endif()
+ if(NOT TARGET GTest::gmock_main)
+ __gtest_determine_library_type(GMOCK_MAIN_LIBRARY)
+ add_library(GTest::gmock_main ${GMOCK_MAIN_LIBRARY_TYPE} IMPORTED)
+ set_target_properties(GTest::gmock_main PROPERTIES
+ INTERFACE_LINK_LIBRARIES "GTest::gmock")
+ __gtest_import_library(GTest::gmock_main GMOCK_MAIN_LIBRARY "")
+ __gtest_import_library(GTest::gmock_main GMOCK_MAIN_LIBRARY "RELEASE")
+ __gtest_import_library(GTest::gmock_main GMOCK_MAIN_LIBRARY "DEBUG")
+ endif()
+endif()
diff --git a/Tests/FindGTest/Test/CMakeLists.txt b/Tests/FindGTest/Test/CMakeLists.txt
index 6537238..9c1eb5e 100644
--- a/Tests/FindGTest/Test/CMakeLists.txt
+++ b/Tests/FindGTest/Test/CMakeLists.txt
@@ -16,3 +16,7 @@ add_executable(test_gtest_var main.cxx)
target_include_directories(test_gtest_var PRIVATE ${GTEST_INCLUDE_DIRS})
target_link_libraries(test_gtest_var PRIVATE ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
add_test(NAME test_gtest_var COMMAND test_gtest_var)
+
+add_executable(test_gmock_tgt main.cxx)
+target_link_libraries(test_gmock_tgt GTest::gmock_main)
+add_test(NAME test_gmock_tgt COMMAND test_gmock_tgt)