From c7ac13e8ed471497e672578816570535440e5815 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Mon, 6 Jan 2020 11:03:16 -0500 Subject: CUDA: Mult-Config Ninja generator now supports CUDA --- Source/cmNinjaNormalTargetGenerator.cxx | 45 ++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 7 deletions(-) (limited to 'Source/cmNinjaNormalTargetGenerator.cxx') diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 517241ee48..f853ac510c 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -83,15 +83,15 @@ void cmNinjaNormalTargetGenerator::Generate(const std::string& config) if (this->GetGeneratorTarget()->GetType() == cmStateEnums::OBJECT_LIBRARY) { this->WriteObjectLibStatement(config); } else { - // If this target has cuda language link inputs, and we need to do - // device linking - this->WriteDeviceLinkStatement(config); firstForConfig = true; for (auto const& fileConfig : this->GetConfigNames()) { if (fileConfig != config && !this->GetGlobalGenerator()->EnableCrossConfigBuild()) { continue; } + // If this target has cuda language link inputs, and we need to do + // device linking + this->WriteDeviceLinkStatement(config, fileConfig, firstForConfig); this->WriteLinkStatement(config, fileConfig, firstForConfig); firstForConfig = false; } @@ -561,7 +561,8 @@ std::vector cmNinjaNormalTargetGenerator::ComputeLinkCmd( } void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement( - const std::string& config) + const std::string& config, const std::string& fileConfig, + bool firstForConfig) { cmGlobalNinjaGenerator* globalGen = this->GetGlobalGenerator(); if (!globalGen->GetLanguageEnabled("CUDA")) { @@ -584,12 +585,42 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement( std::string const& objExt = this->Makefile->GetSafeDefinition("CMAKE_CUDA_OUTPUT_EXTENSION"); - std::string const targetOutputReal = ConvertToNinjaPath( - genTarget->ObjectDirectory + "cmake_device_link" + objExt); + std::string targetOutputDir = + cmStrCat(this->GetLocalGenerator()->GetTargetDirectory(genTarget), + globalGen->ConfigDirectory(config), "/"); + targetOutputDir = globalGen->ExpandCFGIntDir(targetOutputDir, config); - std::string const targetOutputImplib = ConvertToNinjaPath( + std::string targetOutputReal = + ConvertToNinjaPath(targetOutputDir + "cmake_device_link" + objExt); + + std::string targetOutputImplib = ConvertToNinjaPath( genTarget->GetFullPath(config, cmStateEnums::ImportLibraryArtifact)); + if (config != fileConfig) { + std::string targetOutputFileConfigDir = + cmStrCat(this->GetLocalGenerator()->GetTargetDirectory(genTarget), + globalGen->ConfigDirectory(fileConfig), "/"); + targetOutputFileConfigDir = + globalGen->ExpandCFGIntDir(targetOutputDir, fileConfig); + if (targetOutputDir == targetOutputFileConfigDir) { + return; + } + + if (!genTarget->GetFullName(config, cmStateEnums::ImportLibraryArtifact) + .empty() && + !genTarget + ->GetFullName(fileConfig, cmStateEnums::ImportLibraryArtifact) + .empty() && + targetOutputImplib == + ConvertToNinjaPath(genTarget->GetFullPath( + fileConfig, cmStateEnums::ImportLibraryArtifact))) { + return; + } + } + + if (firstForConfig) { + globalGen->GetByproductsForCleanTarget(config).push_back(targetOutputReal); + } this->DeviceLinkObject = targetOutputReal; // Write comments. -- cgit v1.2.1