Commit b87875aa by Daniel Richard G Committed by Copybara-Service

PR #1546: CMake: Enable CMP0074 so that GTest_ROOT can be specified

Imported from GitHub PR https://github.com/abseil/abseil-cpp/pull/1546

I am building Abseil with tests enabled and an external GTest build, i.e.
```
-DABSL_BUILD_TESTING=ON
-DABSL_USE_EXTERNAL_GOOGLETEST=ON
-DABSL_FIND_GOOGLETEST=ON
-DGTest_ROOT=/path/to/googletest/1.14.0
```

However, CMake (3.20.2) configuration yielded this result:
```
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
CMake Warning (dev) at CMakeLists.txt:150 (find_package):
  Policy CMP0074 is not set: find_package uses <PackageName>_ROOT variables.
  Run "cmake --help-policy CMP0074" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  CMake variable GTest_ROOT is set to:

    /path/to/googletest/1.14.0

  For compatibility, CMake is ignoring the variable.
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find GTest (missing: GTEST_LIBRARY GTEST_INCLUDE_DIR
  GTEST_MAIN_LIBRARY)
Call Stack (most recent call first):
  /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake/Modules/FindGTest.cmake:255 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  CMakeLists.txt:150 (find_package)

-- Configuring incomplete, errors occurred!
See also "/tmp/abseil-build/CMakeFiles/CMakeOutput.log".
See also "/tmp/abseil-build/CMakeFiles/CMakeError.log".
```

This PR sets `CMP0074=NEW` so that the GTest install location can be specified via `GTest_ROOT`.
Merge 4e4f035affd9b8af739634afdf9c2e80d14c2391 into 2a18ba75

Merging this change closes #1546

COPYBARA_INTEGRATE_REVIEW=https://github.com/abseil/abseil-cpp/pull/1546 from iskunk:feature/fix-gtest-root 4e4f035affd9b8af739634afdf9c2e80d14c2391
PiperOrigin-RevId: 574159856
Change-Id: Ifc796500c3a6403d28a027375116437bc743205a
parent 2a18ba75
......@@ -33,6 +33,11 @@ if (POLICY CMP0048)
cmake_policy(SET CMP0048 NEW)
endif (POLICY CMP0048)
# Honor the GTest_ROOT variable if specified
if (POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
endif (POLICY CMP0074)
# option() honor variables
if (POLICY CMP0077)
cmake_policy(SET CMP0077 NEW)
......
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