Browse Source

Merge topic 'cmp0037-message' into release-3.29

c773d5b436 CMP0037: Restore diagnostic message for invalid ALIAS target names

Acked-by: Kitware Robot <[email protected]>
Acked-by: buildbot <[email protected]>
Reviewed-by: Ben Boeckel <[email protected]>
Merge-request: !9519
Brad King 1 year ago
parent
commit
19c2f8e1f3

+ 5 - 3
Source/cmGlobalGenerator.cxx

@@ -2730,6 +2730,7 @@ cmGlobalGenerator::SplitFrameworkPath(const std::string& path,
 }
 
 static bool RaiseCMP0037Message(cmake* cm, cmTarget* tgt,
+                                std::string const& targetNameAsWritten,
                                 std::string const& reason)
 {
   MessageType messageType = MessageType::AUTHOR_WARNING;
@@ -2750,8 +2751,8 @@ static bool RaiseCMP0037Message(cmake* cm, cmTarget* tgt,
       break;
   }
   if (issueMessage) {
-    e << "The target name \"" << tgt->GetName() << "\" is reserved " << reason
-      << ".";
+    e << "The target name \"" << targetNameAsWritten << "\" is reserved "
+      << reason << ".";
     if (messageType == MessageType::AUTHOR_WARNING) {
       e << "  It may result in undefined behavior.";
     }
@@ -2770,7 +2771,8 @@ bool cmGlobalGenerator::CheckCMP0037(std::string const& targetName,
   if (!tgt) {
     return true;
   }
-  return RaiseCMP0037Message(this->GetCMakeInstance(), tgt, reason);
+  return RaiseCMP0037Message(this->GetCMakeInstance(), tgt, targetName,
+                             reason);
 }
 
 void cmGlobalGenerator::CreateDefaultGlobalTargets(

+ 4 - 0
Tests/RunCMake/CMP0037/RunCMakeTest.cmake

@@ -45,6 +45,10 @@ run_cmake(WARN-cond)
 run_cmake(WARN-cond-test)
 run_cmake(WARN-cond-package)
 
+run_cmake(alias-test-NEW)
+run_cmake(alias-test-OLD)
+run_cmake(alias-test-WARN)
+
 if(RunCMake_GENERATOR MATCHES "Make|Ninja")
   run_cmake(NEW-cond-package_source)
   run_cmake(OLD-cond-package_source)

+ 1 - 0
Tests/RunCMake/CMP0037/alias-test-NEW-result.txt

@@ -0,0 +1 @@
+1

+ 5 - 0
Tests/RunCMake/CMP0037/alias-test-NEW-stderr.txt

@@ -0,0 +1,5 @@
+^CMake Error at alias-test-common\.cmake:[0-9]+ \(add_library\):
+  The target name "test" is reserved when CTest testing is enabled\.
+Call Stack \(most recent call first\):
+  alias-test-NEW\.cmake:[0-9]+ \(include\)
+  CMakeLists\.txt:[0-9]+ \(include\)$

+ 2 - 0
Tests/RunCMake/CMP0037/alias-test-NEW.cmake

@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0037 NEW)
+include(alias-test-common.cmake)

+ 10 - 0
Tests/RunCMake/CMP0037/alias-test-OLD-stderr.txt

@@ -0,0 +1,10 @@
+^CMake Deprecation Warning at alias-test-OLD\.cmake:[0-9]+ \(cmake_policy\):
+  The OLD behavior for policy CMP0037 will be removed from a future version
+  of CMake\.
+
+  The cmake-policies\(7\) manual explains that the OLD behaviors of all
+  policies are deprecated and that a policy should be set to OLD only under
+  specific short-term circumstances\.  Projects should be ported to the NEW
+  behavior and not rely on setting a policy to OLD\.
+Call Stack \(most recent call first\):
+  CMakeLists\.txt:[0-9]+ \(include\)$

+ 2 - 0
Tests/RunCMake/CMP0037/alias-test-OLD.cmake

@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0037 OLD)
+include(alias-test-common.cmake)

+ 11 - 0
Tests/RunCMake/CMP0037/alias-test-WARN-stderr.txt

@@ -0,0 +1,11 @@
+^CMake Warning \(dev\) at alias-test-common\.cmake:[0-9]+ \(add_library\):
+  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\):
+  alias-test-WARN\.cmake:[0-9]+ \(include\)
+  CMakeLists\.txt:[0-9]+ \(include\)

+ 2 - 0
Tests/RunCMake/CMP0037/alias-test-WARN.cmake

@@ -0,0 +1,2 @@
+# leave CMP0037 unset
+include(alias-test-common.cmake)

+ 3 - 0
Tests/RunCMake/CMP0037/alias-test-common.cmake

@@ -0,0 +1,3 @@
+enable_testing()
+add_library(iface INTERFACE)
+add_library(test ALIAS iface)