Do not produce legacy _LIB_DEPENDS cache entries

Introduce policy `CMP0073` to avoid producing these cache entries.

Fixes: #16364
This commit is contained in:
Brad King
2018-03-06 14:21:38 -05:00
parent 2124a1364a
commit 7723e9a058
10 changed files with 70 additions and 2 deletions

View File

@@ -51,6 +51,14 @@ The :variable:`CMAKE_MINIMUM_REQUIRED_VERSION` variable may also be used
to determine whether to report an error on use of deprecated macros or
functions.
Policies Introduced by CMake 3.12
=================================
.. toctree::
:maxdepth: 1
CMP0073: Do not produce legacy _LIB_DEPENDS cache entries. </policy/CMP0073>
Policies Introduced by CMake 3.11
=================================

25
Help/policy/CMP0073.rst Normal file
View File

@@ -0,0 +1,25 @@
CMP0073
-------
Do not produce legacy ``_LIB_DEPENDS`` cache entries.
Ancient CMake versions once used ``<tgt>_LIB_DEPENDS`` cache entries to
propagate library link dependencies. This has long been done by other
means, leaving the :command:`export_library_dependencies` command as the
only user of these values. That command has long been disallowed by
policy :policy:`CMP0033`, but the ``<tgt>_LIB_DEPENDS`` cache entries
were left for compatibility with possible non-standard uses by projects.
CMake 3.12 and above now prefer to not produce these cache entries
at all. This policy provides compatibility with projects that have
not been updated to avoid using them.
The ``OLD`` behavior for this policy is to set ``<tgt>_LIB_DEPENDS`` cache
entries. The ``NEW`` behavior for this policy is to not set them.
This policy was introduced in CMake version 3.12. Use the
:command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
Unlike most policies, CMake version |release| does *not* warn
when this policy is not set and simply uses ``OLD`` behavior.
.. include:: DEPRECATED.txt

View File

@@ -0,0 +1,5 @@
avoid-LIB_DEPENDS
-----------------
* CMake no longer produces ``<tgt>_LIB_DEPENDS`` cache entries
for library targets. See policy :policy:`CMP0073`.

View File

@@ -214,6 +214,9 @@ class cmMakefile;
3, 10, 0, cmPolicies::WARN) \
SELECT(POLICY, CMP0072, \
"FindOpenGL prefers GLVND by default when available.", 3, 11, 0, \
cmPolicies::WARN) \
SELECT(POLICY, CMP0073, \
"Do not produce legacy _LIB_DEPENDS cache entries.", 3, 12, 0, \
cmPolicies::WARN)
#define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
@@ -238,7 +241,8 @@ class cmMakefile;
F(CMP0063) \
F(CMP0065) \
F(CMP0068) \
F(CMP0069)
F(CMP0069) \
F(CMP0073)
/** \class cmPolicies
* \brief Handles changes in CMake behavior and policies

View File

@@ -737,7 +737,9 @@ void cmTarget::AddLinkLibrary(cmMakefile& mf, const std::string& lib,
// and we removing one instance will break the link line. Duplicates
// will be appropriately eliminated at emit time.
if (this->TargetTypeValue >= cmStateEnums::STATIC_LIBRARY &&
this->TargetTypeValue <= cmStateEnums::MODULE_LIBRARY) {
this->TargetTypeValue <= cmStateEnums::MODULE_LIBRARY &&
(this->GetPolicyStatusCMP0073() == cmPolicies::OLD ||
this->GetPolicyStatusCMP0073() == cmPolicies::WARN)) {
std::string targetEntry = this->Name;
targetEntry += "_LIB_DEPENDS";
std::string dependencies;

View File

@@ -23,6 +23,7 @@
\* CMP0065
\* CMP0068
\* CMP0069
\* CMP0073
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@@ -0,0 +1,3 @@
-- warn_LIB_DEPENDS='general;bar;'
-- old_LIB_DEPENDS='general;bar;'
-- new_LIB_DEPENDS=''

View File

@@ -0,0 +1,18 @@
enable_language(C)
add_library(warn empty.c)
target_link_libraries(warn bar)
message(STATUS "warn_LIB_DEPENDS='${warn_LIB_DEPENDS}'")
cmake_policy(SET CMP0073 OLD)
add_library(old empty.c)
target_link_libraries(old bar)
message(STATUS "old_LIB_DEPENDS='${old_LIB_DEPENDS}'")
cmake_policy(SET CMP0073 NEW)
add_library(new empty.c)
target_link_libraries(new bar)
message(STATUS "new_LIB_DEPENDS='${new_LIB_DEPENDS}'")
if(DEFINED new_LIB_DEPENDS)
message(FATAL_ERROR "new_LIB_DEPENDS set but should not be")
endif()

View File

@@ -1,5 +1,7 @@
include(RunCMake)
run_cmake(CMP0073)
run_cmake(INTERFACEwithNoSources)
run_cmake(OBJECTwithNoSources)
run_cmake(STATICwithNoSources)

View File