summaryrefslogtreecommitdiffstats
path: root/Modules/FindGTest.cmake
diff options
context:
space:
mode:
authorWilliam Reid Paape <wrpaape@gmail.com>2020-06-29 10:04:26 (GMT)
committerWilliam Reid Paape <wrpaape@gmail.com>2020-06-30 23:31:19 (GMT)
commita064b18f85f0b21b44c508f56e5fa7a1912f978c (patch)
tree17ab292467dbe3602b70c3263ecd4fad7a02af37 /Modules/FindGTest.cmake
parent45542049563f0ee8358ead563a4e4cc7d7270110 (diff)
downloadCMake-a064b18f85f0b21b44c508f56e5fa7a1912f978c.zip
CMake-a064b18f85f0b21b44c508f56e5fa7a1912f978c.tar.gz
CMake-a064b18f85f0b21b44c508f56e5fa7a1912f978c.tar.bz2
FindGTest: Allow either "Debug" or "Release" configurations.
Call select_library_configurations on GTest library variable basenames "GTEST" and "GTEST_MAIN" before passing ${basename}_LIBRARY variables to find_package_handle_standard_args. This allows either _DEBUG or _RELEASE library variants to be found for find_package() to pass, whereas the original version would require the presence of _RELEASE variants. Fixes: #17799
Diffstat (limited to 'Modules/FindGTest.cmake')
-rw-r--r--Modules/FindGTest.cmake40
1 files changed, 28 insertions, 12 deletions
diff --git a/Modules/FindGTest.cmake b/Modules/FindGTest.cmake
index 53cab1a..10e31b2 100644
--- a/Modules/FindGTest.cmake
+++ b/Modules/FindGTest.cmake
@@ -96,6 +96,27 @@ function(__gtest_find_library _name)
mark_as_advanced(${_name})
endfunction()
+function(__gtest_find_library_configuration _name _lib _cfg_suffix)
+ set(_libs ${_lib})
+ if(MSVC AND GTEST_MSVC_SEARCH STREQUAL "MD")
+ # The provided /MD project files for Google Test add -md suffixes to the
+ # library names.
+ list(INSERT _libs 0 ${_lib}-md)
+ endif()
+ list(TRANSFORM _libs APPEND "${_cfg_suffix}")
+
+ __gtest_find_library(${_name} ${_libs})
+endfunction()
+
+include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
+function(__gtest_find_and_select_library_configurations _basename _lib)
+ __gtest_find_library_configuration(${_basename}_LIBRARY_RELEASE ${_lib} "")
+ __gtest_find_library_configuration(${_basename}_LIBRARY_DEBUG ${_lib} "d")
+
+ select_library_configurations(${_basename})
+ set(${_basename}_LIBRARY ${${_basename}_LIBRARY} PARENT_SCOPE)
+endfunction()
+
macro(__gtest_determine_windows_library_type _var)
if(EXISTS "${${_var}}")
file(TO_NATIVE_PATH "${${_var}}" _lib_path)
@@ -187,18 +208,13 @@ find_path(GTEST_INCLUDE_DIR gtest/gtest.h
)
mark_as_advanced(GTEST_INCLUDE_DIR)
-if(MSVC AND GTEST_MSVC_SEARCH STREQUAL "MD")
- # The provided /MD project files for Google Test add -md suffixes to the
- # library names.
- __gtest_find_library(GTEST_LIBRARY gtest-md gtest)
- __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)
-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)
+# 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()
+if(NOT GTEST_MAIN_LIBRARY)
+ __gtest_find_and_select_library_configurations(GTEST_MAIN gtest_main)
endif()
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)