1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-16 14:08:35 +08:00

Fix implicit include directory extraction for adaptive relative paths

In some cases GCC reports *relative* implicit include directories.  They
are computed adaptively with respect to the current working directory
such that the effective implicit include directory is an unchanging
absolute path.  Teach our implicit include directory extraction to
recognize such paths and normalize them.

Fixes: #19133
This commit is contained in:
Brad King
2019-04-08 10:04:05 -04:00
parent 6bc6fc2a7f
commit ef41d49812
6 changed files with 53 additions and 0 deletions

View File

@@ -216,6 +216,14 @@ function(cmake_parse_implicit_include_info text lang dir_var log_var state_var)
get_filename_component(dir "${d}" ABSOLUTE)
list(APPEND implicit_dirs "${dir}")
string(APPEND log " collapse include dir [${d}] ==> [${dir}]\n")
elseif("${d}" MATCHES [[^\.\.[\/]\.\.[\/](.*)$]])
# This relative path is deep enough to get out of the CMakeFiles/CMakeTmp
# directory where the ABI check is done. Assume that the compiler has
# computed this path adaptively based on the current working directory
# such that the effective result is absolute.
get_filename_component(dir "${CMAKE_BINARY_DIR}/${CMAKE_MATCH_1}" ABSOLUTE)
list(APPEND implicit_dirs "${dir}")
string(APPEND log " collapse relative include dir [${d}] ==> [${dir}]\n")
else()
string(APPEND log " skipping relative include dir [${d}]\n")
endif()

View File

@@ -19,6 +19,7 @@ set(targets
darwin_nostdinc-CXX-AppleClang-8.0.0.8000042
freebsd-C-Clang-3.3.0 freebsd-CXX-Clang-3.3.0 freebsd-Fortran-GNU-4.6.4
hand-C-empty hand-CXX-empty
hand-C-relative hand-CXX-relative
linux-C-GNU-7.3.0 linux-CXX-GNU-7.3.0 linux-Fortran-GNU-7.3.0
linux-C-Intel-18.0.0.20170811 linux-CXX-Intel-18.0.0.20170811
linux-C-PGI-18.10.1 linux-CXX-PGI-18.10.1

View File

@@ -0,0 +1,21 @@
CMAKE_LANG=C
CMAKE_C_COMPILER_ABI=ELF
CMAKE_C_COMPILER_AR=/usr/bin/gcc-ar-7
CMAKE_C_COMPILER_ARCHITECTURE_ID=
CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN=
CMAKE_C_COMPILER_ID=GNU
CMAKE_C_COMPILER_LAUNCHER=
CMAKE_C_COMPILER_LOADED=1
CMAKE_C_COMPILER_RANLIB=/usr/bin/gcc-ranlib-7
CMAKE_C_COMPILER_TARGET=
CMAKE_C_COMPILER_VERSION=7.3.0
CMAKE_C_COMPILER_VERSION_INTERAL=
This is a hand-written test case.
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
../../../adaptive/relative/include
/usr/include
End of search list.

View File

@@ -0,0 +1 @@
/usr/local/include;[^;]*/Tests/RunCMake/ParseImplicitIncludeInfo/adaptive/relative/include;/usr/include

View File

@@ -0,0 +1,21 @@
CMAKE_LANG=CXX
CMAKE_CXX_COMPILER_ABI=ELF
CMAKE_CXX_COMPILER_AR=/usr/bin/gcc-ar-7
CMAKE_CXX_COMPILER_ARCHITECTURE_ID=
CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN=
CMAKE_CXX_COMPILER_ID=GNU
CMAKE_CXX_COMPILER_LAUNCHER=
CMAKE_CXX_COMPILER_LOADED=1
CMAKE_CXX_COMPILER_RANLIB=/usr/bin/gcc-ranlib-7
CMAKE_CXX_COMPILER_TARGET=
CMAKE_CXX_COMPILER_VERSION=7.3.0
CMAKE_CXX_COMPILER_VERSION_INTERAL=
This is a hand-written test case.
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
../../../adaptive/relative/include
/usr/include
End of search list.

View File

@@ -0,0 +1 @@
/usr/local/include;[^;]*/Tests/RunCMake/ParseImplicitIncludeInfo/adaptive/relative/include;/usr/include