Fix exported include paths for absolute CMAKE_INSTALL_INCLUDEDIR

The INSTALL_INTERFACE include directory was written as
$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}, which unconditionally
prepends the install prefix. When CMAKE_INSTALL_INCLUDEDIR is an
absolute path, the exported GTestTargets.cmake ends up with an invalid
doubled path such as "/usr/local//usr/local/include", and find_package
consumers fail at configure time with "Imported target includes
non-existent path".

Relative paths inside $<INSTALL_INTERFACE:...> are already interpreted
relative to the installation prefix, so the explicit $<INSTALL_PREFIX>/
prefix is redundant for relative values and wrong for absolute ones.
Dropping it keeps the exported path identical for relative values
(${_IMPORT_PREFIX}/include) and uses absolute values as-is.

Fixes #4817
This commit is contained in:
uditDewan 2026-07-18 14:59:31 -04:00
parent fa005b296f
commit fcd5e26089
2 changed files with 4 additions and 4 deletions

View File

@ -105,10 +105,10 @@ endif()
string(REPLACE ";" "$<SEMICOLON>" dirs "${gmock_build_include_dirs}")
target_include_directories(gmock SYSTEM INTERFACE
"$<BUILD_INTERFACE:${dirs}>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
target_include_directories(gmock_main SYSTEM INTERFACE
"$<BUILD_INTERFACE:${dirs}>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
########################################################################
#

View File

@ -140,10 +140,10 @@ set_target_properties(gtest_main PROPERTIES VERSION ${GOOGLETEST_VERSION})
string(REPLACE ";" "$<SEMICOLON>" dirs "${gtest_build_include_dirs}")
target_include_directories(gtest SYSTEM INTERFACE
"$<BUILD_INTERFACE:${dirs}>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
target_include_directories(gtest_main SYSTEM INTERFACE
"$<BUILD_INTERFACE:${dirs}>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
if(CMAKE_SYSTEM_NAME MATCHES "QNX" AND CMAKE_SYSTEM_VERSION VERSION_GREATER_EQUAL 7.1)
target_link_libraries(gtest PUBLIC regex)
endif()