From 5b0693411ef53349f192140b855ec1cdc148f3b9 Mon Sep 17 00:00:00 2001 From: Raul Tambre Date: Sat, 6 Nov 2021 13:06:27 +0200 Subject: CUDA: Ignore USE_WATCOM_QUOTE for device link rules It's useless as the Watcom compiler isn't supported by NVCC. --- Source/cmMakefileExecutableTargetGenerator.cxx | 12 +++--------- Source/cmMakefileLibraryTargetGenerator.cxx | 13 +++---------- Source/cmNinjaNormalTargetGenerator.cxx | 3 --- 3 files changed, 6 insertions(+), 22 deletions(-) diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx index 575fb05..e41ed8c 100644 --- a/Source/cmMakefileExecutableTargetGenerator.cxx +++ b/Source/cmMakefileExecutableTargetGenerator.cxx @@ -170,9 +170,6 @@ void cmMakefileExecutableTargetGenerator::WriteNvidiaDeviceExecutableRule( // Expand the rule variables. { - bool useWatcomQuote = - this->Makefile->IsOn(linkRuleVar + "_USE_WATCOM_QUOTE"); - // Set path conversion for link script shells. this->LocalGenerator->SetLinkScriptShell(useLinkScript); @@ -181,7 +178,6 @@ void cmMakefileExecutableTargetGenerator::WriteNvidiaDeviceExecutableRule( this->LocalGenerator, this->LocalGenerator->GetStateSnapshot().GetDirectory())); linkLineComputer->SetForResponse(useResponseFileForLibs); - linkLineComputer->SetUseWatcomQuote(useWatcomQuote); linkLineComputer->SetRelink(relink); // Collect up flags to link in needed libraries. @@ -193,7 +189,7 @@ void cmMakefileExecutableTargetGenerator::WriteNvidiaDeviceExecutableRule( // rule. std::string buildObjs; this->CreateObjectLists(useLinkScript, false, useResponseFileForObjects, - buildObjs, depends, useWatcomQuote); + buildObjs, depends, false); std::string const& aixExports = this->GetAIXExports(this->GetConfigName()); @@ -204,11 +200,9 @@ void cmMakefileExecutableTargetGenerator::WriteNvidiaDeviceExecutableRule( this->LocalGenerator->MaybeRelativeToCurBinDir(objectDir), cmOutputConverter::SHELL); - cmOutputConverter::OutputFormat output = (useWatcomQuote) - ? cmOutputConverter::WATCOMQUOTE - : cmOutputConverter::SHELL; std::string target = this->LocalGenerator->ConvertToOutputFormat( - this->LocalGenerator->MaybeRelativeToCurBinDir(targetOutput), output); + this->LocalGenerator->MaybeRelativeToCurBinDir(targetOutput), + cmOutputConverter::SHELL); std::string targetFullPathCompilePDB = this->ComputeTargetCompilePDB(this->GetConfigName()); diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx index ace73a7..66031db 100644 --- a/Source/cmMakefileLibraryTargetGenerator.cxx +++ b/Source/cmMakefileLibraryTargetGenerator.cxx @@ -308,9 +308,6 @@ void cmMakefileLibraryTargetGenerator::WriteNvidiaDeviceLibraryRules( // Expand the rule variables. std::vector real_link_commands; { - bool useWatcomQuote = - this->Makefile->IsOn(linkRuleVar + "_USE_WATCOM_QUOTE"); - // Set path conversion for link script shells. this->LocalGenerator->SetLinkScriptShell(useLinkScript); @@ -321,7 +318,6 @@ void cmMakefileLibraryTargetGenerator::WriteNvidiaDeviceLibraryRules( this->LocalGenerator, this->LocalGenerator->GetStateSnapshot().GetDirectory())); linkLineComputer->SetForResponse(useResponseFileForLibs); - linkLineComputer->SetUseWatcomQuote(useWatcomQuote); linkLineComputer->SetRelink(relink); this->CreateLinkLibs(linkLineComputer.get(), linkLibs, @@ -332,11 +328,7 @@ void cmMakefileLibraryTargetGenerator::WriteNvidiaDeviceLibraryRules( std::string buildObjs; this->CreateObjectLists(useLinkScript, false, // useArchiveRules useResponseFileForObjects, buildObjs, depends, - useWatcomQuote); - - cmOutputConverter::OutputFormat output = (useWatcomQuote) - ? cmOutputConverter::WATCOMQUOTE - : cmOutputConverter::SHELL; + false); std::string objectDir = this->GeneratorTarget->GetSupportDirectory(); objectDir = this->LocalGenerator->ConvertToOutputFormat( @@ -344,7 +336,8 @@ void cmMakefileLibraryTargetGenerator::WriteNvidiaDeviceLibraryRules( cmOutputConverter::SHELL); std::string target = this->LocalGenerator->ConvertToOutputFormat( - this->LocalGenerator->MaybeRelativeToCurBinDir(targetOutput), output); + this->LocalGenerator->MaybeRelativeToCurBinDir(targetOutput), + cmOutputConverter::SHELL); std::string targetFullPathCompilePDB = this->ComputeTargetCompilePDB(this->GetConfigName()); diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 517d529..325692e 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -850,8 +850,6 @@ void cmNinjaNormalTargetGenerator::WriteNvidiaDeviceLinkStatement( std::string createRule = genTarget->GetCreateRuleVariable(this->TargetLinkLanguage(config), config); - const bool useWatcomQuote = - this->GetMakefile()->IsOn(createRule + "_USE_WATCOM_QUOTE"); cmLocalNinjaGenerator& localGen = *this->GetLocalGenerator(); vars["TARGET_FILE"] = @@ -862,7 +860,6 @@ void cmNinjaNormalTargetGenerator::WriteNvidiaDeviceLinkStatement( this->GetLocalGenerator(), this->GetLocalGenerator()->GetStateSnapshot().GetDirectory(), globalGen)); - linkLineComputer->SetUseWatcomQuote(useWatcomQuote); linkLineComputer->SetUseNinjaMulti(globalGen->IsMultiConfig()); localGen.GetDeviceLinkFlags(linkLineComputer.get(), config, -- cgit v0.12 From cf7e68087d005051ec07cb21c2aed2963a3d5c4e Mon Sep 17 00:00:00 2001 From: Raul Tambre Date: Sat, 6 Nov 2021 13:35:04 +0200 Subject: CUDA: Avoid unnecessary allocation and GetLinkLanguage() There's no reason to allocate the cmNinjaLinkLineDeviceComputer on the heap. We can also assume the link language as CUDA in cmLocalGenerator::GetDeviceLinkFlags(). --- Source/cmLocalGenerator.cxx | 8 +++----- Source/cmLocalGenerator.h | 2 +- Source/cmNinjaNormalTargetGenerator.cxx | 18 ++++++++---------- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 3a4c386..970e30b 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1410,25 +1410,23 @@ std::vector> cmLocalGenerator::GetStaticLibraryFlags( } void cmLocalGenerator::GetDeviceLinkFlags( - cmLinkLineComputer* linkLineComputer, const std::string& config, + cmLinkLineComputer& linkLineComputer, const std::string& config, std::string& linkLibs, std::string& linkFlags, std::string& frameworkPath, std::string& linkPath, cmGeneratorTarget* target) { cmGeneratorTarget::DeviceLinkSetter setter(*target); cmComputeLinkInformation* pcli = target->GetLinkInformation(config); - const std::string linkLanguage = - linkLineComputer->GetLinkerLanguage(target, config); if (pcli) { // Compute the required device link libraries when // resolving gpu lang device symbols - this->OutputLinkLibraries(pcli, linkLineComputer, linkLibs, frameworkPath, + this->OutputLinkLibraries(pcli, &linkLineComputer, linkLibs, frameworkPath, linkPath); } std::vector linkOpts; - target->GetLinkOptions(linkOpts, config, linkLanguage); + target->GetLinkOptions(linkOpts, config, "CUDA"); // LINK_OPTIONS are escaped. this->AppendCompileOptions(linkFlags, linkOpts); } diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 3614c84..b86c8e8 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -496,7 +496,7 @@ public: /** Fill out these strings for the given target. Libraries to link, * flags, and linkflags. */ - void GetDeviceLinkFlags(cmLinkLineComputer* linkLineComputer, + void GetDeviceLinkFlags(cmLinkLineComputer& linkLineComputer, const std::string& config, std::string& linkLibs, std::string& linkFlags, std::string& frameworkPath, std::string& linkPath, cmGeneratorTarget* target); diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 325692e..228df7f 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -855,16 +855,14 @@ void cmNinjaNormalTargetGenerator::WriteNvidiaDeviceLinkStatement( vars["TARGET_FILE"] = localGen.ConvertToOutputFormat(output, cmOutputConverter::SHELL); - std::unique_ptr linkLineComputer( - new cmNinjaLinkLineDeviceComputer( - this->GetLocalGenerator(), - this->GetLocalGenerator()->GetStateSnapshot().GetDirectory(), - globalGen)); - linkLineComputer->SetUseNinjaMulti(globalGen->IsMultiConfig()); - - localGen.GetDeviceLinkFlags(linkLineComputer.get(), config, - vars["LINK_LIBRARIES"], vars["LINK_FLAGS"], - frameworkPath, linkPath, genTarget); + cmNinjaLinkLineDeviceComputer linkLineComputer( + this->GetLocalGenerator(), + this->GetLocalGenerator()->GetStateSnapshot().GetDirectory(), globalGen); + linkLineComputer.SetUseNinjaMulti(globalGen->IsMultiConfig()); + + localGen.GetDeviceLinkFlags(linkLineComputer, config, vars["LINK_LIBRARIES"], + vars["LINK_FLAGS"], frameworkPath, linkPath, + genTarget); this->addPoolNinjaVariable("JOB_POOL_LINK", genTarget, vars); -- cgit v0.12 From 15fde4c420e0fa469077fad020b9fdc071796f70 Mon Sep 17 00:00:00 2001 From: Raul Tambre Date: Sat, 6 Nov 2021 13:19:51 +0200 Subject: CUDA: Use local shorthands for variables in Clang device link code Helps reduce wrapping of lines making code more readable. --- Source/cmMakefileTargetGenerator.cxx | 26 ++++++++++++-------------- Source/cmNinjaNormalTargetGenerator.cxx | 22 ++++++++++------------ 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index 4e5913e..67beaad 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -1530,9 +1530,9 @@ void cmMakefileTargetGenerator::WriteDeviceLinkRule( return; } + cmLocalUnixMakefileGenerator3* localGen{ this->LocalGenerator }; std::vector architectures = cmExpandedList(architecturesStr); - std::string const& relPath = - this->LocalGenerator->GetHomeRelativeOutputPath(); + std::string const& relPath = localGen->GetHomeRelativeOutputPath(); // Ensure there are no duplicates. const std::vector linkDeps = [&]() -> std::vector { @@ -1552,12 +1552,12 @@ void cmMakefileTargetGenerator::WriteDeviceLinkRule( const std::string objectDir = this->GeneratorTarget->ObjectDirectory; const std::string relObjectDir = - this->LocalGenerator->MaybeRelativeToCurBinDir(objectDir); + localGen->MaybeRelativeToCurBinDir(objectDir); // Construct a list of files associated with this executable that // may need to be cleaned. std::vector cleanFiles; - cleanFiles.push_back(this->LocalGenerator->MaybeRelativeToCurBinDir(output)); + cleanFiles.push_back(localGen->MaybeRelativeToCurBinDir(output)); std::string profiles; std::vector fatbinaryDepends; @@ -1594,8 +1594,8 @@ void cmMakefileTargetGenerator::WriteDeviceLinkRule( " -arch=sm_", architecture, registerFileCmd, " -o=$@ ", cmJoin(linkDeps, " ")); - this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, nullptr, cubin, - linkDeps, { command }, false); + localGen->WriteMakeRule(*this->BuildFileStream, nullptr, cubin, linkDeps, + { command }, false); } // Combine all architectures into a single fatbinary. @@ -1609,9 +1609,8 @@ void cmMakefileTargetGenerator::WriteDeviceLinkRule( const std::string fatbinaryOutputRel = cmStrCat(relPath, relObjectDir, "cmake_cuda_fatbin.h"); - this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, nullptr, - fatbinaryOutputRel, fatbinaryDepends, - { fatbinaryCommand }, false); + localGen->WriteMakeRule(*this->BuildFileStream, nullptr, fatbinaryOutputRel, + fatbinaryDepends, { fatbinaryCommand }, false); // Compile the stub that registers the kernels and contains the // fatbinaries. @@ -1630,13 +1629,12 @@ void cmMakefileTargetGenerator::WriteDeviceLinkRule( std::string compileCmd = this->GetLinkRule("CMAKE_CUDA_DEVICE_LINK_COMPILE"); std::unique_ptr rulePlaceholderExpander( - this->LocalGenerator->CreateRulePlaceholderExpander()); - rulePlaceholderExpander->ExpandRuleVariables(this->LocalGenerator, - compileCmd, vars); + localGen->CreateRulePlaceholderExpander()); + rulePlaceholderExpander->ExpandRuleVariables(localGen, compileCmd, vars); commands.emplace_back(compileCmd); - this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, nullptr, output, - { fatbinaryOutputRel }, commands, false); + localGen->WriteMakeRule(*this->BuildFileStream, nullptr, output, + { fatbinaryOutputRel }, commands, false); // Clean all the possible executable names and symlinks. this->CleanFiles.insert(cleanFiles.begin(), cleanFiles.end()); diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 228df7f..01efcd0 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -744,9 +744,10 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatements( return deps; }(); + cmGlobalNinjaGenerator* globalGen{ this->GetGlobalGenerator() }; const std::string objectDir = cmStrCat(this->GeneratorTarget->GetSupportDirectory(), - this->GetGlobalGenerator()->ConfigDirectory(config)); + globalGen->ConfigDirectory(config)); const std::string ninjaOutputDir = this->ConvertToNinjaPath(objectDir); cmNinjaBuild fatbinary(this->LanguageLinkerCudaFatbinaryRule(config)); @@ -777,26 +778,23 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatements( cmStrCat(" -im=profile=sm_", architecture, ",file=", cubin); fatbinary.ExplicitDeps.emplace_back(cubin); - this->GetGlobalGenerator()->WriteBuild(this->GetCommonFileStream(), dlink); + globalGen->WriteBuild(this->GetCommonFileStream(), dlink); } // Combine all architectures into a single fatbinary. fatbinary.Outputs = { cmStrCat(ninjaOutputDir, "/cmake_cuda_fatbin.h") }; - this->GetGlobalGenerator()->WriteBuild(this->GetCommonFileStream(), - fatbinary); + globalGen->WriteBuild(this->GetCommonFileStream(), fatbinary); // Compile the stub that registers the kernels and contains the fatbinaries. + cmLocalNinjaGenerator* localGen{ this->GetLocalGenerator() }; cmNinjaBuild dcompile(this->LanguageLinkerCudaDeviceCompileRule(config)); dcompile.Outputs = { output }; dcompile.ExplicitDeps = { cmStrCat(ninjaOutputDir, "/cmake_cuda_fatbin.h") }; - dcompile.Variables["FATBIN"] = - this->GetLocalGenerator()->ConvertToOutputFormat( - cmStrCat(objectDir, "/cmake_cuda_fatbin.h"), cmOutputConverter::SHELL); - dcompile.Variables["REGISTER"] = - this->GetLocalGenerator()->ConvertToOutputFormat( - cmStrCat(objectDir, "/cmake_cuda_register.h"), cmOutputConverter::SHELL); - this->GetGlobalGenerator()->WriteBuild(this->GetCommonFileStream(), - dcompile); + dcompile.Variables["FATBIN"] = localGen->ConvertToOutputFormat( + cmStrCat(objectDir, "/cmake_cuda_fatbin.h"), cmOutputConverter::SHELL); + dcompile.Variables["REGISTER"] = localGen->ConvertToOutputFormat( + cmStrCat(objectDir, "/cmake_cuda_register.h"), cmOutputConverter::SHELL); + globalGen->WriteBuild(this->GetCommonFileStream(), dcompile); } void cmNinjaNormalTargetGenerator::WriteNvidiaDeviceLinkStatement( -- cgit v0.12 From 4707ecbe6fed1e135785f9fe9734a4c66807dd77 Mon Sep 17 00:00:00 2001 From: Raul Tambre Date: Sat, 6 Nov 2021 12:54:07 +0200 Subject: CUDA: Support CMP0105 on Clang Add link flags during the "device compile" step. Enabled the relevant tests. The disable reasons regarding separable compilation were outdated and the actual failure case was device link flags support. --- Help/release/dev/cuda-clang-device-link-flags.rst | 7 ++++ Modules/CMakeCUDAInformation.cmake | 2 +- Modules/Compiler/Clang-CUDA.cmake | 4 +++ Source/cmMakefileTargetGenerator.cxx | 4 +++ Source/cmNinjaNormalTargetGenerator.cxx | 15 +++++++++ Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake | 2 +- .../target_link_options/RunCMakeTest.cmake | 17 ++++------ ...genex_DEVICE_LINK-host_link_options-check.cmake | 9 +++-- .../target_link_options/genex_DEVICE_LINK.cmake | 39 +++++++++++----------- 9 files changed, 66 insertions(+), 33 deletions(-) create mode 100644 Help/release/dev/cuda-clang-device-link-flags.rst diff --git a/Help/release/dev/cuda-clang-device-link-flags.rst b/Help/release/dev/cuda-clang-device-link-flags.rst new file mode 100644 index 0000000..2f4f16e --- /dev/null +++ b/Help/release/dev/cuda-clang-device-link-flags.rst @@ -0,0 +1,7 @@ +cuda-clang-device-link-flags +---------------------------- + +* Policy :policy:`CMP0105` and the ``$`` and + ``$`` + :manual:`generator expressions ` + are now supported for Clang. diff --git a/Modules/CMakeCUDAInformation.cmake b/Modules/CMakeCUDAInformation.cmake index 94b67dc..dea721e 100644 --- a/Modules/CMakeCUDAInformation.cmake +++ b/Modules/CMakeCUDAInformation.cmake @@ -198,7 +198,7 @@ endif() # Used when device linking is handled by CMake. if(NOT CMAKE_CUDA_DEVICE_LINK_COMPILE) - set(CMAKE_CUDA_DEVICE_LINK_COMPILE " ${_CMAKE_CUDA_EXTRA_FLAGS} -D__CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ -D__NV_EXTRA_INITIALIZATION=\"\" -D__NV_EXTRA_FINALIZATION=\"\" -DREGISTERLINKBINARYFILE=\\\"\\\" -DFATBINFILE=\\\"\\\" ${_CMAKE_COMPILE_AS_CUDA_FLAG} -c \"${CMAKE_CUDA_COMPILER_TOOLKIT_LIBRARY_ROOT}/bin/crt/link.stub\" -o ") + set(CMAKE_CUDA_DEVICE_LINK_COMPILE " ${_CMAKE_CUDA_EXTRA_FLAGS} -D__CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ -D__NV_EXTRA_INITIALIZATION=\"\" -D__NV_EXTRA_FINALIZATION=\"\" -DREGISTERLINKBINARYFILE=\\\"\\\" -DFATBINFILE=\\\"\\\" ${_CMAKE_COMPILE_AS_CUDA_FLAG} -c \"${CMAKE_CUDA_COMPILER_TOOLKIT_LIBRARY_ROOT}/bin/crt/link.stub\" -o ") endif() unset(__IMPLICIT_DLINK_FLAGS) diff --git a/Modules/Compiler/Clang-CUDA.cmake b/Modules/Compiler/Clang-CUDA.cmake index b105518..219897e 100644 --- a/Modules/Compiler/Clang-CUDA.cmake +++ b/Modules/Compiler/Clang-CUDA.cmake @@ -22,6 +22,10 @@ set(_CMAKE_CUDA_WHOLE_FLAG "-c") set(_CMAKE_CUDA_RDC_FLAG "-fgpu-rdc") set(_CMAKE_CUDA_PTX_FLAG "--cuda-device-only -S") +# Device linking is just regular linking so these are the same. +set(CMAKE_CUDA_DEVICE_LINKER_WRAPPER_FLAG ${CMAKE_CUDA_LINKER_WRAPPER_FLAG}) +set(CMAKE_CUDA_DEVICE_LINKER_WRAPPER_FLAG_SEP ${CMAKE_CUDA_LINKER_WRAPPER_FLAG_SEP}) + # RulePlaceholderExpander expands crosscompile variables like sysroot and target only for CMAKE__COMPILER. Override the default. set(CMAKE_CUDA_LINK_EXECUTABLE " -o ${__IMPLICIT_LINKS}") set(CMAKE_CUDA_CREATE_SHARED_LIBRARY " -o ${__IMPLICIT_LINKS}") diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index 67beaad..8230848 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -1624,6 +1624,10 @@ void cmMakefileTargetGenerator::WriteDeviceLinkRule( vars.Fatbinary = fatbinaryOutput.c_str(); vars.RegisterFile = registerFile.c_str(); + std::string linkFlags; + this->GetDeviceLinkFlags(linkFlags, "CUDA"); + vars.LinkFlags = linkFlags.c_str(); + std::string flags = this->GetFlags("CUDA", this->GetConfigName()); vars.Flags = flags.c_str(); diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 01efcd0..1c5bac8 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -326,6 +326,7 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkRules( vars.Object = "$out"; vars.Fatbinary = "$FATBIN"; vars.RegisterFile = "$REGISTER"; + vars.LinkFlags = "$LINK_FLAGS"; std::string flags = this->GetFlags("CUDA", config); vars.Flags = flags.c_str(); @@ -794,6 +795,20 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatements( cmStrCat(objectDir, "/cmake_cuda_fatbin.h"), cmOutputConverter::SHELL); dcompile.Variables["REGISTER"] = localGen->ConvertToOutputFormat( cmStrCat(objectDir, "/cmake_cuda_register.h"), cmOutputConverter::SHELL); + + cmNinjaLinkLineDeviceComputer linkLineComputer( + localGen, localGen->GetStateSnapshot().GetDirectory(), globalGen); + linkLineComputer.SetUseNinjaMulti(globalGen->IsMultiConfig()); + + // Link libraries and paths are only used during the final executable/library + // link. + std::string frameworkPath; + std::string linkPath; + std::string linkLibs; + localGen->GetDeviceLinkFlags(linkLineComputer, config, linkLibs, + dcompile.Variables["LINK_FLAGS"], frameworkPath, + linkPath, this->GetGeneratorTarget()); + globalGen->WriteBuild(this->GetCommonFileStream(), dcompile); } diff --git a/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake b/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake index 4a0c130..919015f 100644 --- a/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake +++ b/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake @@ -448,7 +448,7 @@ run_cmake_command(NoUnusedVariables ${CMAKE_COMMAND} ${CMAKE_CURRENT_LIST_DIR} ) # CudaSimple uses separable compilation, which is currently only supported on NVCC. -if(CMake_TEST_CUDA AND NOT CMake_TEST_CUDA STREQUAL "Clang") +if(CMake_TEST_CUDA) set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/CudaSimple-build) run_cmake_configure(CudaSimple) include(${RunCMake_TEST_BINARY_DIR}/target_files.cmake) diff --git a/Tests/RunCMake/target_link_options/RunCMakeTest.cmake b/Tests/RunCMake/target_link_options/RunCMakeTest.cmake index a707383..1a29ecf 100644 --- a/Tests/RunCMake/target_link_options/RunCMakeTest.cmake +++ b/Tests/RunCMake/target_link_options/RunCMakeTest.cmake @@ -53,16 +53,13 @@ if (NOT CMAKE_C_COMPILER_ID STREQUAL "Intel") run_cmake_target(genex_DEVICE_LINK interface LinkOptions_shared_interface --config Release) run_cmake_target(genex_DEVICE_LINK private LinkOptions_private --config Release) if (CMake_TEST_CUDA) - # Separable compilation is only supported on NVCC. - if(NOT CMake_TEST_CUDA STREQUAL "Clang") - run_cmake_target(genex_DEVICE_LINK CMP0105_UNSET LinkOptions_CMP0105_UNSET --config Release) - 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() + run_cmake_target(genex_DEVICE_LINK CMP0105_UNSET LinkOptions_CMP0105_UNSET --config Release) + 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() run_cmake_target(genex_DEVICE_LINK no_device LinkOptions_no_device --config Release) diff --git a/Tests/RunCMake/target_link_options/genex_DEVICE_LINK-host_link_options-check.cmake b/Tests/RunCMake/target_link_options/genex_DEVICE_LINK-host_link_options-check.cmake index 31ffe7f..cc3088a 100644 --- a/Tests/RunCMake/target_link_options/genex_DEVICE_LINK-host_link_options-check.cmake +++ b/Tests/RunCMake/target_link_options/genex_DEVICE_LINK-host_link_options-check.cmake @@ -1,4 +1,9 @@ +if(CMake_TEST_CUDA STREQUAL "NVIDIA") + set(expected "-Xlinker=OPT1 -Xlinker=OPT2 -Xlinker=OPT3 -Xlinker=OPT4 -Xlinker=OPT5") +elseif(CMake_TEST_CUDA STREQUAL "Clang") + set(expected "-Wl,OPT1 -Xlinker OPT2 -Xlinker OPT3 -Xlinker OPT4") +endif() -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'.") +if(NOT actual_stdout MATCHES "${expected}") + set(RunCMake_TEST_FAILED "Not found expected '${expected}'") endif() diff --git a/Tests/RunCMake/target_link_options/genex_DEVICE_LINK.cmake b/Tests/RunCMake/target_link_options/genex_DEVICE_LINK.cmake index a53ab20..b6c9ee6 100644 --- a/Tests/RunCMake/target_link_options/genex_DEVICE_LINK.cmake +++ b/Tests/RunCMake/target_link_options/genex_DEVICE_LINK.cmake @@ -25,32 +25,33 @@ target_link_options (LinkOptions_private PRIVATE $) + add_executable(LinkOptions_CMP0105_UNSET LinkOptionsDevice.cu) + set_property(TARGET LinkOptions_CMP0105_UNSET PROPERTY CUDA_SEPARABLE_COMPILATION ON) + target_link_options(LinkOptions_CMP0105_UNSET PRIVATE $) - cmake_policy(SET CMP0105 OLD) + cmake_policy(SET CMP0105 OLD) - add_executable(LinkOptions_CMP0105_OLD LinkOptionsDevice.cu) - set_property(TARGET LinkOptions_CMP0105_OLD PROPERTY CUDA_SEPARABLE_COMPILATION ON) - target_link_options(LinkOptions_CMP0105_OLD PRIVATE $) + add_executable(LinkOptions_CMP0105_OLD LinkOptionsDevice.cu) + set_property(TARGET LinkOptions_CMP0105_OLD PROPERTY CUDA_SEPARABLE_COMPILATION ON) + target_link_options(LinkOptions_CMP0105_OLD PRIVATE $) - cmake_policy(SET CMP0105 NEW) + cmake_policy(SET CMP0105 NEW) - add_executable(LinkOptions_CMP0105_NEW LinkOptionsDevice.cu) - set_property(TARGET LinkOptions_CMP0105_NEW PROPERTY CUDA_SEPARABLE_COMPILATION ON) - target_link_options(LinkOptions_CMP0105_NEW PRIVATE $) + add_executable(LinkOptions_CMP0105_NEW LinkOptionsDevice.cu) + set_property(TARGET LinkOptions_CMP0105_NEW PROPERTY CUDA_SEPARABLE_COMPILATION ON) + target_link_options(LinkOptions_CMP0105_NEW PRIVATE $) - add_executable(LinkOptions_device LinkOptionsDevice.cu) - set_property(TARGET LinkOptions_device PROPERTY CUDA_SEPARABLE_COMPILATION ON) - target_link_options(LinkOptions_device PRIVATE $ - $) + add_executable(LinkOptions_device LinkOptionsDevice.cu) + set_property(TARGET LinkOptions_device PROPERTY CUDA_SEPARABLE_COMPILATION ON) + target_link_options(LinkOptions_device PRIVATE $ + $) - add_executable(LinkOptions_host_link_options LinkOptionsDevice.cu) - set_property(TARGET LinkOptions_host_link_options PROPERTY CUDA_SEPARABLE_COMPILATION ON) + add_executable(LinkOptions_host_link_options LinkOptionsDevice.cu) + set_property(TARGET LinkOptions_host_link_options PROPERTY CUDA_SEPARABLE_COMPILATION ON) + if(CMake_TEST_CUDA STREQUAL "NVIDIA") target_link_options(LinkOptions_host_link_options PRIVATE -Wl,OPT1 -Xlinker=OPT2 "SHELL:-Xlinker OPT3" "SHELL:LINKER:OPT4 LINKER:OPT5") + elseif(CMake_TEST_CUDA STREQUAL "Clang") + target_link_options(LinkOptions_host_link_options PRIVATE -Wl,OPT1 "SHELL:-Xlinker OPT2" "SHELL:LINKER:OPT3 LINKER:OPT4") endif() add_executable(LinkOptions_no_device LinkOptionsDevice.cu) -- cgit v0.12