diff options
author | Brad King <brad.king@kitware.com> | 2023-02-07 14:49:29 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2023-02-07 14:49:49 (GMT) |
commit | 9bef06d0a58d0b20c1bf11e005a9898c05e2eb14 (patch) | |
tree | a4444f9dcaa1a5fbe94ecf05aafe0b8f8916722e /Source | |
parent | 921d8c4d6485f87d8d37c6c488dbb4a20a640032 (diff) | |
parent | 480b3637243d89f59906bee794ababc7cecc220e (diff) | |
download | CMake-9bef06d0a58d0b20c1bf11e005a9898c05e2eb14.zip CMake-9bef06d0a58d0b20c1bf11e005a9898c05e2eb14.tar.gz CMake-9bef06d0a58d0b20c1bf11e005a9898c05e2eb14.tar.bz2 |
Merge topic 'custom-command-policies'
480b363724 cmCustomCommand: Refactor custom command-specific policy values
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !8168
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmCustomCommand.cxx | 19 | ||||
-rw-r--r-- | Source/cmCustomCommand.h | 20 | ||||
-rw-r--r-- | Source/cmGlobalGhsMultiGenerator.cxx | 3 | ||||
-rw-r--r-- | Source/cmGlobalVisualStudio8Generator.cxx | 3 | ||||
-rw-r--r-- | Source/cmGlobalVisualStudioGenerator.cxx | 1 | ||||
-rw-r--r-- | Source/cmGlobalXCodeGenerator.cxx | 3 | ||||
-rw-r--r-- | Source/cmLocalGenerator.cxx | 1 | ||||
-rw-r--r-- | Source/cmLocalVisualStudio7Generator.cxx | 2 | ||||
-rw-r--r-- | Source/cmMakefile.cxx | 6 | ||||
-rw-r--r-- | Source/cmPolicies.h | 2 | ||||
-rw-r--r-- | Source/cmQtAutoGenGlobalInitializer.cxx | 2 | ||||
-rw-r--r-- | Source/cmQtAutoGenInitializer.cxx | 5 |
12 files changed, 34 insertions, 33 deletions
diff --git a/Source/cmCustomCommand.cxx b/Source/cmCustomCommand.cxx index 68c65bb..5b63996 100644 --- a/Source/cmCustomCommand.cxx +++ b/Source/cmCustomCommand.cxx @@ -7,6 +7,8 @@ #include <cmext/algorithm> +#include "cmStateSnapshot.h" + const std::vector<std::string>& cmCustomCommand::GetOutputs() const { return this->Outputs; @@ -182,14 +184,19 @@ void cmCustomCommand::SetJobPool(const std::string& job_pool) this->JobPool = job_pool; } -cmPolicies::PolicyStatus cmCustomCommand::GetCMP0116Status() const -{ - return this->CMP0116Status; -} +#define DEFINE_CC_POLICY_ACCESSOR(P) \ + cmPolicies::PolicyStatus cmCustomCommand::Get##P##Status() const \ + { \ + return this->P##Status; \ + } +CM_FOR_EACH_CUSTOM_COMMAND_POLICY(DEFINE_CC_POLICY_ACCESSOR) +#undef DEFINE_CC_POLICY_ACCESSOR -void cmCustomCommand::SetCMP0116Status(cmPolicies::PolicyStatus cmp0116) +void cmCustomCommand::RecordPolicyValues(const cmStateSnapshot& snapshot) { - this->CMP0116Status = cmp0116; +#define SET_CC_POLICY(P) this->P##Status = snapshot.GetPolicy(cmPolicies::P); + CM_FOR_EACH_CUSTOM_COMMAND_POLICY(SET_CC_POLICY) +#undef SET_CC_POLICY } const std::string& cmCustomCommand::GetTarget() const diff --git a/Source/cmCustomCommand.h b/Source/cmCustomCommand.h index 5533847..3671ad9 100644 --- a/Source/cmCustomCommand.h +++ b/Source/cmCustomCommand.h @@ -17,6 +17,8 @@ class cmImplicitDependsList { }; +class cmStateSnapshot; + /** \class cmCustomCommand * \brief A class to encapsulate a custom command * @@ -108,9 +110,13 @@ public: const std::string& GetJobPool() const; void SetJobPool(const std::string& job_pool); - /** Set/Get the CMP0116 status (used by the Ninja generator) */ - cmPolicies::PolicyStatus GetCMP0116Status() const; - void SetCMP0116Status(cmPolicies::PolicyStatus cmp0116); +#define DECLARE_CC_POLICY_ACCESSOR(P) \ + cmPolicies::PolicyStatus Get##P##Status() const; + CM_FOR_EACH_CUSTOM_COMMAND_POLICY(DECLARE_CC_POLICY_ACCESSOR) +#undef DECLARE_CC_POLICY_ACCESSOR + + /** Record policy values from state snapshot */ + void RecordPolicyValues(const cmStateSnapshot& snapshot); /** Set/Get the associated target */ const std::string& GetTarget() const; @@ -135,5 +141,11 @@ private: bool CommandExpandLists = false; bool StdPipesUTF8 = false; bool HasMainDependency_ = false; - cmPolicies::PolicyStatus CMP0116Status = cmPolicies::WARN; + +// Policies are NEW for synthesized custom commands, and set by cmMakefile for +// user-created custom commands. +#define DECLARE_CC_POLICY_FIELD(P) \ + cmPolicies::PolicyStatus P##Status = cmPolicies::NEW; + CM_FOR_EACH_CUSTOM_COMMAND_POLICY(DECLARE_CC_POLICY_FIELD) +#undef DECLARE_CC_POLICY_FIELD }; diff --git a/Source/cmGlobalGhsMultiGenerator.cxx b/Source/cmGlobalGhsMultiGenerator.cxx index 3da15f6..b1f2b4a 100644 --- a/Source/cmGlobalGhsMultiGenerator.cxx +++ b/Source/cmGlobalGhsMultiGenerator.cxx @@ -22,7 +22,6 @@ #include "cmLocalGhsMultiGenerator.h" #include "cmMakefile.h" #include "cmMessageType.h" -#include "cmPolicies.h" #include "cmSourceFile.h" #include "cmState.h" #include "cmStateTypes.h" @@ -717,7 +716,6 @@ bool cmGlobalGhsMultiGenerator::AddCheckTarget() cc->SetDepends(listFiles); cc->SetCommandLines(commandLines); cc->SetComment("Checking Build System"); - cc->SetCMP0116Status(cmPolicies::NEW); cc->SetEscapeOldStyle(false); cc->SetStdPipesUTF8(true); @@ -747,7 +745,6 @@ void cmGlobalGhsMultiGenerator::AddAllTarget() // Use no actual command lines so that the target itself is not // considered always out of date. auto cc = cm::make_unique<cmCustomCommand>(); - cc->SetCMP0116Status(cmPolicies::NEW); cc->SetEscapeOldStyle(false); cc->SetComment("Build all projects"); cmTarget* allBuild = gen[0]->AddUtilityCommand(this->GetAllTargetName(), diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx index 647fc2d..2e2c8b6 100644 --- a/Source/cmGlobalVisualStudio8Generator.cxx +++ b/Source/cmGlobalVisualStudio8Generator.cxx @@ -169,7 +169,6 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget() cm::static_reference_cast<cmLocalVisualStudio7Generator>(generators[0]); auto cc = cm::make_unique<cmCustomCommand>(); - cc->SetCMP0116Status(cmPolicies::NEW); cmTarget* tgt = lg.AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET, false, std::move(cc)); @@ -225,7 +224,6 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget() cc->SetByproducts(byproducts); cc->SetCommandLines(verifyCommandLines); cc->SetComment("Checking File Globs"); - cc->SetCMP0116Status(cmPolicies::NEW); cc->SetStdPipesUTF8(stdPipesUTF8); lg.AddCustomCommandToTarget(CMAKE_CHECK_BUILD_SYSTEM_TARGET, cmCustomCommandType::PRE_BUILD, @@ -260,7 +258,6 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget() cc->SetDepends(listFiles); cc->SetCommandLines(commandLines); cc->SetComment("Checking Build System"); - cc->SetCMP0116Status(cmPolicies::NEW); cc->SetEscapeOldStyle(false); cc->SetStdPipesUTF8(stdPipesUTF8); if (cmSourceFile* file = diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index 31f6f77..cd0fb18 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -201,7 +201,6 @@ void cmGlobalVisualStudioGenerator::AddExtraIDETargets() // Use no actual command lines so that the target itself is not // considered always out of date. auto cc = cm::make_unique<cmCustomCommand>(); - cc->SetCMP0116Status(cmPolicies::NEW); cc->SetEscapeOldStyle(false); cc->SetComment("Build all projects"); cmTarget* allBuild = diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index f91879e..ed1de16 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -615,7 +615,6 @@ void cmGlobalXCodeGenerator::AddExtraTargets( auto cc = cm::make_unique<cmCustomCommand>(); cc->SetCommandLines( cmMakeSingleCommandLine({ "echo", "Build all projects" })); - cc->SetCMP0116Status(cmPolicies::NEW); cmTarget* allbuild = root->AddUtilityCommand("ALL_BUILD", true, std::move(cc)); @@ -655,7 +654,6 @@ void cmGlobalXCodeGenerator::AddExtraTargets( cmSystemTools::ReplaceString(file, "\\ ", " "); cc = cm::make_unique<cmCustomCommand>(); cc->SetCommandLines(cmMakeSingleCommandLine({ "make", "-f", file })); - cc->SetCMP0116Status(cmPolicies::NEW); cmTarget* check = root->AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET, true, std::move(cc)); @@ -687,7 +685,6 @@ void cmGlobalXCodeGenerator::AddExtraTargets( cc->SetCommandLines(legacyDependHelperCommandLines); cc->SetComment("Depend check for xcode"); cc->SetWorkingDirectory(legacyDependHelperDir.c_str()); - cc->SetCMP0116Status(cmPolicies::NEW); gen->AddCustomCommandToTarget( target->GetName(), cmCustomCommandType::POST_BUILD, std::move(cc), cmObjectLibraryCommands::Accept); diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 75ec694..15bcd02 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2841,7 +2841,6 @@ void cmLocalGenerator::CopyPchCompilePdb( auto cc = cm::make_unique<cmCustomCommand>(); cc->SetCommandLines(commandLines); cc->SetComment(no_message); - cc->SetCMP0116Status(cmPolicies::NEW); cc->SetStdPipesUTF8(true); if (this->GetGlobalGenerator()->IsVisualStudio()) { diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index ded1647..6806a5b 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -141,7 +141,6 @@ void cmLocalVisualStudio7Generator::FixGlobalTargets() cc->SetOutputs(force); cc->SetCommandLines(force_commands); cc->SetComment(" "); - cc->SetCMP0116Status(cmPolicies::NEW); if (cmSourceFile* file = this->AddCustomCommandToOutput(std::move(cc), true)) { l->AddSource(file->ResolveFullPath()); @@ -269,7 +268,6 @@ cmSourceFile* cmLocalVisualStudio7Generator::CreateVCProjBuildRule() cc->SetDepends(listFiles); cc->SetCommandLines(commandLines); cc->SetComment(comment.c_str()); - cc->SetCMP0116Status(cmPolicies::NEW); cc->SetEscapeOldStyle(false); cc->SetStdPipesUTF8(true); this->AddCustomCommandToOutput(std::move(cc), true); diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index aef369e..0ad0e6e 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1117,7 +1117,7 @@ cmTarget* cmMakefile::AddCustomCommandToTarget( // Always create the byproduct sources and mark them generated. this->CreateGeneratedOutputs(byproducts); - cc->SetCMP0116Status(this->GetPolicyStatus(cmPolicies::CMP0116)); + cc->RecordPolicyValues(this->GetStateSnapshot()); // Dispatch command creation to allow generator expressions in outputs. this->AddGeneratorAction( @@ -1156,7 +1156,7 @@ void cmMakefile::AddCustomCommandToOutput( this->CreateGeneratedOutputs(outputs); this->CreateGeneratedOutputs(byproducts); - cc->SetCMP0116Status(this->GetPolicyStatus(cmPolicies::CMP0116)); + cc->RecordPolicyValues(this->GetStateSnapshot()); // Dispatch command creation to allow generator expressions in outputs. this->AddGeneratorAction( @@ -1274,7 +1274,7 @@ cmTarget* cmMakefile::AddUtilityCommand(const std::string& utilityName, // Always create the byproduct sources and mark them generated. this->CreateGeneratedOutputs(byproducts); - cc->SetCMP0116Status(this->GetPolicyStatus(cmPolicies::CMP0116)); + cc->RecordPolicyValues(this->GetStateSnapshot()); // Dispatch command creation to allow generator expressions in outputs. this->AddGeneratorAction( diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index fa24f57..568eca3 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -474,6 +474,8 @@ class cmMakefile; F(CMP0131) \ F(CMP0142) +#define CM_FOR_EACH_CUSTOM_COMMAND_POLICY(F) F(CMP0116) + /** \class cmPolicies * \brief Handles changes in CMake behavior and policies * diff --git a/Source/cmQtAutoGenGlobalInitializer.cxx b/Source/cmQtAutoGenGlobalInitializer.cxx index b7ea7d6..9e3fe7f 100644 --- a/Source/cmQtAutoGenGlobalInitializer.cxx +++ b/Source/cmQtAutoGenGlobalInitializer.cxx @@ -13,7 +13,6 @@ #include "cmLocalGenerator.h" #include "cmMakefile.h" #include "cmMessageType.h" -#include "cmPolicies.h" #include "cmProcessOutput.h" #include "cmQtAutoGen.h" #include "cmQtAutoGenInitializer.h" @@ -173,7 +172,6 @@ void cmQtAutoGenGlobalInitializer::GetOrCreateGlobalTarget( // Create utility target auto cc = cm::make_unique<cmCustomCommand>(); cc->SetWorkingDirectory(makefile->GetHomeOutputDirectory().c_str()); - cc->SetCMP0116Status(cmPolicies::NEW); cc->SetEscapeOldStyle(false); cc->SetComment(comment.c_str()); cmTarget* target = localGen->AddUtilityCommand(name, true, std::move(cc)); diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index 66e591e..410330a 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -1238,7 +1238,6 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() cc->SetDepends(uicDependencies); cc->SetComment(""); cc->SetWorkingDirectory(this->Dir.Work.c_str()); - cc->SetCMP0116Status(cmPolicies::NEW); cc->SetEscapeOldStyle(false); cc->SetStdPipesUTF8(stdPipesUTF8); this->LocalGen->AddCustomCommandToOutput(std::move(cc)); @@ -1332,7 +1331,6 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() cc->SetByproducts(timestampTargetProvides); cc->SetDepends(dependencies); cc->SetCommandLines(timestampTargetCommandLines); - cc->SetCMP0116Status(cmPolicies::NEW); cc->SetEscapeOldStyle(false); cmTarget* timestampTarget = this->LocalGen->AddUtilityCommand( timestampTargetName, true, std::move(cc)); @@ -1371,7 +1369,6 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() cc->SetCommandLines(commandLines); cc->SetComment(autogenComment.c_str()); cc->SetWorkingDirectory(this->Dir.Work.c_str()); - cc->SetCMP0116Status(cmPolicies::NEW); cc->SetEscapeOldStyle(false); cc->SetDepfile(this->AutogenTarget.DepFile); cc->SetStdPipesUTF8(stdPipesUTF8); @@ -1391,7 +1388,6 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() cc->SetByproducts(autogenByproducts); cc->SetDepends(dependencies); cc->SetCommandLines(commandLines); - cc->SetCMP0116Status(cmPolicies::NEW); cc->SetEscapeOldStyle(false); cc->SetComment(autogenComment.c_str()); cmTarget* autogenTarget = this->LocalGen->AddUtilityCommand( @@ -1472,7 +1468,6 @@ bool cmQtAutoGenInitializer::InitRccTargets() auto cc = cm::make_unique<cmCustomCommand>(); cc->SetWorkingDirectory(this->Dir.Work.c_str()); cc->SetCommandLines(commandLines); - cc->SetCMP0116Status(cmPolicies::NEW); cc->SetComment(ccComment.c_str()); cc->SetStdPipesUTF8(true); |