summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2019-02-13 10:05:48 -0500
committerBrad King <brad.king@kitware.com>2019-02-13 10:05:48 -0500
commit30783addc12d82081575f5a7577d7b4953cbd55c (patch)
treea1063c192015125161ca311363b1362376d0833f /Source
parent1c4570e22eb7fcf312426e4e1fb0db0c2a3d5d33 (diff)
parent6fc33829443ea3ef2dc8cc71c0a98b635bec6179 (diff)
downloadcmake-30783addc12d82081575f5a7577d7b4953cbd55c.tar.gz
Merge branch 'fix-legacy-implicit-includes' into release-3.14
Merge-request: !2957
Diffstat (limited to 'Source')
-rw-r--r--Source/cmAlgorithms.h8
-rw-r--r--Source/cmLocalGenerator.cxx28
2 files changed, 29 insertions, 7 deletions
diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h
index 9e3efd30ae..d38b0d1251 100644
--- a/Source/cmAlgorithms.h
+++ b/Source/cmAlgorithms.h
@@ -336,6 +336,14 @@ std::reverse_iterator<Iter> cmMakeReverseIterator(Iter it)
return std::reverse_iterator<Iter>(it);
}
+inline bool cmHasPrefix(std::string const& str, std::string const& prefix)
+{
+ if (str.size() < prefix.size()) {
+ return false;
+ }
+ return str.compare(0, prefix.size(), prefix) == 0;
+}
+
inline bool cmHasSuffix(const std::string& str, const std::string& suffix)
{
if (str.size() < suffix.size()) {
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 252aa4c213..8090e0065d 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -935,16 +935,11 @@ std::vector<BT<std::string>> cmLocalGenerator::GetIncludeDirectoriesImplicit(
} else {
rootPath = this->Makefile->GetSafeDefinition("CMAKE_SYSROOT");
}
+ cmSystemTools::ConvertToUnixSlashes(rootPath);
// Raw list of implicit include directories
std::vector<std::string> impDirVec;
- // Get platform-wide implicit directories.
- if (const char* implicitIncludes = (this->Makefile->GetDefinition(
- "CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES"))) {
- cmSystemTools::ExpandListArgument(implicitIncludes, impDirVec);
- }
-
// Load implicit include directories for this language.
std::string key = "CMAKE_";
key += lang;
@@ -953,9 +948,28 @@ std::vector<BT<std::string>> cmLocalGenerator::GetIncludeDirectoriesImplicit(
cmSystemTools::ExpandListArgument(value, impDirVec);
}
+ // The Platform/UnixPaths module used to hard-code /usr/include for C, CXX,
+ // and CUDA in CMAKE_<LANG>_IMPLICIT_INCLUDE_DIRECTORIES, but those
+ // variables are now computed. On macOS the /usr/include directory is
+ // inside the platform SDK so the computed value does not contain it
+ // directly. In this case adding -I/usr/include can hide SDK headers so we
+ // must still exclude it.
+ if ((lang == "C" || lang == "CXX" || lang == "CUDA") &&
+ std::find(impDirVec.begin(), impDirVec.end(), "/usr/include") ==
+ impDirVec.end() &&
+ std::find_if(impDirVec.begin(), impDirVec.end(),
+ [](std::string const& d) {
+ return cmHasLiteralSuffix(d, "/usr/include");
+ }) != impDirVec.end()) {
+ impDirVec.emplace_back("/usr/include");
+ }
+
for (std::string const& i : impDirVec) {
- std::string imd = rootPath + i;
+ std::string imd = i;
cmSystemTools::ConvertToUnixSlashes(imd);
+ if (!rootPath.empty() && !cmHasPrefix(imd, rootPath)) {
+ imd = rootPath + imd;
+ }
if (implicitSet.insert(imd).second) {
implicitDirs.emplace_back(std::move(imd));
}