Commit 144cc6f1 authored by Nils Gladitz's avatar Nils Gladitz Committed by Brad King
Browse files

Ninja: Add source location as include directory for preprocessed files

Fortran INCLUDE statements are not handled by the preprocessor.

Since the location of the preprocessed file is distinct from the
original source file explicitly add the source file's directory
as an include path in the actual compile step (not the preprocessing step)
so INCLUDE can find it.

Closes: #16332
parent a7218307
Pipeline #28053 passed with stage
...@@ -841,6 +841,18 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( ...@@ -841,6 +841,18 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
// directive. // directive.
ppVars["INCLUDES"] = vars["INCLUDES"]; ppVars["INCLUDES"] = vars["INCLUDES"];
// Prepend source file's original directory as an include directory
// so e.g. Fortran INCLUDE statements can look for files in it.
std::vector<std::string> sourceDirectory;
sourceDirectory.push_back(
cmSystemTools::GetParentDirectory(source->GetFullPath()));
std::string sourceDirectoryFlag = this->LocalGenerator->GetIncludeFlags(
sourceDirectory, this->GeneratorTarget, language, false, false,
this->GetConfigName());
vars["INCLUDES"] = sourceDirectoryFlag + " " + vars["INCLUDES"];
// Explicit preprocessing always uses a depfile. // Explicit preprocessing always uses a depfile.
ppVars["DEP_FILE"] = ppVars["DEP_FILE"] =
cmGlobalNinjaGenerator::EncodeDepfileSpace(ppFileName + ".d"); cmGlobalNinjaGenerator::EncodeDepfileSpace(ppFileName + ".d");
......
...@@ -52,6 +52,8 @@ add_definitions(-DFOO -DBAR=1) ...@@ -52,6 +52,8 @@ add_definitions(-DFOO -DBAR=1)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
add_executable(test_preprocess test_preprocess.F90 test_preprocess_module.F90) add_executable(test_preprocess test_preprocess.F90 test_preprocess_module.F90)
add_executable(test_non_pp_include test_non_pp_include_main.f90)
# Build the external project separately using a custom target. # Build the external project separately using a custom target.
# Make sure it uses the same build configuration as this test. # Make sure it uses the same build configuration as this test.
if(CMAKE_CONFIGURATION_TYPES) if(CMAKE_CONFIGURATION_TYPES)
......
SUBROUTINE NON_PP_INCLUDE_SUBROUTINE
PRINT *, "Hello World!"
END SUBROUTINE NON_PP_INCLUDE_SUBROUTINE
INCLUDE "non_pp_include.f90"
PROGRAM MAINF90
CALL NON_PP_INCLUDE_SUBROUTINE
END PROGRAM MAINF90
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment