diff options
author | Brad King <brad.king@kitware.com> | 2024-09-25 12:58:00 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2024-09-25 12:58:26 (GMT) |
commit | 506255b1f1ba2b7a7d4babce4b86d30238977d87 (patch) | |
tree | 8a1980362f3ea4d24b896021903da1aba2f9e44a /Tests | |
parent | 57480c767647601d6a1c541667d781838f56d8ae (diff) | |
parent | e3895f4a8bcce3d9caae7d0e5559e6f057725fad (diff) | |
download | CMake-506255b1f1ba2b7a7d4babce4b86d30238977d87.zip CMake-506255b1f1ba2b7a7d4babce4b86d30238977d87.tar.gz CMake-506255b1f1ba2b7a7d4babce4b86d30238977d87.tar.bz2 |
Merge topic 'nested_linker_prefixes'
e3895f4a8b Linking: Preserve nested LINKER: prefixes as written
4185dfbe1b Tests/LINK_OPTIONS: extract common code in test (NFC)
54381b5a81 Linking: extract wrapping linker options to a lambda (NFC)
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !9823
Diffstat (limited to 'Tests')
7 files changed, 46 insertions, 18 deletions
diff --git a/Tests/RunCMake/target_link_options/LINKER_expansion-LINKER-check.cmake b/Tests/RunCMake/target_link_options/LINKER_expansion-LINKER-check.cmake index d0ef8de..99f5aa3 100644 --- a/Tests/RunCMake/target_link_options/LINKER_expansion-LINKER-check.cmake +++ b/Tests/RunCMake/target_link_options/LINKER_expansion-LINKER-check.cmake @@ -1,2 +1,3 @@ +set(reference_file "LINKER.txt") include ("${CMAKE_CURRENT_LIST_DIR}/LINKER_expansion-validation.cmake") diff --git a/Tests/RunCMake/target_link_options/LINKER_expansion-LINKER_NESTED-check.cmake b/Tests/RunCMake/target_link_options/LINKER_expansion-LINKER_NESTED-check.cmake new file mode 100644 index 0000000..522fe86 --- /dev/null +++ b/Tests/RunCMake/target_link_options/LINKER_expansion-LINKER_NESTED-check.cmake @@ -0,0 +1,4 @@ + +set(reference_file "LINKER_NESTED.txt") +set(linker_prefix_expected YES) +include ("${CMAKE_CURRENT_LIST_DIR}/LINKER_expansion-validation.cmake") diff --git a/Tests/RunCMake/target_link_options/LINKER_expansion-LINKER_NESTED_SHELL-check.cmake b/Tests/RunCMake/target_link_options/LINKER_expansion-LINKER_NESTED_SHELL-check.cmake new file mode 100644 index 0000000..917455c --- /dev/null +++ b/Tests/RunCMake/target_link_options/LINKER_expansion-LINKER_NESTED_SHELL-check.cmake @@ -0,0 +1,4 @@ + +set(reference_file "LINKER_NESTED_SHELL.txt") +set(linker_prefix_expected YES) +include ("${CMAKE_CURRENT_LIST_DIR}/LINKER_expansion-validation.cmake") diff --git a/Tests/RunCMake/target_link_options/LINKER_expansion-LINKER_SHELL-check.cmake b/Tests/RunCMake/target_link_options/LINKER_expansion-LINKER_SHELL-check.cmake index d0ef8de..99f5aa3 100644 --- a/Tests/RunCMake/target_link_options/LINKER_expansion-LINKER_SHELL-check.cmake +++ b/Tests/RunCMake/target_link_options/LINKER_expansion-LINKER_SHELL-check.cmake @@ -1,2 +1,3 @@ +set(reference_file "LINKER.txt") include ("${CMAKE_CURRENT_LIST_DIR}/LINKER_expansion-validation.cmake") diff --git a/Tests/RunCMake/target_link_options/LINKER_expansion-validation.cmake b/Tests/RunCMake/target_link_options/LINKER_expansion-validation.cmake index 1af8f13..27adde6 100644 --- a/Tests/RunCMake/target_link_options/LINKER_expansion-validation.cmake +++ b/Tests/RunCMake/target_link_options/LINKER_expansion-validation.cmake @@ -1,14 +1,14 @@ -if (actual_stdout MATCHES "LINKER:") +if (actual_stdout MATCHES "LINKER:" AND NOT linker_prefix_expected) set (RunCMake_TEST_FAILED "LINKER: prefix was not expanded.") return() endif() -if (NOT EXISTS "${RunCMake_TEST_BINARY_DIR}/LINKER.txt") - set (RunCMake_TEST_FAILED "${RunCMake_TEST_BINARY_DIR}/LINKER.txt: Reference file not found.") +if (NOT EXISTS "${RunCMake_TEST_BINARY_DIR}/${reference_file}") + set (RunCMake_TEST_FAILED "${RunCMake_TEST_BINARY_DIR}/${reference_file}: Reference file not found.") return() endif() -file(READ "${RunCMake_TEST_BINARY_DIR}/LINKER.txt" linker_flag) +file(READ "${RunCMake_TEST_BINARY_DIR}/${reference_file}" linker_flag) if (NOT actual_stdout MATCHES "${linker_flag}") set (RunCMake_TEST_FAILED "LINKER: was not expanded correctly.") diff --git a/Tests/RunCMake/target_link_options/LINKER_expansion.cmake b/Tests/RunCMake/target_link_options/LINKER_expansion.cmake index f86d19f..2219218 100644 --- a/Tests/RunCMake/target_link_options/LINKER_expansion.cmake +++ b/Tests/RunCMake/target_link_options/LINKER_expansion.cmake @@ -14,26 +14,30 @@ add_executable(dump dump.c) string(REPLACE "${CMAKE_START_TEMP_FILE}" "" CMAKE_C_CREATE_SHARED_LIBRARY "${CMAKE_C_CREATE_SHARED_LIBRARY}") string(REPLACE "${CMAKE_END_TEMP_FILE}" "" CMAKE_C_CREATE_SHARED_LIBRARY "${CMAKE_C_CREATE_SHARED_LIBRARY}") +function (add_test_library target_name) + add_library(${target_name} SHARED LinkOptionsLib.c) -# Use LINKER alone -add_library(linker SHARED LinkOptionsLib.c) -target_link_options(linker PRIVATE "LINKER:-foo,bar") + # use LAUNCH facility to dump linker command + set_property(TARGET ${target_name} PROPERTY RULE_LAUNCH_LINK "\"${DUMP_EXE}\"") -# use LAUNCH facility to dump linker command -set_property(TARGET linker PROPERTY RULE_LAUNCH_LINK "\"${DUMP_EXE}\"") - -add_dependencies (linker dump) + add_dependencies(${target_name} dump) +endfunction() +# Use LINKER alone +add_test_library(linker) +target_link_options(linker PRIVATE "LINKER:-foo,bar") # Use LINKER with SHELL -add_library(linker_shell SHARED LinkOptionsLib.c) +add_test_library(linker_shell) target_link_options(linker_shell PRIVATE "LINKER:SHELL:-foo bar") -# use LAUNCH facility to dump linker command -set_property(TARGET linker_shell PROPERTY RULE_LAUNCH_LINK "\"${DUMP_EXE}\"") - -add_dependencies (linker_shell dump) +# Nested LINKER: prefixes should be preserved as written, only the outermost LINKER: prefix removed +add_test_library(linker_nested) +target_link_options(linker_nested PRIVATE "LINKER:LINKER:-foo,-Xlinker=bar,-Xlinker,--baz,-Wl,/qux") +# Same with LINKER:SHELL: +add_test_library(linker_nested_shell SHARED LinkOptionsLib.c) +target_link_options(linker_nested_shell PRIVATE "LINKER:SHELL:LINKER:-foo -Xlinker=bar -Xlinker --baz -Wl,/qux") # generate reference for LINKER flag if (CMAKE_C_LINKER_WRAPPER_FLAG) @@ -46,11 +50,23 @@ if (CMAKE_C_LINKER_WRAPPER_FLAG) endif() list (JOIN linker_flag " " linker_flag) if (CMAKE_C_LINKER_WRAPPER_FLAG_SEP) - string (APPEND linker_flag "${linker_space}" "-foo${CMAKE_C_LINKER_WRAPPER_FLAG_SEP}bar") + set(linker_sep "${CMAKE_C_LINKER_WRAPPER_FLAG_SEP}") + + set(linker_flag_nested "${linker_flag}${linker_space}LINKER:-foo${linker_sep}-Xlinker=bar${linker_sep}-Xlinker${linker_sep}--baz${linker_sep}-Wl${linker_sep}/qux") + set(linker_flag_nested_shell "${linker_flag}${linker_space}LINKER:-foo${linker_sep}-Xlinker=bar${linker_sep}-Xlinker${linker_sep}--baz${linker_sep}-Wl,/qux") + string (APPEND linker_flag "${linker_space}" "-foo${linker_sep}bar") else() - set (linker_flag "${linker_flag}${linker_space}-foo ${linker_flag}${linker_space}bar") + set(linker_prefix "${linker_flag}${linker_space}") + + set(linker_flag_nested "${linker_prefix}LINKER:-foo ${linker_prefix}-Xlinker=bar ${linker_prefix}-Xlinker ${linker_prefix}--baz ${linker_prefix}-Wl ${linker_prefix}/qux") + set(linker_flag_nested_shell "${linker_prefix}LINKER:-foo ${linker_prefix}-Xlinker=bar ${linker_prefix}-Xlinker ${linker_prefix}--baz ${linker_prefix}-Wl,/qux") + set (linker_flag "${linker_prefix}-foo ${linker_prefix}bar") endif() else() + set(linker_flag_nested "LINKER:-foo -Xlinker=bar -Xlinker --baz -Wl /qux") + set(linker_flag_nested_shell "LINKER:-foo -Xlinker=bar -Xlinker --baz -Wl,/qux") set(linker_flag "-foo bar") endif() file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/LINKER.txt" "${linker_flag}") +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/LINKER_NESTED.txt" "${linker_flag_nested}") +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/LINKER_NESTED_SHELL.txt" "${linker_flag_nested_shell}") diff --git a/Tests/RunCMake/target_link_options/RunCMakeTest.cmake b/Tests/RunCMake/target_link_options/RunCMakeTest.cmake index ff0c5a8..5562c9e 100644 --- a/Tests/RunCMake/target_link_options/RunCMakeTest.cmake +++ b/Tests/RunCMake/target_link_options/RunCMakeTest.cmake @@ -76,6 +76,8 @@ if(RunCMake_GENERATOR MATCHES "(Ninja|Makefile)") run_cmake_target(LINKER_expansion LINKER linker) run_cmake_target(LINKER_expansion LINKER_SHELL linker_shell) + run_cmake_target(LINKER_expansion LINKER_NESTED linker_nested) + run_cmake_target(LINKER_expansion LINKER_NESTED_SHELL linker_nested_shell) endif() run_cmake(empty_keyword_args) |