[Bug]: CMake target has invalid path if googletest was built with an absolute `CMAKE_INSTALL_INCLUDEDIR`
envgap__google__googletest-4817
01 / FAILURE SIGNATURE
As reported upstream
CMake Error in CMakeLists.txt:
Not a benchmark task.
- The project already builds and runs before the fix, so there is nothing to repair.
02 / ENVIRONMENT RECIPE
- Base commit
fa005b296f90faec4f352d7ab382287bf6548c8d- Manifest
googlemock/CMakeLists.txt- Reproduce
Awaiting issue-specific recipe- Run under trace
Awaiting a meaningful runtime command
03 / ORIGINAL ISSUE TEXT
google/googletest #4817 · read the original issue
### Describe the issue
Unfortunately, this line is not compatible with an absolute `CMAKE_INSTALL_INCLUDEDIR` because the installation prefix is prepended to the `CMAKE_INSTALL_INCLUDEDIR` even if it is already an absolute path.
https://github.com/google/googletest/blob/244cec869d12e53378fa0efb610cd4c32a454ec8/googletest/CMakeLists.txt#L146
That results in builds of googletest to which a relative `CMAKE_INSTALL_INCLUDEDIR` was passed causing this error at configure-time of reverse dependencies of googletest.
```
CMake Error in CMakeLists.txt:
Imported target "GTest::gtest_main" includes non-existent path
"/usr/local//usr/local/include"
in its INTERFACE_INCLUDE_DIRECTORIES.
```
### Steps to reproduce the problem
#### commands to build googletest with an absolute `CMAKE_INSTALL_INCLUDEDIR`
```bash
git clone https://github.com/google/googletest.git
cd googletest
mkdir build
cd build
# this command is the only difference
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local \
-DCMAKE_INSTALL_INCLUDEDIR=/usr/local/include
make -j$(nproc)
sudo make install
cd ../..
mkdir test_googletest
cd test_googletest
touch empty.cpp
cat <<-EOF > CMakeLists.txt
cmake_minimum_required(VERSION 3.30)
project(test-googletest)
find_package(GTest REQUIRED)
add_library(test-googletest empty.cpp)
target_link_libraries(test-googletest GTest::gtest_main)
EOF
cmake -S . -B build
```
#### commands to build googletest with a relative `CMAKE_INSTALL_INCLUDEDIR`
```bash
git clone https://github.com/google/googletest.git
cd googletest
mkdir build
cd build
# this command is the only difference
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local \
-DCMAKE_INSTALL_INCLUDEDIR=include
make -j$(nproc)
sudo make install
cd ../..
mkdir test_googletest
cd test_googletest
touch empty.cpp
cat <<-EOF > CMakeLists.txt
cmake_minimum_required(VERSION 3.30)
project(test-googletest)
find_package(GTest REQUIRED)
add_library(test-googletest empty.cpp)
target_link_libraries(test-googletest GTest::gtest_main)
EOF
cmake -S . -B build
```
<details>
<summary>result from absolute CMAKE_INSTALL_INCLUDEDIR</summary>
```
-- The C compiler identification is GNU 14.3.0
-- The CXX compiler identification is GNU 14.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found GTest: /usr/local/lib64/cmake/GTest/GTestConfig.cmake (found version "1.16.0")
-- Configuring done (0.9s)
CMake Error in CMakeLists.txt:
Imported target "GTest::gtest_main" includes non-existent path
"/usr/local//usr/local/include"
in its INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:
* The path was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and references files it does not
provide.
-- Generating done (0.0s)
CMake Generate step failed. Build files cannot be regenerated correctly.
```
</details>
<details>
<summary>result from relative CMAKE_INSTALL_INCLUDEDIR</summary>
```
-- The C compiler identification is GNU 14.3.0
-- The CXX compiler identification is GNU 14.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found GTest: /usr/local/lib64/cmake/GTest/GTestConfig.cmake (found version "1.16.0")
-- Configuring done (0.3s)
-- Generating done (0.0s)
-- Build files have been written to: /home/tacokoneko/code/test_googletest/build
```
</details>
### What version of GoogleTest are you using?
```
244cec869d12e53378fa0efb610cd4c32a454ec8
```
### What operating system and version are you using?
```
Linux CORSAIR 6.12.31-gentoo-dist #1 SMP PREEMPT_DYNAMIC Thu Jun 19 14:25:47 CDT 2025 x86_64 AMD Ryzen 9 5950X 16-Core Processor AuthenticAMD GNU/Linux
```
```
LSB Version: n/a
Distributor ID: Gentoo
Description: Gentoo Linux
Release: 2.17
Codename: n/a
```
### What compiler and version are you using?
```
gcc (Gentoo 14.3.0 p8) 14.3.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
```
### What build system are you using?
```
cmake version 3.31.7
CMake suite maintained and supported by Kitware (kitware.com/cmake).
```
### Additional context
First reported here in a downstream project:
- https://github.com/termux/termux-packages/issues/2569304 / LABELS
Labels from the report text only; not yet run
No supported category has been assigned.
Label rules and the text that matched
[]