CMP0171: Improve diagnostic context

When issuing the policy warning that `codegen` is a reserved target
name, use the diagnostic context in which the target was declared,
rather than the root context (which cannot be affected in script).
This commit is contained in:
Matthew Woehlke
2026-05-11 15:02:49 -04:00
parent e4de3c84ce
commit 556bd0d722
4 changed files with 11 additions and 1 deletions
+1 -1
View File
@@ -3101,7 +3101,7 @@ void cmGlobalGenerator::ReserveGlobalTargetCodegen()
switch (policyStatus) {
case cmPolicies::WARN:
this->GetCMakeInstance()->IssueDiagnostic(
tgt->GetMakefile()->IssueDiagnostic(
cmDiagnostics::CMD_AUTHOR,
cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0171), '\n',
"The target name \"codegen\" is reserved."),
@@ -0,0 +1 @@
add_subdirectory("CMP0171-WARN-QUIET")
@@ -0,0 +1,8 @@
# CMake should warn the user if they have a target named codegen... unless the
# user also suppresses the diagnostic.
cmake_diagnostic(SET CMD_AUTHOR IGNORE RECURSE)
add_custom_target(codegen
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/generated.h.in
${CMAKE_CURRENT_BINARY_DIR}/generated.h
)
@@ -1,6 +1,7 @@
include(RunCMake)
run_cmake("CMP0171-WARN")
run_cmake("CMP0171-WARN-QUIET")
run_cmake_with_options(CMP0171-OLD "-DCMAKE_POLICY_DEFAULT_CMP0171=OLD")