summaryrefslogtreecommitdiffstats
path: root/Source/cmGlobalNinjaGenerator.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2019-05-15 13:21:59 (GMT)
committerKitware Robot <kwrobot@kitware.com>2019-05-15 13:22:18 (GMT)
commit66efdbd21a46b63572f5de677ed126a68e524e7a (patch)
treeca828de9a043ff83bd321185b1c23de9a6b2a788 /Source/cmGlobalNinjaGenerator.cxx
parent0064edf4173fad72749da2c66753387e9a671223 (diff)
parentb5bf369ec68a60bf71297e941bcc742904aae148 (diff)
downloadCMake-66efdbd21a46b63572f5de677ed126a68e524e7a.zip
CMake-66efdbd21a46b63572f5de677ed126a68e524e7a.tar.gz
CMake-66efdbd21a46b63572f5de677ed126a68e524e7a.tar.bz2
Merge topic 'additional_clean_files'
b5bf369ec6 Release notes: Add release notes for ADDITIONAL_CLEAN_FILES properties 4e2ce0a67a Doc: Update and deprecate ADDITIONAL_MAKE_CLEAN_FILES directory property 338994d65d Doc: Add documentation for ADDITIONAL_CLEAN_FILES properties c11f089d73 Tests: Extend MakeClean test to cover ADDITIONAL_CLEAN_FILES 012d599e26 Ninja: Add support for ADDITIONAL_CLEAN_FILES target property 890a1b9dc3 Ninja: Add support for ADDITIONAL_CLEAN_FILES directory property 7b23001f20 Ninja: Add support for additional clean files d745df4b01 Makefiles: Add support for ADDITIONAL_CLEAN_FILES target property ... Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !3318
Diffstat (limited to 'Source/cmGlobalNinjaGenerator.cxx')
-rw-r--r--Source/cmGlobalNinjaGenerator.cxx102
1 files changed, 95 insertions, 7 deletions
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx
index 67c22a7..00276f8 100644
--- a/Source/cmGlobalNinjaGenerator.cxx
+++ b/Source/cmGlobalNinjaGenerator.cxx
@@ -855,6 +855,11 @@ std::string const& cmGlobalNinjaGenerator::ConvertToNinjaPath(
.first->second;
}
+void cmGlobalNinjaGenerator::AddAdditionalCleanFile(std::string fileName)
+{
+ this->AdditionalCleanFiles.emplace(std::move(fileName));
+}
+
void cmGlobalNinjaGenerator::AddCXXCompileCommand(
const std::string& commandLine, const std::string& sourceFile)
{
@@ -1468,8 +1473,80 @@ bool cmGlobalNinjaGenerator::SupportsMultilineDepfile() const
return this->NinjaSupportsMultilineDepfile;
}
+bool cmGlobalNinjaGenerator::WriteTargetCleanAdditional(std::ostream& os)
+{
+ cmLocalGenerator* lgr = this->LocalGenerators.at(0);
+ std::string cleanScriptRel = "CMakeFiles/clean_additional.cmake";
+ std::string cleanScriptAbs = lgr->GetBinaryDirectory();
+ cleanScriptAbs += '/';
+ cleanScriptAbs += cleanScriptRel;
+
+ // Check if there are additional files to clean
+ if (this->AdditionalCleanFiles.empty()) {
+ // Remove cmake clean script file if it exists
+ cmSystemTools::RemoveFile(cleanScriptAbs);
+ return false;
+ }
+
+ // Write cmake clean script file
+ {
+ cmGeneratedFileStream fout(cleanScriptAbs);
+ if (!fout) {
+ return false;
+ }
+ fout << "# Additional clean files\n\n";
+ fout << "file(REMOVE_RECURSE\n";
+ for (std::string const& acf : this->AdditionalCleanFiles) {
+ fout << " "
+ << cmOutputConverter::EscapeForCMake(ConvertToNinjaPath(acf))
+ << '\n';
+ }
+ fout << ")\n";
+ }
+ // Register clean script file
+ lgr->GetMakefile()->AddCMakeOutputFile(cleanScriptAbs);
+
+ // Write rule
+ {
+ std::string cmd = CMakeCmd();
+ cmd += " -P ";
+ cmd += lgr->ConvertToOutputFormat(this->NinjaOutputPath(cleanScriptRel),
+ cmOutputConverter::SHELL);
+ WriteRule(*this->RulesFileStream, "CLEAN_ADDITIONAL", cmd,
+ "Cleaning additional files...",
+ "Rule for cleaning additional files.",
+ /*depfile=*/"",
+ /*deptype=*/"",
+ /*rspfile=*/"",
+ /*rspcontent*/ "",
+ /*restat=*/"",
+ /*generator=*/false);
+ }
+
+ // Write build
+ {
+ cmNinjaDeps outputs;
+ outputs.emplace_back(
+ this->NinjaOutputPath(this->GetAdditionalCleanTargetName()));
+ WriteBuild(os, "Clean additional files.", "CLEAN_ADDITIONAL",
+ /*outputs=*/outputs,
+ /*implicitOuts=*/cmNinjaDeps(),
+ /*explicitDeps=*/cmNinjaDeps(),
+ /*implicitDeps=*/cmNinjaDeps(),
+ /*orderOnlyDeps=*/cmNinjaDeps(),
+ /*variables=*/cmNinjaVars());
+ }
+ // Return success
+ return true;
+}
+
void cmGlobalNinjaGenerator::WriteTargetClean(std::ostream& os)
{
+ // -- Additional clean target
+ bool additionalFiles = WriteTargetCleanAdditional(os);
+
+ // -- Default clean target
+ // Write rule
WriteRule(*this->RulesFileStream, "CLEAN", NinjaCmd() + " -t clean",
"Cleaning all built files...",
"Rule for cleaning all built files.",
@@ -1479,13 +1556,24 @@ void cmGlobalNinjaGenerator::WriteTargetClean(std::ostream& os)
/*rspcontent*/ "",
/*restat=*/"",
/*generator=*/false);
- WriteBuild(os, "Clean all the built files.", "CLEAN",
- /*outputs=*/cmNinjaDeps(1, this->NinjaOutputPath("clean")),
- /*implicitOuts=*/cmNinjaDeps(),
- /*explicitDeps=*/cmNinjaDeps(),
- /*implicitDeps=*/cmNinjaDeps(),
- /*orderOnlyDeps=*/cmNinjaDeps(),
- /*variables=*/cmNinjaVars());
+
+ // Write build
+ {
+ cmNinjaDeps explicitDeps;
+ if (additionalFiles) {
+ explicitDeps.emplace_back(
+ this->NinjaOutputPath(this->GetAdditionalCleanTargetName()));
+ }
+ cmNinjaDeps outputs;
+ outputs.emplace_back(this->NinjaOutputPath(this->GetCleanTargetName()));
+ WriteBuild(os, "Clean all the built files.", "CLEAN",
+ /*outputs=*/outputs,
+ /*implicitOuts=*/cmNinjaDeps(),
+ /*explicitDeps=*/explicitDeps,
+ /*implicitDeps=*/cmNinjaDeps(),
+ /*orderOnlyDeps=*/cmNinjaDeps(),
+ /*variables=*/cmNinjaVars());
+ }
}
void cmGlobalNinjaGenerator::WriteTargetHelp(std::ostream& os)