CMP0210: Warn at most once per CMAKE_<LANG>_LINK_FLAGS variable

Additionally, add more testing for the warning case.

Issue: #21934
This commit is contained in:
Tyler Yankee
2026-02-18 11:44:07 -05:00
parent 4966f3ed98
commit 8b350fae71
11 changed files with 41 additions and 10 deletions
+6
View File
@@ -1386,6 +1386,11 @@ void cmGlobalGenerator::AddCMP0068WarnTarget(std::string const& target)
this->CMP0068WarnTargets.insert(target);
}
bool cmGlobalGenerator::ShouldWarnCMP0210(std::string const& lang)
{
return this->WarnedCMP0210Languages.insert(lang).second;
}
bool cmGlobalGenerator::CheckALLOW_DUPLICATE_CUSTOM_TARGETS() const
{
// If the property is not enabled then okay.
@@ -2101,6 +2106,7 @@ void cmGlobalGenerator::ClearGeneratorMembers()
this->RuntimeDependencySets.clear();
this->RuntimeDependencySetsByName.clear();
this->WarnedExperimental.clear();
this->WarnedCMP0210Languages.clear();
}
bool cmGlobalGenerator::SupportsShortObjectNames() const
+4
View File
@@ -715,6 +715,8 @@ public:
return configs;
}
bool ShouldWarnCMP0210(std::string const& lang);
bool ShouldWarnExperimental(cm::string_view featureName,
cm::string_view featureUuid);
@@ -967,6 +969,8 @@ private:
// track targets to issue CMP0068 warning for.
std::set<std::string> CMP0068WarnTargets;
std::unordered_set<std::string> WarnedCMP0210Languages;
std::unordered_set<std::string> WarnedExperimental;
mutable std::map<cmSourceFile*, std::set<cmGeneratorTarget const*>>
+6 -3
View File
@@ -3384,17 +3384,20 @@ void cmLocalGenerator::AddPerLanguageLinkFlags(std::string& flags,
// their wishes), while also exempting cases when the latter variable
// (substituted for the former spelling under the NEW behavior) is being
// used legitimately by CMake.
// Additionally, WARN at most once per language, instead of on every
// target.
if (!langLinkFlags.empty() &&
target->GetType() != cmStateEnums::EXECUTABLE &&
langLinkFlags !=
this->Makefile->GetSafeDefinition(
cmStrCat("CMAKE_EXECUTABLE_CREATE_", lang, "_FLAGS"))) {
cmStrCat("CMAKE_EXECUTABLE_CREATE_", lang, "_FLAGS")) &&
this->GlobalGenerator->ShouldWarnCMP0210(lang)) {
this->IssueMessage(
MessageType::AUTHOR_WARNING,
cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0210), "\n",
"For compatibility with older versions of CMake, ",
"CMAKE_", lang, "_LINK_FLAGS will be ignored for target '",
target->GetName(), "'."));
"CMAKE_", lang, "_LINK_FLAGS will be ignored for all ",
"non-EXECUTABLE targets which use these flags."));
}
CM_FALLTHROUGH;
case cmPolicies::OLD:
@@ -1 +0,0 @@
.*BADFLAG.*
@@ -0,0 +1 @@
.*BADFLAG_C.*
@@ -0,0 +1 @@
.*BADFLAG_CXX.*
@@ -4,5 +4,14 @@ CMake Warning \(dev\) in CMakeLists\.txt:
the cmake_policy command to set the policy and suppress this warning\.
For compatibility with older versions of CMake, CMAKE_C_LINK_FLAGS will be
ignored for target 'LinkFlags_shared'\.
ignored for all non-EXECUTABLE targets which use these flags.
This warning is for project developers\. Use -Wno-dev to suppress it\.
CMake Warning \(dev\) in CMakeLists\.txt:
Policy CMP0210 is not set: CMAKE_<LANG>_LINK_FLAGS adds link flags to all
target types\. Run "cmake --help-policy CMP0210" for policy details\. Use
the cmake_policy command to set the policy and suppress this warning\.
For compatibility with older versions of CMake, CMAKE_CXX_LINK_FLAGS will
be ignored for all non-EXECUTABLE targets which use these flags.
This warning is for project developers\. Use -Wno-dev to suppress it\.
@@ -1,3 +1,8 @@
set(CMAKE_C_LINK_FLAGS ${pre}BADFLAG${obj})
add_library(LinkFlags_shared SHARED LinkFlagsLib.c)
add_executable(LinkFlags_exe LinkFlagsExe.c)
set(CMAKE_C_LINK_FLAGS ${pre}BADFLAG_C${obj})
set(CMAKE_CXX_LINK_FLAGS ${pre}BADFLAG_CXX${obj})
add_library(LinkFlags_shared_C SHARED LinkFlagsLib.c)
add_executable(LinkFlags_exe_C LinkFlagsExe.c)
add_library(LinkFlags_shared_CXX SHARED LinkFlagsLib.cxx)
add_executable(LinkFlags_exe_CXX LinkFlagsExe.cxx)
+4 -2
View File
@@ -65,8 +65,10 @@ if (NOT CMAKE_C_COMPILER_ID STREQUAL "Intel")
run_cmake_target(CMAKE_LANG_LINK_FLAGS-CMP0210-OLD exe)
run_cmake(CMAKE_LANG_LINK_FLAGS-CMP0210-WARN)
run_cmake_target(CMAKE_LANG_LINK_FLAGS-CMP0210-WARN shared)
run_cmake_target(CMAKE_LANG_LINK_FLAGS-CMP0210-WARN exe)
run_cmake_target(CMAKE_LANG_LINK_FLAGS-CMP0210-WARN shared_C)
run_cmake_target(CMAKE_LANG_LINK_FLAGS-CMP0210-WARN exe_C)
run_cmake_target(CMAKE_LANG_LINK_FLAGS-CMP0210-WARN shared_CXX)
run_cmake_target(CMAKE_LANG_LINK_FLAGS-CMP0210-WARN exe_CXX)
endif()
unset(RunCMake_TEST_OPTIONS)