From 90a34ff79196c90b64ab16066f957e51a78a7375 Mon Sep 17 00:00:00 2001 From: Raul Laasner Date: Wed, 16 Aug 2017 14:12:35 -0400 Subject: Ninja: Fix references to source files in gfortran diagnostics The Ninja generator preprocesses and compiles separately for Fortran. When compiling, tell gfortran that the source is already preprocessed so that it will honor the `# ` directives when producing diagnostics messages. Fixes: #17160 --- Modules/Compiler/GNU-Fortran.cmake | 2 ++ Source/cmNinjaTargetGenerator.cxx | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Modules/Compiler/GNU-Fortran.cmake b/Modules/Compiler/GNU-Fortran.cmake index 94dc275..c333d50 100644 --- a/Modules/Compiler/GNU-Fortran.cmake +++ b/Modules/Compiler/GNU-Fortran.cmake @@ -7,6 +7,8 @@ set(CMAKE_Fortran_PREPROCESS_SOURCE set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-ffixed-form") set(CMAKE_Fortran_FORMAT_FREE_FLAG "-ffree-form") +set(CMAKE_Fortran_POSTPROCESS_FLAG "-fpreprocessed") + # No -DNDEBUG for Fortran. string(APPEND CMAKE_Fortran_FLAGS_MINSIZEREL_INIT " -Os") string(APPEND CMAKE_Fortran_FLAGS_RELEASE_INIT " -O3") diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 7cc6ede..4b16dc7 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -891,9 +891,15 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( // The actual compilation will now use the preprocessed source. explicitDeps.push_back(ppFileName); - // Preprocessing and compilation use the same flags. + // Preprocessing and compilation generally use the same flags. ppVars["FLAGS"] = vars["FLAGS"]; + // In case compilation requires flags that are incompatible with + // preprocessing, include them here. + std::string const postFlag = + this->Makefile->GetSafeDefinition("CMAKE_Fortran_POSTPROCESS_FLAG"); + this->LocalGenerator->AppendFlags(vars["FLAGS"], postFlag); + // Move preprocessor definitions to the preprocessor build statement. std::swap(ppVars["DEFINES"], vars["DEFINES"]); -- cgit v0.12