summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorRobert Maynard <rmaynard@nvidia.com>2023-09-22 15:13:25 (GMT)
committerRobert Maynard <rmaynard@nvidia.com>2023-09-22 15:54:12 (GMT)
commitaa8facefe8a451918f9be143c2adc1fffe162c4a (patch)
treeac3ef511a3fb92f548a2ed174ef1f3d24d1cb64a /Source
parentf83790af0b0bdc7c409c2fb5d2e88d8c9c177684 (diff)
downloadCMake-aa8facefe8a451918f9be143c2adc1fffe162c4a.zip
CMake-aa8facefe8a451918f9be143c2adc1fffe162c4a.tar.gz
CMake-aa8facefe8a451918f9be143c2adc1fffe162c4a.tar.bz2
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 `<Object>` 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.
Diffstat (limited to 'Source')
-rw-r--r--Source/cmVisualStudio10TargetGenerator.cxx47
1 files 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<BT<std::string>> btLibVec;
- computer.ComputeLinkLibraries(cli, std::string{}, btLibVec);
+ if (doDeviceLinking) {
std::vector<std::string> 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<BT<std::string>> 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);