diff options
author | Brad King <brad.king@kitware.com> | 2021-04-20 13:59:47 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2021-04-20 13:59:53 (GMT) |
commit | 4c0d69e8131c8fde3446d2d966d3c68cc3bef296 (patch) | |
tree | 338351decb69739c653b4e557bad79e01c4d0e2c /Source | |
parent | 6d30975a9e7256676aa488b318a738a50614885c (diff) | |
parent | 253aff6c94401f468ea8f9c953d325c5a8c72eb0 (diff) | |
download | CMake-4c0d69e8131c8fde3446d2d966d3c68cc3bef296.zip CMake-4c0d69e8131c8fde3446d2d966d3c68cc3bef296.tar.gz CMake-4c0d69e8131c8fde3446d2d966d3c68cc3bef296.tar.bz2 |
Merge topic 'Xcode-add_custom_command-DEPFILE'
253aff6c94 Xcode: Add support of DEPFILE for add_custom_command, part 2
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !6015
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmCustomCommandGenerator.cxx | 4 | ||||
-rw-r--r-- | Source/cmGlobalXCodeGenerator.cxx | 28 | ||||
-rw-r--r-- | Source/cmGlobalXCodeGenerator.h | 9 | ||||
-rw-r--r-- | Source/cmTransformDepfile.cxx | 20 | ||||
-rw-r--r-- | Source/cmTransformDepfile.h | 1 | ||||
-rw-r--r-- | Source/cmcmd.cxx | 2 |
6 files changed, 54 insertions, 10 deletions
diff --git a/Source/cmCustomCommandGenerator.cxx b/Source/cmCustomCommandGenerator.cxx index 7659792..1054beb 100644 --- a/Source/cmCustomCommandGenerator.cxx +++ b/Source/cmCustomCommandGenerator.cxx @@ -226,6 +226,9 @@ cmCustomCommandGenerator::cmCustomCommandGenerator( case cmDepfileFormat::VsTlog: argv.emplace_back("vstlog"); break; + case cmDepfileFormat::MakeDepfile: + argv.emplace_back("makedepfile"); + break; } argv.push_back(this->LG->GetSourceDirectory()); argv.push_back(this->LG->GetCurrentSourceDirectory()); @@ -430,6 +433,7 @@ std::string cmCustomCommandGenerator::GetInternalDepfileName( std::string extension; switch (*this->LG->GetGlobalGenerator()->DepfileFormat()) { case cmDepfileFormat::GccDepfile: + case cmDepfileFormat::MakeDepfile: extension = ".d"; break; case cmDepfileFormat::VsTlog: diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index dc3d3f2..92dd555 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -2213,9 +2213,33 @@ void cmGlobalXCodeGenerator::CreateCustomRulesMakefile( } } makefileStream << "\n\n"; + + auto depfilesDirectory = + cmStrCat(target->GetLocalGenerator()->GetCurrentBinaryDirectory(), + "/CMakeFiles/d/"); + for (auto const& command : commands) { - cmCustomCommandGenerator ccg(command, configName, - this->CurrentLocalGenerator); + cmCustomCommandGenerator ccg( + command, configName, this->CurrentLocalGenerator, true, {}, + [this, &depfilesDirectory](const std::string& config, + const std::string& file) -> std::string { + return cmStrCat( + depfilesDirectory, + this->GetObjectId(cmXCodeObject::PBXShellScriptBuildPhase, file), + ".", config, ".d"); + }); + + auto depfile = ccg.GetInternalDepfile(); + if (!depfile.empty()) { + makefileStream << "include " + << cmSystemTools::ConvertToOutputPath(depfile) << "\n\n"; + + cmSystemTools::MakeDirectory(depfilesDirectory); + if (!cmSystemTools::FileExists(depfile)) { + cmSystemTools::Touch(depfile, true); + } + } + std::vector<std::string> realDepends; realDepends.reserve(ccg.GetDepends().size()); for (auto const& d : ccg.GetDepends()) { diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h index 2406472..ef61601 100644 --- a/Source/cmGlobalXCodeGenerator.h +++ b/Source/cmGlobalXCodeGenerator.h @@ -115,13 +115,12 @@ public: /** * Used to determine if this generator supports DEPFILE option. */ - bool SupportsCustomCommandDepfile() const override - { - return this->XcodeBuildSystem >= BuildSystem::Twelve; - } + bool SupportsCustomCommandDepfile() const override { return true; } virtual cm::optional<cmDepfileFormat> DepfileFormat() const override { - return cmDepfileFormat::GccDepfile; + return this->XcodeBuildSystem == BuildSystem::One + ? cmDepfileFormat::MakeDepfile + : cmDepfileFormat::GccDepfile; } bool SetSystemName(std::string const& s, cmMakefile* mf) override; diff --git a/Source/cmTransformDepfile.cxx b/Source/cmTransformDepfile.cxx index b693582..6e0366c 100644 --- a/Source/cmTransformDepfile.cxx +++ b/Source/cmTransformDepfile.cxx @@ -36,8 +36,9 @@ void WriteFilenameGcc(cmsys::ofstream& fout, const std::string& filename) } } -void WriteGccDepfile(cmsys::ofstream& fout, const cmLocalGenerator& lg, - const cmGccDepfileContent& content) +void WriteDepfile(cmDepfileFormat format, cmsys::ofstream& fout, + const cmLocalGenerator& lg, + const cmGccDepfileContent& content) { const auto& binDir = lg.GetBinaryDirectory(); std::function<std::string(const std::string&)> formatPath = @@ -65,6 +66,18 @@ void WriteGccDepfile(cmsys::ofstream& fout, const cmLocalGenerator& lg, } fout << '\n'; } + + if (format == cmDepfileFormat::MakeDepfile) { + // In this case, phony targets must be added for all dependencies + fout << "\n"; + for (auto const& dep : content) { + for (auto const& path : dep.paths) { + fout << "\n"; + WriteFilenameGcc(fout, formatPath(path)); + fout << ":\n"; + } + } + } } // tlog format : always windows paths on Windows regardless the generator @@ -122,7 +135,8 @@ bool cmTransformDepfile(cmDepfileFormat format, const cmLocalGenerator& lg, } switch (format) { case cmDepfileFormat::GccDepfile: - WriteGccDepfile(fout, lg, content); + case cmDepfileFormat::MakeDepfile: + WriteDepfile(format, fout, lg, content); break; case cmDepfileFormat::VsTlog: WriteVsTlog(fout, lg, content); diff --git a/Source/cmTransformDepfile.h b/Source/cmTransformDepfile.h index c43a45f..c31e4ab 100644 --- a/Source/cmTransformDepfile.h +++ b/Source/cmTransformDepfile.h @@ -8,6 +8,7 @@ enum class cmDepfileFormat { GccDepfile, VsTlog, + MakeDepfile }; class cmLocalGenerator; diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 928435e..2c2ae4d 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -1527,6 +1527,8 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args, format = cmDepfileFormat::GccDepfile; } else if (args[3] == "vstlog") { format = cmDepfileFormat::VsTlog; + } else if (args[3] == "makedepfile") { + format = cmDepfileFormat::MakeDepfile; } else { return 1; } |