summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-02-15 21:53:15 (GMT)
committerBrad King <brad.king@kitware.com>2022-02-15 22:38:33 (GMT)
commitc1e812ad4ff3f175dfc7c0de52b56dbaff9d3d16 (patch)
tree5840bdb54a151b2135e45d8b4f441fcdc06ae90b /Tests
parent5571a316489ff71e4139e967464a7ad97574fce2 (diff)
downloadCMake-c1e812ad4ff3f175dfc7c0de52b56dbaff9d3d16.zip
CMake-c1e812ad4ff3f175dfc7c0de52b56dbaff9d3d16.tar.gz
CMake-c1e812ad4ff3f175dfc7c0de52b56dbaff9d3d16.tar.bz2
target_link_libraries: Improve tolerance of unquoted generator expressions
Prior to commit 1d709ea2f5 (cmGeneratorTarget: Propagate backtraces from INTERFACE_LINK_LIBRARIES, 2021-12-15, v3.23.0-rc1~228^2), the value of `INTERFACE_LINK_LIBRARIES` was a single string. If an unquoted generator expression passed to `target_link_libraries` contained `;` and became multiple arguments, they would all accumulate as a single `;`-separated list in the value of `INTERFACE_LINK_LIBRARIES`. Since that commit, each argument to `target_link_libraries` is placed in `INTERFACE_LINK_LIBRARIES` as a separate entry, as has long been the case for `LINK_LIBRARIES`. That behavior change broke projects that were accidentally relying on accumulation in `INTERFACE_LINK_LIBRARIES` to produce complete generator expressions containing `;`. Teach `target_link_libraries` to accumulate consecutive non-keyword arguments into a single entry before placing them in `LINK_LIBRARIES` or `INTERFACE_LINK_LIBRARIES`. For example, treat `a b c` as if they were written as `"a;b;c"`. This restores the previously accidental support for unquoted generator expressions in `INTERFACE_LINK_LIBRARIES`, and also enables it for `LINK_LIBRARIES`. For now, do not drop the `target_link_libraries` documentation that recommends quoting generator expressions. Quoting is still important to populate `LINK_LIBRARIES` in CMake 3.22 and below, and is also good practice to keep generator expressions whole. Fixes: #23203
Diffstat (limited to 'Tests')
-rw-r--r--Tests/CMakeCommands/target_link_libraries/cmp0022/CMakeLists.txt10
1 files changed, 10 insertions, 0 deletions
diff --git a/Tests/CMakeCommands/target_link_libraries/cmp0022/CMakeLists.txt b/Tests/CMakeCommands/target_link_libraries/cmp0022/CMakeLists.txt
index 83103cf..ca6309b 100644
--- a/Tests/CMakeCommands/target_link_libraries/cmp0022/CMakeLists.txt
+++ b/Tests/CMakeCommands/target_link_libraries/cmp0022/CMakeLists.txt
@@ -1,3 +1,4 @@
+cmake_policy(SET CMP0028 NEW)
include(GenerateExportHeader)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
@@ -17,6 +18,15 @@ assert_property(cmp0022ifacelib INTERFACE_LINK_LIBRARIES "")
add_executable(cmp0022exe cmp0022exe.cpp)
target_link_libraries(cmp0022exe cmp0022lib)
+# Test adding unquoted genex with ';' to LINK_LIBRARIES and INTERFACE_LINK_LIBRARIES.
+target_link_libraries(cmp0022lib
+ PUBLIC $<0:imp::missing1;imp::missing2>
+ PRIVATE $<0:imp::missing3;imp::missing4>
+ INTERFACE $<0:imp::missing5;imp::missing6>
+ )
+assert_property(cmp0022lib INTERFACE_LINK_LIBRARIES "cmp0022ifacelib;$<0:imp::missing1;imp::missing2>;$<0:imp::missing5;imp::missing6>")
+assert_property(cmp0022lib LINK_LIBRARIES "cmp0022ifacelib;$<0:imp::missing1;imp::missing2>;$<0:imp::missing3;imp::missing4>")
+
add_library(staticlib1 STATIC staticlib1.cpp)
generate_export_header(staticlib1)
add_library(staticlib2 STATIC staticlib2.cpp)