diff options
-rw-r--r-- | Help/variable/CMAKE_LANG_IMPLICIT_INCLUDE_DIRECTORIES.rst | 7 | ||||
-rw-r--r-- | Source/cmLocalGenerator.cxx | 24 |
2 files changed, 21 insertions, 10 deletions
diff --git a/Help/variable/CMAKE_LANG_IMPLICIT_INCLUDE_DIRECTORIES.rst b/Help/variable/CMAKE_LANG_IMPLICIT_INCLUDE_DIRECTORIES.rst index cc80851074..e361fd98e7 100644 --- a/Help/variable/CMAKE_LANG_IMPLICIT_INCLUDE_DIRECTORIES.rst +++ b/Help/variable/CMAKE_LANG_IMPLICIT_INCLUDE_DIRECTORIES.rst @@ -6,4 +6,9 @@ Directories implicitly searched by the compiler for header files. CMake does not explicitly specify these directories on compiler command lines for language ``<LANG>``. This prevents system include directories from being treated as user include directories on some -compilers. +compilers, which is important for ``C``, ``CXX``, and ``CUDA`` to +avoid overriding standard library headers. + +This value is not used for ``Fortran`` because it has no standard +library headers and some compilers do not search their implicit +include directories for module ``.mod`` files. diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 8b01af156c..7e568188b9 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -947,15 +947,21 @@ std::vector<BT<std::string>> cmLocalGenerator::GetIncludeDirectoriesImplicit( std::vector<std::string> impDirVec = userStandardDirs; // Load implicit include directories for this language. - std::string key = "CMAKE_"; - key += lang; - key += "_IMPLICIT_INCLUDE_DIRECTORIES"; - if (const char* value = this->Makefile->GetDefinition(key)) { - size_t const impDirVecOldSize = impDirVec.size(); - cmSystemTools::ExpandListArgument(value, impDirVec); - // FIXME: Use cmRange with 'advance()' when it supports non-const. - for (size_t i = impDirVecOldSize; i < impDirVec.size(); ++i) { - cmSystemTools::ConvertToUnixSlashes(impDirVec[i]); + // We ignore this for Fortran because: + // * There are no standard library headers to avoid overriding. + // * Compilers like gfortran do not search their own implicit include + // directories for modules ('.mod' files). + if (lang != "Fortran") { + std::string key = "CMAKE_"; + key += lang; + key += "_IMPLICIT_INCLUDE_DIRECTORIES"; + if (const char* value = this->Makefile->GetDefinition(key)) { + size_t const impDirVecOldSize = impDirVec.size(); + cmSystemTools::ExpandListArgument(value, impDirVec); + // FIXME: Use cmRange with 'advance()' when it supports non-const. + for (size_t i = impDirVecOldSize; i < impDirVec.size(); ++i) { + cmSystemTools::ConvertToUnixSlashes(impDirVec[i]); + } } } |