Commit 294166fc by Andrei Polushin Committed by GitHub

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.
parent 628a2825
...@@ -134,8 +134,14 @@ if(BUILD_TESTING AND ABSL_BUILD_TESTING) ...@@ -134,8 +134,14 @@ if(BUILD_TESTING AND ABSL_BUILD_TESTING)
if (ABSL_USE_EXTERNAL_GOOGLETEST) if (ABSL_USE_EXTERNAL_GOOGLETEST)
if (ABSL_FIND_GOOGLETEST) if (ABSL_FIND_GOOGLETEST)
find_package(GTest REQUIRED) find_package(GTest REQUIRED)
else() elseif(NOT TARGET GTest::gtest)
if (NOT TARGET gtest AND 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.") 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()
endif() endif()
...@@ -157,14 +163,6 @@ if(BUILD_TESTING AND ABSL_BUILD_TESTING) ...@@ -157,14 +163,6 @@ if(BUILD_TESTING AND ABSL_BUILD_TESTING)
include(CMake/Googletest/DownloadGTest.cmake) include(CMake/Googletest/DownloadGTest.cmake)
endif() 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)
check_target(GTest::gtest_main) check_target(GTest::gtest_main)
check_target(GTest::gmock) check_target(GTest::gmock)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment