From 144cc6f1f9020433cb4a94f072fc74f1202ce1f3 Mon Sep 17 00:00:00 2001 From: Nils Gladitz Date: Fri, 23 Sep 2016 22:59:37 +0200 Subject: [PATCH] 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 --- Source/cmNinjaTargetGenerator.cxx | 12 ++++++++++++ Tests/FortranModules/CMakeLists.txt | 2 ++ Tests/FortranModules/non_pp_include.f90 | 3 +++ Tests/FortranModules/test_non_pp_include_main.f90 | 5 +++++ 4 files changed, 22 insertions(+) create mode 100644 Tests/FortranModules/non_pp_include.f90 create mode 100644 Tests/FortranModules/test_non_pp_include_main.f90 diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index b418ce380..f88eb7bb2 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 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 ff1277146..399660002 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 000000000..7eb172596 --- /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 000000000..8a04fbdf4 --- /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