mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-16 20:21:41 -06:00
LINK_DIRECTORIES target property: add policy for absolute paths check.
This commit is contained in:
committed by
Craig Scott
parent
a71caab46b
commit
b5915744eb
@@ -57,6 +57,7 @@ Policies Introduced by CMake 3.13
|
|||||||
.. toctree::
|
.. toctree::
|
||||||
:maxdepth: 1
|
:maxdepth: 1
|
||||||
|
|
||||||
|
CMP0081: Relative paths not allowed in LINK_DIRECTORIES target property. </policy/CMP0081>
|
||||||
CMP0080: BundleUtilities cannot be included at configure time. </policy/CMP0080>
|
CMP0080: BundleUtilities cannot be included at configure time. </policy/CMP0080>
|
||||||
CMP0079: target_link_libraries allows use with targets in other directories. </policy/CMP0079>
|
CMP0079: target_link_libraries allows use with targets in other directories. </policy/CMP0079>
|
||||||
CMP0078: UseSWIG generates standard target names. </policy/CMP0078>
|
CMP0078: UseSWIG generates standard target names. </policy/CMP0078>
|
||||||
|
|||||||
22
Help/policy/CMP0081.rst
Normal file
22
Help/policy/CMP0081.rst
Normal 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
|
||||||
5
Help/release/dev/LINK_DIRECTORIES-policy.rst
Normal file
5
Help/release/dev/LINK_DIRECTORIES-policy.rst
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
LINK_DIRECTORIES-policy
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
* The :prop_tgt:`LINK_DIRECTORIES` target property expects absolute paths.
|
||||||
|
See policy :policy:`CMP0081`.
|
||||||
@@ -3091,14 +3091,38 @@ void processLinkDirectories(
|
|||||||
for (std::string& entryDirectory : entryDirectories) {
|
for (std::string& entryDirectory : entryDirectories) {
|
||||||
if (!cmSystemTools::FileIsFullPath(entryDirectory)) {
|
if (!cmSystemTools::FileIsFullPath(entryDirectory)) {
|
||||||
std::ostringstream e;
|
std::ostringstream e;
|
||||||
|
bool noMessage = false;
|
||||||
|
cmake::MessageType messageType = cmake::FATAL_ERROR;
|
||||||
if (!targetName.empty()) {
|
if (!targetName.empty()) {
|
||||||
/* clang-format off */
|
/* clang-format off */
|
||||||
e << "Target \"" << targetName << "\" contains relative "
|
e << "Target \"" << targetName << "\" contains relative "
|
||||||
"path in its INTERFACE_LINK_DIRECTORIES:\n"
|
"path in its INTERFACE_LINK_DIRECTORIES:\n"
|
||||||
" \"" << entryDirectory << "\"";
|
" \"" << entryDirectory << "\"";
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
tgt->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, e.str());
|
} else {
|
||||||
return;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -237,7 +237,10 @@ class cmMakefile;
|
|||||||
13, 0, cmPolicies::WARN) \
|
13, 0, cmPolicies::WARN) \
|
||||||
SELECT(POLICY, CMP0080, \
|
SELECT(POLICY, CMP0080, \
|
||||||
"BundleUtilities cannot be included at configure time", 3, 13, 0, \
|
"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_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
|
||||||
#define CM_FOR_EACH_POLICY_ID(POLICY) \
|
#define CM_FOR_EACH_POLICY_ID(POLICY) \
|
||||||
@@ -263,7 +266,8 @@ class cmMakefile;
|
|||||||
F(CMP0068) \
|
F(CMP0068) \
|
||||||
F(CMP0069) \
|
F(CMP0069) \
|
||||||
F(CMP0073) \
|
F(CMP0073) \
|
||||||
F(CMP0076)
|
F(CMP0076) \
|
||||||
|
F(CMP0081)
|
||||||
|
|
||||||
/** \class cmPolicies
|
/** \class cmPolicies
|
||||||
* \brief Handles changes in CMake behavior and policies
|
* \brief Handles changes in CMake behavior and policies
|
||||||
|
|||||||
5
Tests/RunCMake/CMP0081/CMP0081-Common.cmake
Normal file
5
Tests/RunCMake/CMP0081/CMP0081-Common.cmake
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
enable_language(CXX)
|
||||||
|
|
||||||
|
add_library(foo SHARED empty.cpp)
|
||||||
|
set_target_properties(foo PROPERTIES LINK_DIRECTORIES "../lib")
|
||||||
1
Tests/RunCMake/CMP0081/CMP0081-NEW-result.txt
Normal file
1
Tests/RunCMake/CMP0081/CMP0081-NEW-result.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
1
|
||||||
4
Tests/RunCMake/CMP0081/CMP0081-NEW-stderr.txt
Normal file
4
Tests/RunCMake/CMP0081/CMP0081-NEW-stderr.txt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
CMake Error in CMakeLists.txt:
|
||||||
|
Found relative path while evaluating link directories of "foo":
|
||||||
|
|
||||||
|
"../lib"
|
||||||
4
Tests/RunCMake/CMP0081/CMP0081-NEW.cmake
Normal file
4
Tests/RunCMake/CMP0081/CMP0081-NEW.cmake
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
cmake_policy(SET CMP0081 NEW)
|
||||||
|
|
||||||
|
include (CMP0081-Common.cmake)
|
||||||
1
Tests/RunCMake/CMP0081/CMP0081-OLD-result.txt
Normal file
1
Tests/RunCMake/CMP0081/CMP0081-OLD-result.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
0
|
||||||
4
Tests/RunCMake/CMP0081/CMP0081-OLD.cmake
Normal file
4
Tests/RunCMake/CMP0081/CMP0081-OLD.cmake
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
cmake_policy(SET CMP0081 OLD)
|
||||||
|
|
||||||
|
include (CMP0081-Common.cmake)
|
||||||
1
Tests/RunCMake/CMP0081/CMP0081-WARN-result.txt
Normal file
1
Tests/RunCMake/CMP0081/CMP0081-WARN-result.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
0
|
||||||
10
Tests/RunCMake/CMP0081/CMP0081-WARN-stderr.txt
Normal file
10
Tests/RunCMake/CMP0081/CMP0081-WARN-stderr.txt
Normal 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.
|
||||||
2
Tests/RunCMake/CMP0081/CMP0081-WARN.cmake
Normal file
2
Tests/RunCMake/CMP0081/CMP0081-WARN.cmake
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
include (CMP0081-Common.cmake)
|
||||||
3
Tests/RunCMake/CMP0081/CMakeLists.txt
Normal file
3
Tests/RunCMake/CMP0081/CMakeLists.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.1)
|
||||||
|
project(${RunCMake_TEST} NONE)
|
||||||
|
include(${RunCMake_TEST}.cmake)
|
||||||
5
Tests/RunCMake/CMP0081/RunCMakeTest.cmake
Normal file
5
Tests/RunCMake/CMP0081/RunCMakeTest.cmake
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
include(RunCMake)
|
||||||
|
|
||||||
|
run_cmake(CMP0081-OLD)
|
||||||
|
run_cmake(CMP0081-NEW)
|
||||||
|
run_cmake(CMP0081-WARN)
|
||||||
7
Tests/RunCMake/CMP0081/empty.cpp
Normal file
7
Tests/RunCMake/CMP0081/empty.cpp
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#ifdef _WIN32
|
||||||
|
__declspec(dllexport)
|
||||||
|
#endif
|
||||||
|
int empty()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -106,6 +106,7 @@ if(CMAKE_SYSTEM_NAME MATCHES Darwin AND CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG)
|
|||||||
add_RunCMake_test(CMP0068)
|
add_RunCMake_test(CMP0068)
|
||||||
endif()
|
endif()
|
||||||
add_RunCMake_test(CMP0069)
|
add_RunCMake_test(CMP0069)
|
||||||
|
add_RunCMake_test(CMP0081)
|
||||||
|
|
||||||
# The test for Policy 65 requires the use of the
|
# The test for Policy 65 requires the use of the
|
||||||
# CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS variable, which both the VS and Xcode
|
# CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS variable, which both the VS and Xcode
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
\* CMP0069
|
\* CMP0069
|
||||||
\* CMP0073
|
\* CMP0073
|
||||||
\* CMP0076
|
\* CMP0076
|
||||||
|
\* CMP0081
|
||||||
|
|
||||||
Call Stack \(most recent call first\):
|
Call Stack \(most recent call first\):
|
||||||
CMakeLists.txt:3 \(include\)
|
CMakeLists.txt:3 \(include\)
|
||||||
|
|||||||
Reference in New Issue
Block a user