LINK_DIRECTORIES target property: add policy for absolute paths check.

This commit is contained in:
Marc Chevrier
2018-09-18 17:23:07 +02:00
committed by Craig Scott
parent a71caab46b
commit b5915744eb
19 changed files with 109 additions and 4 deletions

View File

@@ -57,6 +57,7 @@ Policies Introduced by CMake 3.13
.. toctree::
:maxdepth: 1
CMP0081: Relative paths not allowed in LINK_DIRECTORIES target property. </policy/CMP0081>
CMP0080: BundleUtilities cannot be included at configure time. </policy/CMP0080>
CMP0079: target_link_libraries allows use with targets in other directories. </policy/CMP0079>
CMP0078: UseSWIG generates standard target names. </policy/CMP0078>

22
Help/policy/CMP0081.rst Normal file
View File

@@ -0,0 +1,22 @@
CMP0081
-------
Relative paths not allowed in :prop_tgt:`LINK_DIRECTORIES` target property.
CMake 3.12 and lower allowed the :prop_dir:`LINK_DIRECTORIES` directory
property to contain relative paths. The base path for such relative
entries is not well defined. CMake 3.13 and later will issue a
``FATAL_ERROR`` if the :prop_tgt:`LINK_DIRECTORIES` target property
(which is initialized by the :prop_dir:`LINK_DIRECTORIES` directory property)
contains a relative path.
The ``OLD`` behavior for this policy is not to warn about relative paths
in the :prop_tgt:`LINK_DIRECTORIES` target property. The ``NEW`` behavior for
this policy is to issue a ``FATAL_ERROR`` if :prop_tgt:`LINK_DIRECTORIES`
contains a relative path.
This policy was introduced in CMake version 3.13. CMake version
|release| warns when the policy is not set and uses ``OLD`` behavior. Use
the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt

View File

@@ -0,0 +1,5 @@
LINK_DIRECTORIES-policy
-----------------------
* The :prop_tgt:`LINK_DIRECTORIES` target property expects absolute paths.
See policy :policy:`CMP0081`.

View File

@@ -3091,14 +3091,38 @@ void processLinkDirectories(
for (std::string& entryDirectory : entryDirectories) {
if (!cmSystemTools::FileIsFullPath(entryDirectory)) {
std::ostringstream e;
bool noMessage = false;
cmake::MessageType messageType = cmake::FATAL_ERROR;
if (!targetName.empty()) {
/* clang-format off */
e << "Target \"" << targetName << "\" contains relative "
"path in its INTERFACE_LINK_DIRECTORIES:\n"
" \"" << entryDirectory << "\"";
/* clang-format on */
tgt->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, e.str());
return;
} else {
switch (tgt->GetPolicyStatusCMP0081()) {
case cmPolicies::WARN: {
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0081) << "\n";
messageType = cmake::AUTHOR_WARNING;
} break;
case cmPolicies::OLD:
noMessage = true;
break;
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::REQUIRED_ALWAYS:
case cmPolicies::NEW:
// Issue the fatal message.
break;
}
e << "Found relative path while evaluating link directories of "
"\""
<< tgt->GetName() << "\":\n \"" << entryDirectory << "\"\n";
}
if (!noMessage) {
tgt->GetLocalGenerator()->IssueMessage(messageType, e.str());
if (messageType == cmake::FATAL_ERROR) {
return;
}
}
}

View File

@@ -237,7 +237,10 @@ class cmMakefile;
13, 0, cmPolicies::WARN) \
SELECT(POLICY, CMP0080, \
"BundleUtilities cannot be included at configure time", 3, 13, 0, \
cmPolicies::WARN)
cmPolicies::WARN) \
SELECT(POLICY, CMP0081, \
"Relative paths not allowed in LINK_DIRECTORIES target property.", \
3, 13, 0, cmPolicies::WARN)
#define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
#define CM_FOR_EACH_POLICY_ID(POLICY) \
@@ -263,7 +266,8 @@ class cmMakefile;
F(CMP0068) \
F(CMP0069) \
F(CMP0073) \
F(CMP0076)
F(CMP0076) \
F(CMP0081)
/** \class cmPolicies
* \brief Handles changes in CMake behavior and policies

View File

@@ -0,0 +1,5 @@
enable_language(CXX)
add_library(foo SHARED empty.cpp)
set_target_properties(foo PROPERTIES LINK_DIRECTORIES "../lib")

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1,4 @@
CMake Error in CMakeLists.txt:
Found relative path while evaluating link directories of "foo":
"../lib"

View File

@@ -0,0 +1,4 @@
cmake_policy(SET CMP0081 NEW)
include (CMP0081-Common.cmake)

View File

@@ -0,0 +1 @@
0

View File

@@ -0,0 +1,4 @@
cmake_policy(SET CMP0081 OLD)
include (CMP0081-Common.cmake)

View File

@@ -0,0 +1 @@
0

View File

@@ -0,0 +1,10 @@
CMake Warning \(dev\) in CMakeLists.txt:
Policy CMP0081 is not set: Relative paths not allowed in LINK_DIRECTORIES
target property. Run "cmake --help-policy CMP0081" for policy details.
Use the cmake_policy command to set the policy and suppress this warning.
Found relative path while evaluating link directories of "foo":
"../lib"
This warning is for project developers. Use -Wno-dev to suppress it.

View File

@@ -0,0 +1,2 @@
include (CMP0081-Common.cmake)

View File

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

View File

@@ -0,0 +1,5 @@
include(RunCMake)
run_cmake(CMP0081-OLD)
run_cmake(CMP0081-NEW)
run_cmake(CMP0081-WARN)

View File

@@ -0,0 +1,7 @@
#ifdef _WIN32
__declspec(dllexport)
#endif
int empty()
{
return 0;
}

View File

@@ -106,6 +106,7 @@ if(CMAKE_SYSTEM_NAME MATCHES Darwin AND CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG)
add_RunCMake_test(CMP0068)
endif()
add_RunCMake_test(CMP0069)
add_RunCMake_test(CMP0081)
# The test for Policy 65 requires the use of the
# CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS variable, which both the VS and Xcode

View File

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