diff options
author | Brad King <brad.king@kitware.com> | 2020-11-06 16:26:42 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2020-11-06 16:50:38 (GMT) |
commit | 33a8e0bb093f33fb0c206c820fe3b3945cae5a78 (patch) | |
tree | 32e5a7d53739449ed0403cd7bcaffe49f8c88c3d | |
parent | bff1871c3922a1730ea61a0b155d1ebad5d254c3 (diff) | |
download | CMake-33a8e0bb093f33fb0c206c820fe3b3945cae5a78.zip CMake-33a8e0bb093f33fb0c206c820fe3b3945cae5a78.tar.gz CMake-33a8e0bb093f33fb0c206c820fe3b3945cae5a78.tar.bz2 |
cmNinjaTargetGenerator: Simplify scan rule depfile selection
The depfile can always be the first output of the build statement
with a `.d` suffix added. This approach easily avoids conflicts.
-rw-r--r-- | Source/cmNinjaTargetGenerator.cxx | 62 |
1 files changed, 32 insertions, 30 deletions
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 49d2ae2..2b63a09 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -1064,13 +1064,12 @@ cmNinjaBuild GetScanBuildStatement(const std::string& ruleName, const std::string& ppFileName, bool compilePP, bool compilePPWithDefines, cmNinjaBuild& objBuild, cmNinjaVars& vars, - const std::string& depFileName, - const std::string& objectFileName) + const std::string& objectFileName, + cmLocalGenerator* lg) { cmNinjaBuild scanBuild(ruleName); if (!ppFileName.empty()) { - scanBuild.Outputs.push_back(ppFileName); scanBuild.RspFile = cmStrCat(ppFileName, ".rsp"); } else { scanBuild.RspFile = "$out.rsp"; @@ -1109,26 +1108,32 @@ cmNinjaBuild GetScanBuildStatement(const std::string& ruleName, // directive. scanBuild.Variables["INCLUDES"] = vars["INCLUDES"]; - // Explicit preprocessing always uses a depfile. - scanBuild.Variables["DEP_FILE"] = depFileName; - if (compilePP) { - // The actual compilation does not need a depfile because it - // depends on the already-preprocessed source. - vars.erase("DEP_FILE"); - } - // Tell dependency scanner the object file that will result from // compiling the source. scanBuild.Variables["OBJ_FILE"] = objectFileName; // Tell dependency scanner where to store dyndep intermediate results. - std::string const ddiFile = cmStrCat(objectFileName, ".ddi"); - if (ppFileName.empty()) { - scanBuild.Outputs.push_back(ddiFile); - } else { - scanBuild.Variables["DYNDEP_INTERMEDIATE_FILE"] = ddiFile; + std::string const& ddiFile = cmStrCat(objectFileName, ".ddi"); + scanBuild.Variables["DYNDEP_INTERMEDIATE_FILE"] = ddiFile; + + // Outputs of the scan/preprocessor build statement. + if (!ppFileName.empty()) { + scanBuild.Outputs.push_back(ppFileName); scanBuild.ImplicitOuts.push_back(ddiFile); + } else { + scanBuild.Outputs.push_back(ddiFile); } + + // Scanning always uses a depfile for preprocessor dependencies. + std::string const& depFileName = cmStrCat(scanBuild.Outputs.front(), ".d"); + scanBuild.Variables["DEP_FILE"] = + lg->ConvertToOutputFormat(depFileName, cmOutputConverter::SHELL); + if (compilePP) { + // The actual compilation does not need a depfile because it + // depends on the already-preprocessed source. + vars.erase("DEP_FILE"); + } + return scanBuild; } } @@ -1289,22 +1294,19 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( bool const compilePPWithDefines = compilePP && this->CompileWithDefines(language); - std::string const ppFileName = compilePP - ? this->ConvertToNinjaPath(this->GetPreprocessedFilePath(source, config)) - : ""; - - std::string const buildName = compilePP - ? this->LanguagePreprocessAndScanRule(language, config) - : this->LanguageScanRule(language, config); - - const auto depExtension = compilePP ? ".pp.d" : ".d"; - const std::string depFileName = - this->GetLocalGenerator()->ConvertToOutputFormat( - cmStrCat(objectFileName, depExtension), cmOutputConverter::SHELL); + std::string scanRuleName; + std::string ppFileName; + if (compilePP) { + scanRuleName = this->LanguagePreprocessAndScanRule(language, config); + ppFileName = this->ConvertToNinjaPath( + this->GetPreprocessedFilePath(source, config)); + } else { + scanRuleName = this->LanguageScanRule(language, config); + } cmNinjaBuild ppBuild = GetScanBuildStatement( - buildName, ppFileName, compilePP, compilePPWithDefines, objBuild, vars, - depFileName, objectFileName); + scanRuleName, ppFileName, compilePP, compilePPWithDefines, objBuild, + vars, objectFileName, this->LocalGenerator); if (compilePP) { // In case compilation requires flags that are incompatible with |