Fortran: Do not suppress explicit use of implicit include directories

Since commit 2e91627dea (ParseImplicitIncludeInfo: add Fortran implicit
include handling, 2019-01-25, v3.14.0-rc1~73^2) we actually populate
`CMAKE_Fortran_IMPLICIT_INCLUDE_DIRECTORIES` for the first time.  This
value may be useful to project code to pass to other tooling that wants
to preprocess the way Fortran does, so we should compute the value.
However, compilers like `gfortran` do not actually search their own
implicit include directories for `.mod` files.  The directories must be
passed via `-I` in order for `.mod` files in them to be found.

Since Fortran has no standard library header files that we need to avoid
overriding, it is safe to *not* filter out implicit include directories
from those passed explicitly via `-I` options.  Skip this filtering so
that include directories specified by project code to find `.mod` files
will be searched by the compiler even if they happen to be implicitly
searched by the preprocessor.

Fixes: #18914
This commit is contained in:
Brad King 2019-02-20 08:13:01 -05:00
parent 890bae524c
commit 3dc81a48ff
2 changed files with 21 additions and 10 deletions

View File

@ -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.

View File

@ -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]);
}
}
}