diff options
author | Peter Hill <zed.three@gmail.com> | 2020-05-08 11:25:57 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2020-05-21 15:46:32 (GMT) |
commit | 3888de23daca814d66a40642d3e369a5c4747131 (patch) | |
tree | 5cd424b87c1a866453f8e7fe27b37ad24931b4e9 /Source | |
parent | 66c4e87282176328bc2764afd53015dffd42d7f5 (diff) | |
download | CMake-3888de23daca814d66a40642d3e369a5c4747131.zip CMake-3888de23daca814d66a40642d3e369a5c4747131.tar.gz CMake-3888de23daca814d66a40642d3e369a5c4747131.tar.bz2 |
Ninja: Skip Fortran preprocessing if Fortran_PREPROCESS is OFF
If `Fortran_PREPROCESS` is explicitly turned off for a source file then
we know it does not need to be preprocessed. Teach the Ninja generator
to skip preprocessing in this case. Otherwise we still must preprocess
just in case.
Fixes: #18870
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmNinjaTargetGenerator.cxx | 64 | ||||
-rw-r--r-- | Source/cmNinjaTargetGenerator.h | 2 |
2 files changed, 56 insertions, 10 deletions
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 63e95ee..a499bc8 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -106,7 +106,16 @@ std::string cmNinjaTargetGenerator::LanguagePreprocessRule( std::string const& lang, const std::string& config) const { return cmStrCat( - lang, "_PREPROCESS__", + lang, "_PREPROCESS_SCAN__", + cmGlobalNinjaGenerator::EncodeRuleName(this->GeneratorTarget->GetName()), + '_', config); +} + +std::string cmNinjaTargetGenerator::LanguageDependencyRule( + std::string const& lang, const std::string& config) const +{ + return cmStrCat( + lang, "_SCAN__", cmGlobalNinjaGenerator::EncodeRuleName(this->GeneratorTarget->GetName()), '_', config); } @@ -671,6 +680,22 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang, // Remove preprocessor definitions from compilation step vars.Defines = ""; } + + // Just dependency scanning for files that have preprocessing turned off + const auto scanCommand = + GetScanCommand(cmakeCmd, tdi, lang, "$in", needDyndep, "$out"); + + auto scanRule = GetPreprocessScanRule( + this->LanguageDependencyRule(lang, config), vars, "", flags, launcher, + rulePlaceholderExpander.get(), scanCommand, this->GetLocalGenerator()); + + // Write the rule for generating dependencies for the given language. + scanRule.Comment = cmStrCat("Rule for generating ", lang, + " dependencies on non-preprocessed files."); + scanRule.Description = + cmStrCat("Generating ", lang, " dependencies for $in"); + + this->GetGlobalGenerator()->AddRule(scanRule); } if (needDyndep) { @@ -1091,8 +1116,12 @@ cmNinjaBuild GetPreprocessOrScanBuild( // Tell dependency scanner where to store dyndep intermediate results. std::string const ddiFile = cmStrCat(objectFileName, ".ddi"); - ppBuild.Variables["DYNDEP_INTERMEDIATE_FILE"] = ddiFile; - ppBuild.ImplicitOuts.push_back(ddiFile); + if (ppFileName.empty()) { + ppBuild.Outputs.push_back(ddiFile); + } else { + ppBuild.Variables["DYNDEP_INTERMEDIATE_FILE"] = ddiFile; + ppBuild.ImplicitOuts.push_back(ddiFile); + } } return ppBuild; } @@ -1237,19 +1266,34 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( bool const explicitPP = this->NeedExplicitPreprocessing(language); if (explicitPP) { - bool const compilePP = this->UsePreprocessedSource(language); + // If source/target has preprocessing turned off, we still need to + // generate an explicit dependency step + const auto srcpp = source->GetSafeProperty("Fortran_PREPROCESS"); + cmOutputConverter::FortranPreprocess preprocess = + cmOutputConverter::GetFortranPreprocess(srcpp); + if (preprocess == cmOutputConverter::FortranPreprocess::Unset) { + const auto& tgtpp = + this->GeneratorTarget->GetSafeProperty("Fortran_PREPROCESS"); + preprocess = cmOutputConverter::GetFortranPreprocess(tgtpp); + } + + bool const compilePP = this->UsePreprocessedSource(language) && + (preprocess != cmOutputConverter::FortranPreprocess::NotNeeded); bool const compilePPWithDefines = compilePP && this->CompilePreprocessedSourceWithDefines(language); - std::string const ppFileName = - this->ConvertToNinjaPath(this->GetPreprocessedFilePath(source, config)); + std::string const ppFileName = compilePP + ? this->ConvertToNinjaPath(this->GetPreprocessedFilePath(source, config)) + : ""; - std::string const buildName = - this->LanguagePreprocessRule(language, config); + std::string const buildName = compilePP + ? this->LanguagePreprocessRule(language, config) + : this->LanguageDependencyRule(language, config); + const auto depExtension = compilePP ? ".pp.d" : ".d"; const std::string depFileName = this->GetLocalGenerator()->ConvertToOutputFormat( - cmStrCat(objectFileName, ".pp.d"), cmOutputConverter::SHELL); + cmStrCat(objectFileName, depExtension), cmOutputConverter::SHELL); cmNinjaBuild ppBuild = GetPreprocessOrScanBuild( buildName, ppFileName, compilePP, compilePPWithDefines, objBuild, vars, @@ -1276,7 +1320,7 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( } if (firstForConfig && needDyndep) { - const std::string& ddiFile = ppBuild.ImplicitOuts.back(); + std::string const ddiFile = cmStrCat(objectFileName, ".ddi"); this->Configs[config].DDIFiles[language].push_back(ddiFile); } diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h index 8678dc3..2e0a511 100644 --- a/Source/cmNinjaTargetGenerator.h +++ b/Source/cmNinjaTargetGenerator.h @@ -70,6 +70,8 @@ protected: const std::string& config) const; std::string LanguagePreprocessRule(std::string const& lang, const std::string& config) const; + std::string LanguageDependencyRule(std::string const& lang, + const std::string& config) const; bool NeedExplicitPreprocessing(std::string const& lang) const; std::string LanguageDyndepRule(std::string const& lang, const std::string& config) const; |