summaryrefslogtreecommitdiff
path: root/Modules/FindGTest.cmake
diff options
context:
space:
mode:
authorMario Emmenlauer <memmenlauer@biodataanalysis.de>2020-10-21 17:47:17 +0200
committerBrad King <brad.king@kitware.com>2020-10-22 09:32:36 -0400
commit2327b4330cce157d616ff8b611b3e77568d00351 (patch)
treea28317d12cc4c68743fb88a8c233aa432821f625 /Modules/FindGTest.cmake
parent6d45f951ed0eba8feefc3c5aeeaeed628bf6497c (diff)
downloadcmake-2327b4330cce157d616ff8b611b3e77568d00351.tar.gz
FindGTest: Added support for CONFIG mode
Upstream GTest provides its own CMake package files. Use them if available. Fixes: #18801
Diffstat (limited to 'Modules/FindGTest.cmake')
-rw-r--r--Modules/FindGTest.cmake49
1 files changed, 34 insertions, 15 deletions
diff --git a/Modules/FindGTest.cmake b/Modules/FindGTest.cmake
index 1470b45e88..ff50869681 100644
--- a/Modules/FindGTest.cmake
+++ b/Modules/FindGTest.cmake
@@ -33,7 +33,7 @@ Result variables
This module will set the following variables in your project:
-``GTEST_FOUND``
+``GTest_FOUND``
Found the Google Testing framework
``GTEST_INCLUDE_DIRS``
the directory containing the Google Test headers
@@ -176,10 +176,41 @@ function(__gtest_import_library _target _var _config)
endif()
endfunction()
+function(__gtest_define_backwards_compatible_library_targets)
+ set(GTEST_BOTH_LIBRARIES ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} PARENT_SCOPE)
+
+ # Add targets mapping the same library names as defined in
+ # older versions of CMake's FindGTest
+ if(NOT TARGET GTest::GTest)
+ add_library(GTest::GTest INTERFACE IMPORTED)
+ target_link_libraries(GTest::GTest INTERFACE GTest::gtest)
+ endif()
+ if(NOT TARGET GTest::Main)
+ add_library(GTest::Main INTERFACE IMPORTED)
+ target_link_libraries(GTest::Main INTERFACE GTest::gtest_main)
+ endif()
+endfunction()
+
#
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+# first specifically look for the CMake version of GTest
+find_package(GTest QUIET NO_MODULE)
+
+# if we found the GTest cmake package then we are done, and
+# can print what we found and return.
+if(GTest_FOUND)
+ FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTest HANDLE_COMPONENTS CONFIG_MODE)
+
+ set(GTEST_LIBRARIES GTest::gtest)
+ set(GTEST_MAIN_LIBRARIES GTest::gtest_main)
+
+ __gtest_define_backwards_compatible_library_targets()
+
+ return()
+endif()
+
if(NOT DEFINED GTEST_MSVC_SEARCH)
set(GTEST_MSVC_SEARCH MD)
endif()
@@ -219,8 +250,6 @@ find_path(GTEST_INCLUDE_DIR gtest/gtest.h
)
mark_as_advanced(GTEST_INCLUDE_DIR)
-# Allow GTEST_LIBRARY and GTEST_MAIN_LIBRARY to be set manually, as the
-# locations of the gtest and gtest_main libraries, respectively.
if(NOT GTEST_LIBRARY)
__gtest_find_and_select_library_configurations(GTEST gtest)
endif()
@@ -230,11 +259,10 @@ endif()
FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTest DEFAULT_MSG GTEST_LIBRARY GTEST_INCLUDE_DIR GTEST_MAIN_LIBRARY)
-if(GTEST_FOUND)
+if(GTest_FOUND)
set(GTEST_INCLUDE_DIRS ${GTEST_INCLUDE_DIR})
__gtest_append_debugs(GTEST_LIBRARIES GTEST_LIBRARY)
__gtest_append_debugs(GTEST_MAIN_LIBRARIES GTEST_MAIN_LIBRARY)
- set(GTEST_BOTH_LIBRARIES ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES})
find_package(Threads QUIET)
@@ -267,14 +295,5 @@ if(GTEST_FOUND)
__gtest_import_library(GTest::gtest_main GTEST_MAIN_LIBRARY "DEBUG")
endif()
- # Add targets mapping the same library names as defined in
- # older versions of CMake's FindGTest
- if(NOT TARGET GTest::GTest)
- add_library(GTest::GTest INTERFACE IMPORTED)
- target_link_libraries(GTest::GTest INTERFACE GTest::gtest)
- endif()
- if(NOT TARGET GTest::Main)
- add_library(GTest::Main INTERFACE IMPORTED)
- target_link_libraries(GTest::Main INTERFACE GTest::gtest_main)
- endif()
+ __gtest_define_backwards_compatible_library_targets()
endif()