summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/cmNinjaTargetGenerator.cxx12
-rw-r--r--Tests/FortranModules/CMakeLists.txt2
-rw-r--r--Tests/FortranModules/non_pp_include.f903
-rw-r--r--Tests/FortranModules/test_non_pp_include_main.f905
4 files changed, 22 insertions, 0 deletions
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx
index b418ce3..f88eb7b 100644
--- a/Source/cmNinjaTargetGenerator.cxx
+++ b/Source/cmNinjaTargetGenerator.cxx
@@ -841,6 +841,18 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
// directive.
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.
ppVars["DEP_FILE"] =
cmGlobalNinjaGenerator::EncodeDepfileSpace(ppFileName + ".d");
diff --git a/Tests/FortranModules/CMakeLists.txt b/Tests/FortranModules/CMakeLists.txt
index ff12771..3996600 100644
--- a/Tests/FortranModules/CMakeLists.txt
+++ b/Tests/FortranModules/CMakeLists.txt
@@ -52,6 +52,8 @@ add_definitions(-DFOO -DBAR=1)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
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.
# Make sure it uses the same build configuration as this test.
if(CMAKE_CONFIGURATION_TYPES)
diff --git a/Tests/FortranModules/non_pp_include.f90 b/Tests/FortranModules/non_pp_include.f90
new file mode 100644
index 0000000..7eb1725
--- /dev/null
+++ b/Tests/FortranModules/non_pp_include.f90
@@ -0,0 +1,3 @@
+SUBROUTINE NON_PP_INCLUDE_SUBROUTINE
+ PRINT *, "Hello World!"
+END SUBROUTINE NON_PP_INCLUDE_SUBROUTINE
diff --git a/Tests/FortranModules/test_non_pp_include_main.f90 b/Tests/FortranModules/test_non_pp_include_main.f90
new file mode 100644
index 0000000..8a04fbd
--- /dev/null
+++ b/Tests/FortranModules/test_non_pp_include_main.f90
@@ -0,0 +1,5 @@
+INCLUDE "non_pp_include.f90"
+
+PROGRAM MAINF90
+ CALL NON_PP_INCLUDE_SUBROUTINE
+END PROGRAM MAINF90