diff options
author | Brad King <brad.king@kitware.com> | 2017-10-26 18:01:51 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2017-10-30 14:21:31 (GMT) |
commit | ae5f40696ef6efc62b663457b72184f682a23fe2 (patch) | |
tree | 4cc03a0f0d2bcb4db26b27b5a59ffec77edfa848 /Source/cmGlobalGenerator.cxx | |
parent | 409527a03ced550fbc295faf965aebc7b8dbe003 (diff) | |
download | CMake-ae5f40696ef6efc62b663457b72184f682a23fe2.zip CMake-ae5f40696ef6efc62b663457b72184f682a23fe2.tar.gz CMake-ae5f40696ef6efc62b663457b72184f682a23fe2.tar.bz2 |
CMP0037: Allow test and package targets when features are not enabled
When CMake will not generate a test, package, or package_source target,
allow projects to create their own targets with these names.
Fixes: #16062
Diffstat (limited to 'Source/cmGlobalGenerator.cxx')
-rw-r--r-- | Source/cmGlobalGenerator.cxx | 72 |
1 files changed, 67 insertions, 5 deletions
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index a0977ac..11ea46f 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -2220,6 +2220,45 @@ inline std::string removeQuotes(const std::string& s) return s; } +bool cmGlobalGenerator::CheckCMP0037(std::string const& targetName, + std::string const& reason) const +{ + cmTarget* tgt = this->FindTarget(targetName); + if (!tgt) { + return true; + } + cmake::MessageType messageType = cmake::AUTHOR_WARNING; + std::ostringstream e; + bool issueMessage = false; + switch (tgt->GetPolicyStatusCMP0037()) { + case cmPolicies::WARN: + e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0037) << "\n"; + issueMessage = true; + CM_FALLTHROUGH; + case cmPolicies::OLD: + break; + case cmPolicies::NEW: + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::REQUIRED_ALWAYS: + issueMessage = true; + messageType = cmake::FATAL_ERROR; + break; + } + if (issueMessage) { + e << "The target name \"" << targetName << "\" is reserved " << reason + << "."; + if (messageType == cmake::AUTHOR_WARNING) { + e << " It may result in undefined behavior."; + } + this->GetCMakeInstance()->IssueMessage(messageType, e.str(), + tgt->GetBacktrace()); + if (messageType == cmake::FATAL_ERROR) { + return false; + } + } + return true; +} + void cmGlobalGenerator::CreateDefaultGlobalTargets( std::vector<GlobalTargetInfo>& targets) { @@ -2241,6 +2280,14 @@ void cmGlobalGenerator::AddGlobalTarget_Package( return; } + const char* reservedTargets[] = { "package", "PACKAGE" }; + for (const char* const* tn = cm::cbegin(reservedTargets); + tn != cm::cend(reservedTargets); ++tn) { + if (!this->CheckCMP0037(*tn, "when CPack packaging is enabled")) { + return; + } + } + const char* cmakeCfgIntDir = this->GetCMakeCFGIntDir(); GlobalTargetInfo gti; gti.Name = this->GetPackageTargetName(); @@ -2284,6 +2331,14 @@ void cmGlobalGenerator::AddGlobalTarget_PackageSource( return; } + const char* reservedTargets[] = { "package_source" }; + for (const char* const* tn = cm::cbegin(reservedTargets); + tn != cm::cend(reservedTargets); ++tn) { + if (!this->CheckCMP0037(*tn, "when CPack source packaging is enabled")) { + return; + } + } + GlobalTargetInfo gti; gti.Name = packageSourceTargetName; gti.Message = "Run CPack packaging tool for source..."; @@ -2307,6 +2362,14 @@ void cmGlobalGenerator::AddGlobalTarget_Test( return; } + const char* reservedTargets[] = { "test", "RUN_TESTS" }; + for (const char* const* tn = cm::cbegin(reservedTargets); + tn != cm::cend(reservedTargets); ++tn) { + if (!this->CheckCMP0037(*tn, "when CTest testing is enabled")) { + return; + } + } + const char* cmakeCfgIntDir = this->GetCMakeCFGIntDir(); GlobalTargetInfo gti; gti.Name = this->GetTestTargetName(); @@ -2590,11 +2653,10 @@ bool cmGlobalGenerator::IsReservedTarget(std::string const& name) // by one or more of the cmake generators. // Adding additional targets to this list will require a policy! - const char* reservedTargets[] = { - "all", "ALL_BUILD", "help", "install", "INSTALL", - "preinstall", "clean", "edit_cache", "rebuild_cache", "test", - "RUN_TESTS", "package", "PACKAGE", "package_source", "ZERO_CHECK" - }; + const char* reservedTargets[] = { "all", "ALL_BUILD", "help", + "install", "INSTALL", "preinstall", + "clean", "edit_cache", "rebuild_cache", + "ZERO_CHECK" }; return std::find(cm::cbegin(reservedTargets), cm::cend(reservedTargets), name) != cm::cend(reservedTargets); |