mirror of
https://github.com/abseil/abseil-cpp.git
synced 2026-06-04 12:07:05 +08:00
cmake: use target aliases from local Google Test checkout. (#1083)
* cmake: use target aliases from local Google Test checkout. `ABSL_FIND_GOOGLETEST` is a dependent option, it is always `OFF` when `ABSL_USE_EXTERNAL_GOOGLETEST` is `OFF` (i.e. when Google Test is checked out locally). `GTest::` target aliases are to be added only if `find_package(GTest)` has been actually used. * cmake: clarify adding GTest:: aliases.
This commit is contained in:
@@ -134,8 +134,14 @@ if(BUILD_TESTING AND ABSL_BUILD_TESTING)
|
||||
if (ABSL_USE_EXTERNAL_GOOGLETEST)
|
||||
if (ABSL_FIND_GOOGLETEST)
|
||||
find_package(GTest REQUIRED)
|
||||
else()
|
||||
if (NOT TARGET gtest AND NOT TARGET GTest::gtest)
|
||||
elseif(NOT TARGET GTest::gtest)
|
||||
if(TARGET gtest)
|
||||
# When Google Test is included directly rather than through find_package, the aliases are missing.
|
||||
add_library(GTest::gtest ALIAS gtest)
|
||||
add_library(GTest::gtest_main ALIAS gtest_main)
|
||||
add_library(GTest::gmock ALIAS gmock)
|
||||
add_library(GTest::gmock_main ALIAS gmock_main)
|
||||
else()
|
||||
message(FATAL_ERROR "ABSL_USE_EXTERNAL_GOOGLETEST is ON and ABSL_FIND_GOOGLETEST is OFF, which means that the top-level project must build the Google Test project. However, the target gtest was not found.")
|
||||
endif()
|
||||
endif()
|
||||
@@ -157,14 +163,6 @@ if(BUILD_TESTING AND ABSL_BUILD_TESTING)
|
||||
include(CMake/Googletest/DownloadGTest.cmake)
|
||||
endif()
|
||||
|
||||
if (NOT ABSL_FIND_GOOGLETEST)
|
||||
# When Google Test is included directly rather than through find_package, the aliases are missing.
|
||||
add_library(GTest::gtest ALIAS gtest)
|
||||
add_library(GTest::gtest_main ALIAS gtest_main)
|
||||
add_library(GTest::gmock ALIAS gmock)
|
||||
add_library(GTest::gmock_main ALIAS gmock_main)
|
||||
endif()
|
||||
|
||||
check_target(GTest::gtest)
|
||||
check_target(GTest::gtest_main)
|
||||
check_target(GTest::gmock)
|
||||
|
||||
Reference in New Issue
Block a user