mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-15 03:48:02 +08:00
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
This commit is contained in:
@@ -2707,6 +2707,7 @@ cmGlobalGenerator::SplitFrameworkPath(const std::string& path,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool RaiseCMP0037Message(cmake* cm, cmTarget* tgt,
|
static bool RaiseCMP0037Message(cmake* cm, cmTarget* tgt,
|
||||||
|
std::string const& targetNameAsWritten,
|
||||||
std::string const& reason)
|
std::string const& reason)
|
||||||
{
|
{
|
||||||
MessageType messageType = MessageType::AUTHOR_WARNING;
|
MessageType messageType = MessageType::AUTHOR_WARNING;
|
||||||
@@ -2727,8 +2728,8 @@ static bool RaiseCMP0037Message(cmake* cm, cmTarget* tgt,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (issueMessage) {
|
if (issueMessage) {
|
||||||
e << "The target name \"" << tgt->GetName() << "\" is reserved " << reason
|
e << "The target name \"" << targetNameAsWritten << "\" is reserved "
|
||||||
<< ".";
|
<< reason << ".";
|
||||||
if (messageType == MessageType::AUTHOR_WARNING) {
|
if (messageType == MessageType::AUTHOR_WARNING) {
|
||||||
e << " It may result in undefined behavior.";
|
e << " It may result in undefined behavior.";
|
||||||
}
|
}
|
||||||
@@ -2747,7 +2748,8 @@ bool cmGlobalGenerator::CheckCMP0037(std::string const& targetName,
|
|||||||
if (!tgt) {
|
if (!tgt) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return RaiseCMP0037Message(this->GetCMakeInstance(), tgt, reason);
|
return RaiseCMP0037Message(this->GetCMakeInstance(), tgt, targetName,
|
||||||
|
reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmGlobalGenerator::CreateDefaultGlobalTargets(
|
void cmGlobalGenerator::CreateDefaultGlobalTargets(
|
||||||
|
@@ -45,6 +45,10 @@ run_cmake(WARN-cond)
|
|||||||
run_cmake(WARN-cond-test)
|
run_cmake(WARN-cond-test)
|
||||||
run_cmake(WARN-cond-package)
|
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")
|
if(RunCMake_GENERATOR MATCHES "Make|Ninja")
|
||||||
run_cmake(NEW-cond-package_source)
|
run_cmake(NEW-cond-package_source)
|
||||||
run_cmake(OLD-cond-package_source)
|
run_cmake(OLD-cond-package_source)
|
||||||
|
1
Tests/RunCMake/CMP0037/alias-test-NEW-result.txt
Normal file
1
Tests/RunCMake/CMP0037/alias-test-NEW-result.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
1
|
5
Tests/RunCMake/CMP0037/alias-test-NEW-stderr.txt
Normal file
5
Tests/RunCMake/CMP0037/alias-test-NEW-stderr.txt
Normal file
@@ -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
Tests/RunCMake/CMP0037/alias-test-NEW.cmake
Normal file
2
Tests/RunCMake/CMP0037/alias-test-NEW.cmake
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
cmake_policy(SET CMP0037 NEW)
|
||||||
|
include(alias-test-common.cmake)
|
10
Tests/RunCMake/CMP0037/alias-test-OLD-stderr.txt
Normal file
10
Tests/RunCMake/CMP0037/alias-test-OLD-stderr.txt
Normal file
@@ -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
Tests/RunCMake/CMP0037/alias-test-OLD.cmake
Normal file
2
Tests/RunCMake/CMP0037/alias-test-OLD.cmake
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
cmake_policy(SET CMP0037 OLD)
|
||||||
|
include(alias-test-common.cmake)
|
11
Tests/RunCMake/CMP0037/alias-test-WARN-stderr.txt
Normal file
11
Tests/RunCMake/CMP0037/alias-test-WARN-stderr.txt
Normal file
@@ -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
Tests/RunCMake/CMP0037/alias-test-WARN.cmake
Normal file
2
Tests/RunCMake/CMP0037/alias-test-WARN.cmake
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# leave CMP0037 unset
|
||||||
|
include(alias-test-common.cmake)
|
3
Tests/RunCMake/CMP0037/alias-test-common.cmake
Normal file
3
Tests/RunCMake/CMP0037/alias-test-common.cmake
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
enable_testing()
|
||||||
|
add_library(iface INTERFACE)
|
||||||
|
add_library(test ALIAS iface)
|
Reference in New Issue
Block a user