summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2017-10-26 18:01:51 (GMT)
committerBrad King <brad.king@kitware.com>2017-10-30 14:21:31 (GMT)
commitae5f40696ef6efc62b663457b72184f682a23fe2 (patch)
tree4cc03a0f0d2bcb4db26b27b5a59ffec77edfa848
parent409527a03ced550fbc295faf965aebc7b8dbe003 (diff)
downloadCMake-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
-rw-r--r--Source/cmGlobalGenerator.cxx72
-rw-r--r--Source/cmGlobalGenerator.h3
-rw-r--r--Source/cmPolicies.h1
-rw-r--r--Tests/RunCMake/CMP0037/NEW-cond-package-result.txt1
-rw-r--r--Tests/RunCMake/CMP0037/NEW-cond-package-stderr.txt4
-rw-r--r--Tests/RunCMake/CMP0037/NEW-cond-package.cmake5
-rw-r--r--Tests/RunCMake/CMP0037/NEW-cond-package_source-result.txt1
-rw-r--r--Tests/RunCMake/CMP0037/NEW-cond-package_source-stderr.txt5
-rw-r--r--Tests/RunCMake/CMP0037/NEW-cond-package_source.cmake5
-rw-r--r--Tests/RunCMake/CMP0037/NEW-cond-test-result.txt1
-rw-r--r--Tests/RunCMake/CMP0037/NEW-cond-test-stderr.txt4
-rw-r--r--Tests/RunCMake/CMP0037/NEW-cond-test.cmake5
-rw-r--r--Tests/RunCMake/CMP0037/NEW-cond.cmake4
-rw-r--r--Tests/RunCMake/CMP0037/OLD-cond-package.cmake5
-rw-r--r--Tests/RunCMake/CMP0037/OLD-cond-package_source.cmake5
-rw-r--r--Tests/RunCMake/CMP0037/OLD-cond-test.cmake5
-rw-r--r--Tests/RunCMake/CMP0037/OLD-cond.cmake5
-rw-r--r--Tests/RunCMake/CMP0037/RunCMakeTest.cmake16
-rw-r--r--Tests/RunCMake/CMP0037/WARN-cond-package-stderr.txt11
-rw-r--r--Tests/RunCMake/CMP0037/WARN-cond-package.cmake5
-rw-r--r--Tests/RunCMake/CMP0037/WARN-cond-package_source-stderr.txt11
-rw-r--r--Tests/RunCMake/CMP0037/WARN-cond-package_source.cmake5
-rw-r--r--Tests/RunCMake/CMP0037/WARN-cond-test-stderr.txt11
-rw-r--r--Tests/RunCMake/CMP0037/WARN-cond-test.cmake5
-rw-r--r--Tests/RunCMake/CMP0037/WARN-cond.cmake4
-rw-r--r--Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt1
26 files changed, 195 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);
diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h
index c5a5297..8fcb533 100644
--- a/Source/cmGlobalGenerator.h
+++ b/Source/cmGlobalGenerator.h
@@ -568,6 +568,9 @@ private:
void ClearGeneratorMembers();
+ bool CheckCMP0037(std::string const& targetName,
+ std::string const& reason) const;
+
void IndexMakefile(cmMakefile* mf);
virtual const char* GetBuildIgnoreErrorsFlag() const { return nullptr; }
diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h
index 354011a..7d15ee2 100644
--- a/Source/cmPolicies.h
+++ b/Source/cmPolicies.h
@@ -225,6 +225,7 @@ class cmMakefile;
F(CMP0021) \
F(CMP0022) \
F(CMP0027) \
+ F(CMP0037) \
F(CMP0038) \
F(CMP0041) \
F(CMP0042) \
diff --git a/Tests/RunCMake/CMP0037/NEW-cond-package-result.txt b/Tests/RunCMake/CMP0037/NEW-cond-package-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/NEW-cond-package-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMP0037/NEW-cond-package-stderr.txt b/Tests/RunCMake/CMP0037/NEW-cond-package-stderr.txt
new file mode 100644
index 0000000..270fa6d
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/NEW-cond-package-stderr.txt
@@ -0,0 +1,4 @@
+^CMake Error at NEW-cond-package.cmake:4 \(add_custom_target\):
+ The target name "package" is reserved when CPack packaging is enabled.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/CMP0037/NEW-cond-package.cmake b/Tests/RunCMake/CMP0037/NEW-cond-package.cmake
new file mode 100644
index 0000000..ceea907
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/NEW-cond-package.cmake
@@ -0,0 +1,5 @@
+cmake_policy(SET CMP0037 NEW)
+file(WRITE "${CMAKE_BINARY_DIR}/CPackConfig.cmake" "")
+add_custom_target(test)
+add_custom_target(package)
+add_custom_target(package_source)
diff --git a/Tests/RunCMake/CMP0037/NEW-cond-package_source-result.txt b/Tests/RunCMake/CMP0037/NEW-cond-package_source-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/NEW-cond-package_source-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMP0037/NEW-cond-package_source-stderr.txt b/Tests/RunCMake/CMP0037/NEW-cond-package_source-stderr.txt
new file mode 100644
index 0000000..2d32147
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/NEW-cond-package_source-stderr.txt
@@ -0,0 +1,5 @@
+^CMake Error at NEW-cond-package_source.cmake:5 \(add_custom_target\):
+ The target name "package_source" is reserved when CPack source packaging is
+ enabled.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/CMP0037/NEW-cond-package_source.cmake b/Tests/RunCMake/CMP0037/NEW-cond-package_source.cmake
new file mode 100644
index 0000000..3f8883b
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/NEW-cond-package_source.cmake
@@ -0,0 +1,5 @@
+cmake_policy(SET CMP0037 NEW)
+file(WRITE "${CMAKE_BINARY_DIR}/CPackSourceConfig.cmake" "")
+add_custom_target(test)
+add_custom_target(package)
+add_custom_target(package_source)
diff --git a/Tests/RunCMake/CMP0037/NEW-cond-test-result.txt b/Tests/RunCMake/CMP0037/NEW-cond-test-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/NEW-cond-test-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMP0037/NEW-cond-test-stderr.txt b/Tests/RunCMake/CMP0037/NEW-cond-test-stderr.txt
new file mode 100644
index 0000000..44b4741
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/NEW-cond-test-stderr.txt
@@ -0,0 +1,4 @@
+^CMake Error at NEW-cond-test.cmake:3 \(add_custom_target\):
+ The target name "test" is reserved when CTest testing is enabled.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/CMP0037/NEW-cond-test.cmake b/Tests/RunCMake/CMP0037/NEW-cond-test.cmake
new file mode 100644
index 0000000..7eeaffc
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/NEW-cond-test.cmake
@@ -0,0 +1,5 @@
+cmake_policy(SET CMP0037 NEW)
+enable_testing()
+add_custom_target(test)
+add_custom_target(package)
+add_custom_target(package_source)
diff --git a/Tests/RunCMake/CMP0037/NEW-cond.cmake b/Tests/RunCMake/CMP0037/NEW-cond.cmake
new file mode 100644
index 0000000..d0dc77af
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/NEW-cond.cmake
@@ -0,0 +1,4 @@
+cmake_policy(SET CMP0037 NEW)
+add_custom_target(test)
+add_custom_target(package)
+add_custom_target(package_source)
diff --git a/Tests/RunCMake/CMP0037/OLD-cond-package.cmake b/Tests/RunCMake/CMP0037/OLD-cond-package.cmake
new file mode 100644
index 0000000..7a0afbe
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/OLD-cond-package.cmake
@@ -0,0 +1,5 @@
+cmake_policy(SET CMP0037 OLD)
+file(WRITE "${CMAKE_BINARY_DIR}/CPackConfig.cmake" "")
+add_custom_target(test)
+add_custom_target(package)
+add_custom_target(package_source)
diff --git a/Tests/RunCMake/CMP0037/OLD-cond-package_source.cmake b/Tests/RunCMake/CMP0037/OLD-cond-package_source.cmake
new file mode 100644
index 0000000..95616b6
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/OLD-cond-package_source.cmake
@@ -0,0 +1,5 @@
+cmake_policy(SET CMP0037 OLD)
+file(WRITE "${CMAKE_BINARY_DIR}/CPackSourceConfig.cmake" "")
+add_custom_target(test)
+add_custom_target(package)
+add_custom_target(package_source)
diff --git a/Tests/RunCMake/CMP0037/OLD-cond-test.cmake b/Tests/RunCMake/CMP0037/OLD-cond-test.cmake
new file mode 100644
index 0000000..bfa32a9
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/OLD-cond-test.cmake
@@ -0,0 +1,5 @@
+cmake_policy(SET CMP0037 OLD)
+enable_testing()
+add_custom_target(test)
+add_custom_target(package)
+add_custom_target(package_source)
diff --git a/Tests/RunCMake/CMP0037/OLD-cond.cmake b/Tests/RunCMake/CMP0037/OLD-cond.cmake
new file mode 100644
index 0000000..abad680
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/OLD-cond.cmake
@@ -0,0 +1,5 @@
+cmake_policy(SET CMP0037 OLD)
+
+add_custom_target(test)
+add_custom_target(package)
+add_custom_target(package_source)
diff --git a/Tests/RunCMake/CMP0037/RunCMakeTest.cmake b/Tests/RunCMake/CMP0037/RunCMakeTest.cmake
index 04c1b52..98274f0 100644
--- a/Tests/RunCMake/CMP0037/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CMP0037/RunCMakeTest.cmake
@@ -12,3 +12,19 @@ endif()
run_cmake(CMP0037-WARN-reserved)
run_cmake(CMP0037-OLD-reserved)
run_cmake(CMP0037-NEW-reserved)
+
+run_cmake(NEW-cond)
+run_cmake(NEW-cond-test)
+run_cmake(NEW-cond-package)
+run_cmake(OLD-cond)
+run_cmake(OLD-cond-test)
+run_cmake(OLD-cond-package)
+run_cmake(WARN-cond)
+run_cmake(WARN-cond-test)
+run_cmake(WARN-cond-package)
+
+if(RunCMake_GENERATOR MATCHES "Make|Ninja")
+ run_cmake(NEW-cond-package_source)
+ run_cmake(OLD-cond-package_source)
+ run_cmake(WARN-cond-package_source)
+endif()
diff --git a/Tests/RunCMake/CMP0037/WARN-cond-package-stderr.txt b/Tests/RunCMake/CMP0037/WARN-cond-package-stderr.txt
new file mode 100644
index 0000000..5960e51
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/WARN-cond-package-stderr.txt
@@ -0,0 +1,11 @@
+^CMake Warning \(dev\) at WARN-cond-package.cmake:4 \(add_custom_target\):
+ Policy CMP0037 is not set: Target names should not be reserved and should
+ match a validity pattern. Run "cmake --help-policy CMP0037" for policy
+ details. Use the cmake_policy command to set the policy and suppress this
+ warning.
+
+ The target name "package" is reserved when CPack packaging is enabled. It
+ may result in undefined behavior.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
+This warning is for project developers. Use -Wno-dev to suppress it.$
diff --git a/Tests/RunCMake/CMP0037/WARN-cond-package.cmake b/Tests/RunCMake/CMP0037/WARN-cond-package.cmake
new file mode 100644
index 0000000..61cdc68
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/WARN-cond-package.cmake
@@ -0,0 +1,5 @@
+
+file(WRITE "${CMAKE_BINARY_DIR}/CPackConfig.cmake" "")
+add_custom_target(test)
+add_custom_target(package)
+add_custom_target(package_source)
diff --git a/Tests/RunCMake/CMP0037/WARN-cond-package_source-stderr.txt b/Tests/RunCMake/CMP0037/WARN-cond-package_source-stderr.txt
new file mode 100644
index 0000000..ae72909
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/WARN-cond-package_source-stderr.txt
@@ -0,0 +1,11 @@
+^CMake Warning \(dev\) at WARN-cond-package_source.cmake:5 \(add_custom_target\):
+ Policy CMP0037 is not set: Target names should not be reserved and should
+ match a validity pattern. Run "cmake --help-policy CMP0037" for policy
+ details. Use the cmake_policy command to set the policy and suppress this
+ warning.
+
+ The target name "package_source" is reserved when CPack source packaging is
+ enabled. It may result in undefined behavior.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
+This warning is for project developers. Use -Wno-dev to suppress it.$
diff --git a/Tests/RunCMake/CMP0037/WARN-cond-package_source.cmake b/Tests/RunCMake/CMP0037/WARN-cond-package_source.cmake
new file mode 100644
index 0000000..468380c
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/WARN-cond-package_source.cmake
@@ -0,0 +1,5 @@
+
+file(WRITE "${CMAKE_BINARY_DIR}/CPackSourceConfig.cmake" "")
+add_custom_target(test)
+add_custom_target(package)
+add_custom_target(package_source)
diff --git a/Tests/RunCMake/CMP0037/WARN-cond-test-stderr.txt b/Tests/RunCMake/CMP0037/WARN-cond-test-stderr.txt
new file mode 100644
index 0000000..e7a3ee5
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/WARN-cond-test-stderr.txt
@@ -0,0 +1,11 @@
+^CMake Warning \(dev\) at WARN-cond-test.cmake:3 \(add_custom_target\):
+ Policy CMP0037 is not set: Target names should not be reserved and should
+ match a validity pattern. Run "cmake --help-policy CMP0037" for policy
+ details. Use the cmake_policy command to set the policy and suppress this
+ warning.
+
+ The target name "test" is reserved when CTest testing is enabled. It may
+ result in undefined behavior.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
+This warning is for project developers. Use -Wno-dev to suppress it.$
diff --git a/Tests/RunCMake/CMP0037/WARN-cond-test.cmake b/Tests/RunCMake/CMP0037/WARN-cond-test.cmake
new file mode 100644
index 0000000..982af36
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/WARN-cond-test.cmake
@@ -0,0 +1,5 @@
+
+enable_testing()
+add_custom_target(test)
+add_custom_target(package)
+add_custom_target(package_source)
diff --git a/Tests/RunCMake/CMP0037/WARN-cond.cmake b/Tests/RunCMake/CMP0037/WARN-cond.cmake
new file mode 100644
index 0000000..04a7f9d
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/WARN-cond.cmake
@@ -0,0 +1,4 @@
+
+add_custom_target(test)
+add_custom_target(package)
+add_custom_target(package_source)
diff --git a/Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt b/Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt
index 5f6be87..8d5139d 100644
--- a/Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt
+++ b/Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt
@@ -12,6 +12,7 @@
\* CMP0021
\* CMP0022
\* CMP0027
+ \* CMP0037
\* CMP0038
\* CMP0041
\* CMP0042