diff options
author | Brad King <brad.king@kitware.com> | 2019-05-29 14:40:09 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-05-30 13:24:59 (GMT) |
commit | 2d0b0e2b9d50aa14ccf345c727b2da73dfba9bd6 (patch) | |
tree | a47622e41b44f79aa0c1574707efa1576283338e /Source/cmLocalGenerator.cxx | |
parent | f872033d7531ed1d7d7345ff7873442ec8dbcee1 (diff) | |
download | CMake-2d0b0e2b9d50aa14ccf345c727b2da73dfba9bd6.zip CMake-2d0b0e2b9d50aa14ccf345c727b2da73dfba9bd6.tar.gz CMake-2d0b0e2b9d50aa14ccf345c727b2da73dfba9bd6.tar.bz2 |
Do not exclude include directories made implicit by CPATH
Entries of the `CPATH` environment variable are implicitly searched as
include directories by some C/C++ compilers. Since commit 5990ecb741
(Compute implicit include directories from compiler output, 2018-12-07,
v3.14.0-rc1~108^2) these entries are detected by CMake and included in
the `CMAKE_{C,CXX}_IMPLICIT_INCLUDE_DIRECTORIES` variables.
However, we should not exclude them from explicit specification via `-I`
or particularly `-isystem` because they are meant as user-specified
include directories that can be re-ordered without breaking compiler
builtin headers. In particular, we need explicit requests via
`include_directories` with the `SYSTEM` option to result in `-isystem`
so that third-party headers do not produce warnings.
Co-Author: Ben Boeckel <ben.boeckel@kitware.com>
Fixes: #19291
Diffstat (limited to 'Source/cmLocalGenerator.cxx')
-rw-r--r-- | Source/cmLocalGenerator.cxx | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 7e15234..f6962d1 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -88,6 +88,19 @@ cmLocalGenerator::cmLocalGenerator(cmGlobalGenerator* gg, cmMakefile* makefile) this->ComputeObjectMaxPath(); + // Canonicalize entries of the CPATH environment variable the same + // way detection of CMAKE_<LANG>_IMPLICIT_INCLUDE_DIRECTORIES does. + { + std::vector<std::string> cpath; + cmSystemTools::GetPath(cpath, "CPATH"); + for (std::string& cp : cpath) { + if (cmSystemTools::FileIsFullPath(cp)) { + cp = cmSystemTools::CollapseFullPath(cp); + this->EnvCPATH.emplace(std::move(cp)); + } + } + } + std::vector<std::string> enabledLanguages = this->GetState()->GetEnabledLanguages(); @@ -988,9 +1001,18 @@ std::vector<BT<std::string>> cmLocalGenerator::GetIncludeDirectoriesImplicit( } // Checks if this is not an excluded (implicit) include directory. - auto notExcluded = [&implicitSet, &implicitExclude](std::string const& dir) { - return ((implicitSet.find(dir) == implicitSet.end()) && - (implicitExclude.find(dir) == implicitExclude.end())); + auto notExcluded = [this, &implicitSet, &implicitExclude, + &lang](std::string const& dir) { + return ( + // Do not exclude directories that are not in an excluded set. + ((implicitSet.find(dir) == implicitSet.end()) && + (implicitExclude.find(dir) == implicitExclude.end())) + // Do not exclude entries of the CPATH environment variable even though + // they are implicitly searched by the compiler. They are meant to be + // user-specified directories that can be re-ordered or converted to + // -isystem without breaking real compiler builtin headers. + || ((lang == "C" || lang == "CXX") && + (this->EnvCPATH.find(dir) != this->EnvCPATH.end()))); }; // Get the target-specific include directories. |