From aa8facefe8a451918f9be143c2adc1fffe162c4a Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Fri, 22 Sep 2023 11:13:25 -0400 Subject: CUDA: Visual Studio propagate objects to device linking When given objects via `target_link_libraries(consumer PRIVATE producer)` the VisualStudio solution adds the objects under as `` entries in the solution. This works for host side linking but isn't handled by the cuda msbuild extensions. So to work around this we manually add the objects as additional link items. --- Source/cmVisualStudio10TargetGenerator.cxx | 47 +++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index ea4bd06..2a54a55 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -3864,22 +3864,41 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions( } cudaLinkOptions.AppendFlagString("AdditionalOptions", linkFlags); - // For static libraries that have device linking enabled compute - // the libraries - if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY && - doDeviceLinking) { - cmComputeLinkInformation& cli = *pcli; - cmLinkLineDeviceComputer computer( - this->LocalGenerator, - this->LocalGenerator->GetStateSnapshot().GetDirectory()); - std::vector> btLibVec; - computer.ComputeLinkLibraries(cli, std::string{}, btLibVec); + if (doDeviceLinking) { std::vector libVec; - for (auto const& item : btLibVec) { - libVec.emplace_back(item.Value); + auto const& kinded = this->GeneratorTarget->GetKindedSources(configName); + // CMake conversion uses full paths when possible to allow deeper trees. + // However, CUDA 8.0 msbuild rules fail on absolute paths so for CUDA + // we must use relative paths. + const bool forceRelative = true; + for (cmGeneratorTarget::SourceAndKind const& si : kinded.Sources) { + switch (si.Kind) { + case cmGeneratorTarget::SourceKindExternalObject: { + std::string path = + this->ConvertPath(si.Source.Value->GetFullPath(), forceRelative); + ConvertToWindowsSlash(path); + libVec.emplace_back(std::move(path)); + } break; + default: + break; + } + } + // For static libraries that have device linking enabled compute + // the libraries + if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY) { + cmComputeLinkInformation& cli = *pcli; + cmLinkLineDeviceComputer computer( + this->LocalGenerator, + this->LocalGenerator->GetStateSnapshot().GetDirectory()); + std::vector> btLibVec; + computer.ComputeLinkLibraries(cli, std::string{}, btLibVec); + for (auto const& item : btLibVec) { + libVec.emplace_back(item.Value); + } + } + if (!libVec.empty()) { + cudaLinkOptions.AddFlag("AdditionalDependencies", libVec); } - - cudaLinkOptions.AddFlag("AdditionalDependencies", libVec); } this->CudaLinkOptions[configName] = std::move(pOptions); -- cgit v0.12