summaryrefslogtreecommitdiffstats
path: root/Source/cmGlobalXCodeGenerator.cxx
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@gmail.com>2021-04-15 12:13:57 (GMT)
committerBrad King <brad.king@kitware.com>2021-04-15 16:17:31 (GMT)
commitd67cc4882d54a18abbd5d01365ce1fc72d702a0e (patch)
treed609494ba1f13292a45d92630b47c4094ad2cc82 /Source/cmGlobalXCodeGenerator.cxx
parent498b916cdd96330baa33bc10667b43cbb78674d4 (diff)
downloadCMake-d67cc4882d54a18abbd5d01365ce1fc72d702a0e.zip
CMake-d67cc4882d54a18abbd5d01365ce1fc72d702a0e.tar.gz
CMake-d67cc4882d54a18abbd5d01365ce1fc72d702a0e.tar.bz2
Xcode: Add support of DEPFILE for add_custom_command
Issue: #20286
Diffstat (limited to 'Source/cmGlobalXCodeGenerator.cxx')
-rw-r--r--Source/cmGlobalXCodeGenerator.cxx33
1 files changed, 29 insertions, 4 deletions
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index 7dd1704..dc3d3f2 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -17,6 +17,7 @@
#include "cmsys/RegularExpression.hxx"
+#include "cmCMakePath.h"
#include "cmComputeLinkInformation.h"
#include "cmCryptoHash.h"
#include "cmCustomCommand.h"
@@ -1864,9 +1865,20 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateRunScriptBuildPhase(
std::set<std::string> allConfigInputs;
std::set<std::string> allConfigOutputs;
+ cmXCodeObject* buildPhase =
+ this->CreateObject(cmXCodeObject::PBXShellScriptBuildPhase,
+ cmStrCat(gt->GetName(), ':', sf->GetFullPath()));
+
+ auto depfilesDirectory = cmStrCat(
+ gt->GetLocalGenerator()->GetCurrentBinaryDirectory(), "/CMakeFiles/d/");
+ auto depfilesPrefix = cmStrCat(depfilesDirectory, buildPhase->GetId(), ".");
+
std::string shellScript = "set -e\n";
for (std::string const& configName : this->CurrentConfigurationTypes) {
- cmCustomCommandGenerator ccg(cc, configName, this->CurrentLocalGenerator);
+ cmCustomCommandGenerator ccg(
+ cc, configName, this->CurrentLocalGenerator, true, {},
+ [&depfilesPrefix](const std::string& config, const std::string&)
+ -> std::string { return cmStrCat(depfilesPrefix, config, ".d"); });
std::vector<std::string> realDepends;
realDepends.reserve(ccg.GetDepends().size());
for (auto const& d : ccg.GetDepends()) {
@@ -1886,9 +1898,22 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateRunScriptBuildPhase(
"\"; then :\n", this->ConstructScript(ccg), "fi\n");
}
- cmXCodeObject* buildPhase =
- this->CreateObject(cmXCodeObject::PBXShellScriptBuildPhase,
- cmStrCat(gt->GetName(), ':', sf->GetFullPath()));
+ if (!cc.GetDepfile().empty()) {
+ buildPhase->AddAttribute(
+ "dependencyFile",
+ this->CreateString(cmStrCat(depfilesDirectory, buildPhase->GetId(),
+ ".$(CONFIGURATION).d")));
+ // to avoid spurious errors during first build, create empty dependency
+ // files
+ cmSystemTools::MakeDirectory(depfilesDirectory);
+ for (std::string const& configName : this->CurrentConfigurationTypes) {
+ auto file = cmStrCat(depfilesPrefix, configName, ".d");
+ if (!cmSystemTools::FileExists(file)) {
+ cmSystemTools::Touch(file, true);
+ }
+ }
+ }
+
buildPhase->AddAttribute("buildActionMask",
this->CreateString("2147483647"));
cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);