mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-22 06:59:01 -06:00
Merge topic 'CUDA-device-link'
bb96984ec9 CUDA Device link: Ensure all link options are correctly formatted
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5962
This commit is contained in:
@@ -3655,13 +3655,58 @@ std::vector<BT<std::string>> wrapOptions(
|
||||
return result;
|
||||
}
|
||||
|
||||
if (wrapperFlag.empty() || cmHasLiteralPrefix(options.front(), "LINKER:")) {
|
||||
// nothing specified or LINKER wrapper, insert elements as is
|
||||
if (wrapperFlag.empty()) {
|
||||
// nothing specified, insert elements as is
|
||||
result.reserve(options.size());
|
||||
for (std::string& o : options) {
|
||||
result.emplace_back(std::move(o), bt);
|
||||
}
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
|
||||
for (std::vector<std::string>::size_type index = 0; index < options.size();
|
||||
index++) {
|
||||
if (cmHasLiteralPrefix(options[index], "LINKER:")) {
|
||||
// LINKER wrapper specified, insert elements as is
|
||||
result.emplace_back(std::move(options[index]), bt);
|
||||
continue;
|
||||
}
|
||||
if (cmHasLiteralPrefix(options[index], "-Wl,")) {
|
||||
// replace option by LINKER wrapper
|
||||
result.emplace_back(options[index].replace(0, 4, "LINKER:"), bt);
|
||||
continue;
|
||||
}
|
||||
if (cmHasLiteralPrefix(options[index], "-Xlinker=")) {
|
||||
// replace option by LINKER wrapper
|
||||
result.emplace_back(options[index].replace(0, 9, "LINKER:"), bt);
|
||||
continue;
|
||||
}
|
||||
if (options[index] == "-Xlinker") {
|
||||
// replace option by LINKER wrapper
|
||||
if (index + 1 < options.size()) {
|
||||
result.emplace_back("LINKER:" + options[++index], bt);
|
||||
} else {
|
||||
result.emplace_back(std::move(options[index]), bt);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// collect all options which must be transformed
|
||||
std::vector<std::string> opts;
|
||||
while (index < options.size()) {
|
||||
if (!cmHasLiteralPrefix(options[index], "LINKER:") &&
|
||||
!cmHasLiteralPrefix(options[index], "-Wl,") &&
|
||||
!cmHasLiteralPrefix(options[index], "-Xlinker")) {
|
||||
opts.emplace_back(std::move(options[index++]));
|
||||
} else {
|
||||
--index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (opts.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!wrapperSep.empty()) {
|
||||
if (concatFlagAndArgs) {
|
||||
// insert flag elements except last one
|
||||
@@ -3670,24 +3715,23 @@ std::vector<BT<std::string>> wrapOptions(
|
||||
}
|
||||
// concatenate last flag element and all list values
|
||||
// in one option
|
||||
result.emplace_back(wrapperFlag.back() + cmJoin(options, wrapperSep),
|
||||
bt);
|
||||
result.emplace_back(wrapperFlag.back() + cmJoin(opts, wrapperSep), bt);
|
||||
} else {
|
||||
for (std::string const& i : wrapperFlag) {
|
||||
result.emplace_back(i, bt);
|
||||
}
|
||||
// concatenate all list values in one option
|
||||
result.emplace_back(cmJoin(options, wrapperSep), bt);
|
||||
result.emplace_back(cmJoin(opts, wrapperSep), bt);
|
||||
}
|
||||
} else {
|
||||
// prefix each element of list with wrapper
|
||||
if (concatFlagAndArgs) {
|
||||
std::transform(options.begin(), options.end(), options.begin(),
|
||||
std::transform(opts.begin(), opts.end(), opts.begin(),
|
||||
[&wrapperFlag](std::string const& o) -> std::string {
|
||||
return wrapperFlag.back() + o;
|
||||
});
|
||||
}
|
||||
for (std::string& o : options) {
|
||||
for (std::string& o : opts) {
|
||||
for (auto i = wrapperFlag.begin(),
|
||||
e = concatFlagAndArgs ? wrapperFlag.end() - 1
|
||||
: wrapperFlag.end();
|
||||
|
||||
@@ -17,6 +17,9 @@ if (NOT CMAKE_C_COMPILER_ID STREQUAL "Intel")
|
||||
if (NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
|
||||
list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Release)
|
||||
endif()
|
||||
if (RunCMake_GENERATOR MATCHES "Ninja")
|
||||
set(VERBOSE -- -v)
|
||||
endif()
|
||||
|
||||
run_cmake(LINK_OPTIONS)
|
||||
|
||||
@@ -56,6 +59,10 @@ if (NOT CMAKE_C_COMPILER_ID STREQUAL "Intel")
|
||||
run_cmake_target(genex_DEVICE_LINK CMP0105_OLD LinkOptions_CMP0105_OLD --config Release)
|
||||
run_cmake_target(genex_DEVICE_LINK CMP0105_NEW LinkOptions_CMP0105_NEW --config Release)
|
||||
run_cmake_target(genex_DEVICE_LINK device LinkOptions_device --config Release)
|
||||
|
||||
if (RunCMake_GENERATOR MATCHES "(Ninja|Unix Makefiles)")
|
||||
run_cmake_target(genex_DEVICE_LINK host_link_options LinkOptions_host_link_options --config Release ${VERBOSE})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
run_cmake_target(genex_DEVICE_LINK no_device LinkOptions_no_device --config Release)
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
if (NOT actual_stdout MATCHES "-Xlinker=OPT1 -Xlinker=OPT2 -Xlinker=OPT3 -Xlinker=OPT4 -Xlinker=OPT5")
|
||||
set (RunCMake_TEST_FAILED "Not found expected '-Xlinker=OPT1 -Xlinker=OPT2 -Xlinker=OPT3 -Xlinker=OPT4 -Xlinker=OPT5'.")
|
||||
endif()
|
||||
@@ -0,0 +1 @@
|
||||
.*
|
||||
@@ -1,6 +1,10 @@
|
||||
|
||||
enable_language(C)
|
||||
|
||||
set(CMAKE_VERBOSE_MAKEFILE TRUE)
|
||||
set(CMAKE_C_USE_RESPONSE_FILE_FOR_LIBRARIES FALSE)
|
||||
set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_LIBRARIES FALSE)
|
||||
|
||||
set (obj "${CMAKE_C_OUTPUT_EXTENSION}")
|
||||
if(BORLAND)
|
||||
set(pre -)
|
||||
@@ -43,6 +47,10 @@ if (CMake_TEST_CUDA)
|
||||
set_property(TARGET LinkOptions_device PROPERTY CUDA_SEPARABLE_COMPILATION ON)
|
||||
target_link_options(LinkOptions_device PRIVATE $<DEVICE_LINK:${pre}BADFLAG_DEVICE_LINK${obj}>
|
||||
$<HOST_LINK:${pre}BADFLAG_NORMAL_LINK${obj}>)
|
||||
|
||||
add_executable(LinkOptions_host_link_options LinkOptionsDevice.cu)
|
||||
set_property(TARGET LinkOptions_host_link_options PROPERTY CUDA_SEPARABLE_COMPILATION ON)
|
||||
target_link_options(LinkOptions_host_link_options PRIVATE -Wl,OPT1 -Xlinker=OPT2 "SHELL:-Xlinker OPT3" "SHELL:LINKER:OPT4 LINKER:OPT5")
|
||||
endif()
|
||||
|
||||
add_executable(LinkOptions_no_device LinkOptionsDevice.cu)
|
||||
|
||||
Reference in New Issue
Block a user