summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorKyle Edwards <kyle.edwards@kitware.com>2020-10-02 21:35:40 (GMT)
committerKyle Edwards <kyle.edwards@kitware.com>2020-10-13 14:19:46 (GMT)
commit146e1e6ba14d964bf120635aca953cc76e5b2282 (patch)
treee8fd8309f7288a275322dcbc14a8ee99370aba4b /Source
parent596439b1bbac44b4218f65615d93e9fe9bd43922 (diff)
downloadCMake-146e1e6ba14d964bf120635aca953cc76e5b2282.zip
CMake-146e1e6ba14d964bf120635aca953cc76e5b2282.tar.gz
CMake-146e1e6ba14d964bf120635aca953cc76e5b2282.tar.bz2
Ninja: Transform DEPFILEs with policy CMP0116
Fixes: #21267
Diffstat (limited to 'Source')
-rw-r--r--Source/cmGlobalNinjaGenerator.h5
-rw-r--r--Source/cmLocalNinjaGenerator.cxx45
-rw-r--r--Source/cmPolicies.h5
3 files changed, 52 insertions, 3 deletions
diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h
index 884a711..ec001d3 100644
--- a/Source/cmGlobalNinjaGenerator.h
+++ b/Source/cmGlobalNinjaGenerator.h
@@ -24,6 +24,7 @@
#include "cmNinjaTypes.h"
#include "cmPolicies.h"
#include "cmStringAlgorithms.h"
+#include "cmTransformDepfile.h"
class cmCustomCommand;
class cmGeneratorTarget;
@@ -211,6 +212,10 @@ public:
const char* GetCleanTargetName() const override { return "clean"; }
bool SupportsCustomCommandDepfile() const override { return true; }
+ cm::optional<cmDepfileFormat> DepfileFormat() const override
+ {
+ return cmDepfileFormat::GccDepfile;
+ }
virtual cmGeneratedFileStream* GetImplFileStream(
const std::string& /*config*/) const
diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx
index ad782ee..ce85320 100644
--- a/Source/cmLocalNinjaGenerator.cxx
+++ b/Source/cmLocalNinjaGenerator.cxx
@@ -22,7 +22,9 @@
#include "cmGlobalNinjaGenerator.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmNinjaTargetGenerator.h"
+#include "cmPolicies.h"
#include "cmProperty.h"
#include "cmRulePlaceholderExpander.h"
#include "cmSourceFile.h"
@@ -573,7 +575,20 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatement(
return;
}
- cmCustomCommandGenerator ccg(*cc, config, this);
+ bool transformDepfile = false;
+ auto cmp0116 = this->GetPolicyStatus(cmPolicies::CMP0116);
+ switch (cmp0116) {
+ case cmPolicies::OLD:
+ case cmPolicies::WARN:
+ break;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::NEW:
+ transformDepfile = true;
+ break;
+ }
+
+ cmCustomCommandGenerator ccg(*cc, config, this, transformDepfile);
const std::vector<std::string>& outputs = ccg.GetOutputs();
const std::vector<std::string>& byproducts = ccg.GetByproducts();
@@ -623,10 +638,36 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatement(
cmCryptoHash hash(cmCryptoHash::AlgoSHA256);
customStep += hash.HashString(ninjaOutputs[0]).substr(0, 7);
+ std::string depfile = cc->GetDepfile();
+ if (!depfile.empty()) {
+ switch (cmp0116) {
+ case cmPolicies::WARN:
+ if (this->GetCurrentBinaryDirectory() !=
+ this->GetBinaryDirectory() ||
+ this->Makefile->PolicyOptionalWarningEnabled(
+ "CMAKE_POLICY_WARNING_CMP0116")) {
+ this->GetCMakeInstance()->IssueMessage(
+ MessageType::AUTHOR_WARNING,
+ cmPolicies::GetPolicyWarning(cmPolicies::CMP0116),
+ cc->GetBacktrace());
+ }
+ CM_FALLTHROUGH;
+ case cmPolicies::OLD:
+ break;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::NEW:
+ cmSystemTools::MakeDirectory(
+ cmStrCat(this->GetBinaryDirectory(), "/CMakeFiles/d"));
+ depfile = ccg.GetInternalDepfile();
+ break;
+ }
+ }
+
gg->WriteCustomCommandBuild(
this->BuildCommandLine(cmdLines, customStep),
this->ConstructComment(ccg), "Custom command for " + ninjaOutputs[0],
- cc->GetDepfile(), cc->GetJobPool(), cc->GetUsesTerminal(),
+ depfile, cc->GetJobPool(), cc->GetUsesTerminal(),
/*restat*/ !symbolic || !byproducts.empty(), ninjaOutputs, config,
ninjaDeps, orderOnlyDeps);
}
diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h
index f9f7d0e..99bac98 100644
--- a/Source/cmPolicies.h
+++ b/Source/cmPolicies.h
@@ -342,7 +342,10 @@ class cmMakefile;
"ExternalProject step targets fully adopt their steps.", 3, 19, 0, \
cmPolicies::WARN) \
SELECT(POLICY, CMP0115, "Source file extensions must be explicit.", 3, 20, \
- 0, cmPolicies::WARN)
+ 0, cmPolicies::WARN) \
+ SELECT(POLICY, CMP0116, \
+ "Ninja generators transform DEPFILEs from add_custom_command().", 3, \
+ 20, 0, cmPolicies::WARN)
#define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
#define CM_FOR_EACH_POLICY_ID(POLICY) \