CMP0037: Restore diagnostic message for invalid ALIAS target names
Refactoring in commit 7a4c02cb38
(cmGlobalGenerator: factor out
messaging for CMP0037, 2023-09-24, v3.28.0-rc1~39^2~7) incorrectly
switched to reporting the aliased target name instead of the invalid
name of the alias itself.
Fixes: #25979
stage/master/nightly/2024/05/15
parent
065729b6d1
commit
c773d5b436
|
@ -2707,6 +2707,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;
|
||||
|
@ -2727,8 +2728,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.";
|
||||
}
|
||||
|
@ -2747,7 +2748,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(
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
1
|
|
@ -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\)$
|
|
@ -0,0 +1,2 @@
|
|||
cmake_policy(SET CMP0037 NEW)
|
||||
include(alias-test-common.cmake)
|
|
@ -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\)$
|
|
@ -0,0 +1,2 @@
|
|||
cmake_policy(SET CMP0037 OLD)
|
||||
include(alias-test-common.cmake)
|
|
@ -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\)
|
|
@ -0,0 +1,2 @@
|
|||
# leave CMP0037 unset
|
||||
include(alias-test-common.cmake)
|
|
@ -0,0 +1,3 @@
|
|||
enable_testing()
|
||||
add_library(iface INTERFACE)
|
||||
add_library(test ALIAS iface)
|
Loading…
Reference in New Issue