summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorGravatar Andrei Polushin <polushin@gmail.com>2022-01-07 21:42:54 +0700
committerGravatar GitHub <noreply@github.com>2022-01-07 09:42:54 -0500
commit294166fcbeae8c19b8817330a0874c186d147266 (patch)
treeb254312806a506862dac2710e2f7b0aa11cbec91 /CMakeLists.txt
parent628a2825f8dc0219964886e7cc3f7f519e3bd950 (diff)
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.
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt18
1 files changed, 8 insertions, 10 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ff49ac1e..5bd3415a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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)