CMP0065: Remove support for OLD behavior

This commit is contained in:
Brad King
2024-12-13 13:56:18 -05:00
parent d9dd38cccf
commit fb1bd1d330
19 changed files with 30 additions and 107 deletions

View File

@@ -337,7 +337,7 @@ Other Behavior Settings
Some policies are set automatically in the generated test project
as needed to honor the state of the calling project:
* :policy:`CMP0065`
* :policy:`CMP0065` (in CMake versions prior to 4.0)
* :policy:`CMP0083`
* :policy:`CMP0091`
* :policy:`CMP0104`

View File

@@ -1,6 +1,9 @@
CMP0065
-------
.. |REMOVED_IN_CMAKE_VERSION| replace:: 4.0
.. include:: REMOVED_PROLOGUE.txt
.. versionadded:: 3.4
Do not add flags to export symbols from executables without
@@ -21,11 +24,9 @@ flags when linking executables if the :prop_tgt:`ENABLE_EXPORTS` target
property is set to ``True``.
.. |INTRODUCED_IN_CMAKE_VERSION| replace:: 3.4
.. |WARNS_OR_DOES_NOT_WARN| replace:: does *not* warn by default
.. include:: STANDARD_ADVICE.txt
.. |WARNED_OR_DID_NOT_WARN| replace:: did *not* warn by default
.. include:: REMOVED_EPILOGUE.txt
See documentation of the
:variable:`CMAKE_POLICY_WARNING_CMP0065 <CMAKE_POLICY_WARNING_CMP<NNNN>>`
variable to control the warning.
.. include:: DEPRECATED.txt
variable to control the warning in CMake versions before 4.0.

View File

@@ -14,8 +14,8 @@ only for the policies that do not warn by default:
policy :policy:`CMP0056` in CMake versions before 4.0.
* ``CMAKE_POLICY_WARNING_CMP0060`` controlled the warning for
policy :policy:`CMP0060` in CMake versions before 4.0.
* ``CMAKE_POLICY_WARNING_CMP0065`` controls the warning for
policy :policy:`CMP0065`.
* ``CMAKE_POLICY_WARNING_CMP0065`` controlled the warning for
policy :policy:`CMP0065` in CMake versions before 4.0.
* ``CMAKE_POLICY_WARNING_CMP0066`` controls the warning for
policy :policy:`CMP0066`.
* ``CMAKE_POLICY_WARNING_CMP0067`` controls the warning for

View File

@@ -12,7 +12,7 @@ macro(__aix_compiler_gnu lang)
set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG "-Wl,-blibpath:")
set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG_SEP ":")
string(APPEND CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS " -Wl,-bnoipath")
set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "-Wl,-bexpall") # CMP0065 old behavior
set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "-Wl,-bexpall")
set(CMAKE_${lang}_USE_IMPLICIT_LINK_DIRECTORIES_IN_RUNTIME_PATH 1)
set(CMAKE_${lang}_VERBOSE_LINK_FLAG "-Wl,-v")

View File

@@ -12,7 +12,7 @@ macro(__aix_compiler_xl lang)
set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG "-Wl,-blibpath:")
set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG_SEP ":")
string(APPEND CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS " -Wl,-bnoipath")
set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "-Wl,-bexpall") # CMP0065 old behavior
set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "-Wl,-bexpall")
set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS " ")
set(CMAKE_SHARED_MODULE_${lang}_FLAGS " ")

View File

@@ -847,13 +847,6 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
fprintf(fout, "\n");
}
/* Set the appropriate policy information for ENABLE_EXPORTS */
fprintf(fout, "cmake_policy(SET CMP0065 %s)\n",
this->Makefile->GetPolicyStatus(cmPolicies::CMP0065) ==
cmPolicies::NEW
? "NEW"
: "OLD");
/* Set the appropriate policy information for PIE link flags */
fprintf(fout, "cmake_policy(SET CMP0083 %s)\n",
this->Makefile->GetPolicyStatus(cmPolicies::CMP0083) ==

View File

@@ -1629,10 +1629,10 @@ void cmLocalGenerator::GetTargetFlags(
exeFlags += " ";
}
std::string cmp0065Flags =
this->GetLinkLibsCMP0065(linkLanguage, *target);
if (!cmp0065Flags.empty()) {
exeFlags += cmp0065Flags;
std::string exeExportFlags =
this->GetExeExportFlags(linkLanguage, *target);
if (!exeExportFlags.empty()) {
exeFlags += exeExportFlags;
exeFlags += " ";
}
@@ -1959,46 +1959,18 @@ void cmLocalGenerator::OutputLinkLibraries(
linkLineComputer->ComputeLinkLibraries(cli, stdLibString, linkLibraries);
}
std::string cmLocalGenerator::GetLinkLibsCMP0065(
std::string cmLocalGenerator::GetExeExportFlags(
std::string const& linkLanguage, cmGeneratorTarget& tgt) const
{
std::string linkFlags;
// Flags to link an executable to shared libraries.
// Flags to export symbols from an executable.
if (tgt.GetType() == cmStateEnums::EXECUTABLE &&
this->StateSnapshot.GetState()->GetGlobalPropertyAsBool(
"TARGET_SUPPORTS_SHARED_LIBS")) {
bool add_shlib_flags = false;
switch (tgt.GetPolicyStatusCMP0065()) {
case cmPolicies::WARN:
if (!tgt.GetPropertyAsBool("ENABLE_EXPORTS") &&
this->Makefile->PolicyOptionalWarningEnabled(
"CMAKE_POLICY_WARNING_CMP0065")) {
std::ostringstream w;
/* clang-format off */
w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0065) << "\n"
"For compatibility with older versions of CMake, "
"additional flags may be added to export symbols on all "
"executables regardless of their ENABLE_EXPORTS property.";
/* clang-format on */
this->IssueMessage(MessageType::AUTHOR_WARNING, w.str());
}
CM_FALLTHROUGH;
case cmPolicies::OLD:
// OLD behavior is to always add the flags, except on AIX where
// we compute symbol exports if ENABLE_EXPORTS is on.
add_shlib_flags =
!(tgt.IsAIX() && tgt.GetPropertyAsBool("ENABLE_EXPORTS"));
break;
case cmPolicies::NEW:
// NEW behavior is to only add the flags if ENABLE_EXPORTS is on,
// except on AIX where we compute symbol exports.
add_shlib_flags =
!tgt.IsAIX() && tgt.GetPropertyAsBool("ENABLE_EXPORTS");
break;
}
if (add_shlib_flags) {
// Only add the flags if ENABLE_EXPORTS is on,
// except on AIX where we compute symbol exports.
if (!tgt.IsAIX() && tgt.GetPropertyAsBool("ENABLE_EXPORTS")) {
linkFlags = this->Makefile->GetSafeDefinition(
cmStrCat("CMAKE_SHARED_LIBRARY_LINK_", linkLanguage, "_FLAGS"));
}

View File

@@ -123,8 +123,8 @@ public:
cmGeneratorTarget const* target,
std::string const& language);
std::string GetLinkLibsCMP0065(std::string const& linkLanguage,
cmGeneratorTarget& tgt) const;
std::string GetExeExportFlags(std::string const& linkLanguage,
cmGeneratorTarget& tgt) const;
cmState* GetState() const;
cmStateSnapshot GetStateSnapshot() const;

View File

@@ -4015,10 +4015,10 @@ bool cmMakefile::SetPolicy(cmPolicies::PolicyID id,
!(this->GetCMakeInstance()->GetIsInTryCompile() &&
(
// Policies set by cmCoreTryCompile::TryCompileCode.
id == cmPolicies::CMP0065 || id == cmPolicies::CMP0083 ||
id == cmPolicies::CMP0091 || id == cmPolicies::CMP0104 ||
id == cmPolicies::CMP0123 || id == cmPolicies::CMP0126 ||
id == cmPolicies::CMP0128 || id == cmPolicies::CMP0136)) &&
id == cmPolicies::CMP0083 || id == cmPolicies::CMP0091 ||
id == cmPolicies::CMP0104 || id == cmPolicies::CMP0123 ||
id == cmPolicies::CMP0126 || id == cmPolicies::CMP0128 ||
id == cmPolicies::CMP0136)) &&
(!this->IsSet("CMAKE_WARN_DEPRECATED") ||
this->IsOn("CMAKE_WARN_DEPRECATED"))) {
this->IssueMessage(MessageType::DEPRECATION_WARNING,

View File

@@ -397,7 +397,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
}
this->LocalGenerator->AppendFlags(linkFlags,
this->LocalGenerator->GetLinkLibsCMP0065(
this->LocalGenerator->GetExeExportFlags(
linkLanguage, *this->GeneratorTarget));
this->UseLWYU = this->LocalGenerator->AppendLWYUFlags(

View File

@@ -189,7 +189,7 @@ class cmMakefile;
SELECT(POLICY, CMP0065, \
"Do not add flags to export symbols from executables without " \
"the ENABLE_EXPORTS target property.", \
3, 4, 0, WARN) \
3, 4, 0, NEW) \
SELECT(POLICY, CMP0066, \
"Honor per-config flags in try_compile() source-file signature.", 3, \
7, 0, WARN) \

View File

@@ -1,3 +1,3 @@
cmake_minimum_required(VERSION 3.3)
cmake_minimum_required(VERSION 3.10)
project(${RunCMake_TEST} NONE)
include(${RunCMake_TEST}.cmake)

View File

@@ -1,4 +0,0 @@
enable_language(C)
include(BuildTargetInSubProject.cmake)
BuildTargetInSubProject(TestPolicyCMP0065 FooOLDBad1 FALSE)

View File

@@ -1,4 +0,0 @@
enable_language(C)
include(BuildTargetInSubProject.cmake)
BuildTargetInSubProject(TestPolicyCMP0065 FooOLDBad2 FALSE)

View File

@@ -1,12 +1,7 @@
include(RunCMake)
set(RunCMake_IGNORE_POLICY_VERSION_DEPRECATION ON)
run_cmake(OLDBad1)
if(NOT CMAKE_SYSTEM_NAME STREQUAL "AIX")
# Tests with ENABLE_EXPORTS ON. For AIX we do not use the flags at all.
run_cmake(OLDBad2)
run_cmake(NEWBad)
endif()
run_cmake(NEWGood)
run_cmake(WARN-OFF)
run_cmake(WARN-ON)

View File

@@ -1,3 +0,0 @@
enable_language(C)
add_executable(main subproject/main.c)

View File

@@ -1,10 +0,0 @@
CMake Warning \(dev\) in CMakeLists.txt:
Policy CMP0065 is not set: Do not add flags to export symbols from
executables without the ENABLE_EXPORTS target property. Run "cmake
--help-policy CMP0065" for policy details. Use the cmake_policy command to
set the policy and suppress this warning.
For compatibility with older versions of CMake, additional flags may be
added to export symbols on all executables regardless of their
ENABLE_EXPORTS property.
This warning is for project developers. Use -Wno-dev to suppress it.

View File

@@ -1,3 +0,0 @@
set(CMAKE_POLICY_WARNING_CMP0065 1)
enable_language(C)
add_executable(main subproject/main.c)

View File

@@ -1,22 +1,8 @@
cmake_minimum_required(VERSION 3.3)
cmake_minimum_required(VERSION 3.10)
project(TestPolicyCMP0065 C)
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS BADFLAGS)
#----------------------------------------------------------------------
cmake_policy(SET CMP0065 OLD)
add_executable(FooOLDBad1 main.c)
#----------------------------------------------------------------------
cmake_policy(SET CMP0065 OLD)
add_executable(FooOLDBad2 main.c)
set_target_properties(FooOLDBad2 PROPERTIES ENABLE_EXPORTS ON)
#----------------------------------------------------------------------
cmake_policy(SET CMP0065 NEW)
add_executable(FooNEWGood main.c)
#----------------------------------------------------------------------
cmake_policy(SET CMP0065 NEW)
add_executable(FooNEWBad main.c)
set_target_properties(FooNEWBad PROPERTIES ENABLE_EXPORTS ON)