summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@gmail.com>2020-04-06 09:22:37 (GMT)
committerMarc Chevrier <marc.chevrier@gmail.com>2020-04-19 13:53:11 (GMT)
commit4248bb452a5886ec4b632e2d602fcaafd2b13aaf (patch)
treeb7e126570036c7a7ec0ac61ca7ef99f67edd6d18 /Source
parentec48e023f6261371aa5d0e46ebf9c163e40c9b40 (diff)
downloadCMake-4248bb452a5886ec4b632e2d602fcaafd2b13aaf.zip
CMake-4248bb452a5886ec4b632e2d602fcaafd2b13aaf.tar.gz
CMake-4248bb452a5886ec4b632e2d602fcaafd2b13aaf.tar.bz2
CUDA: Device linking use now link options
properties LINK_OPTIONS and INTERFACE_LINK_OPTIONS are propagated to the device link step. To control which options are selected for normal link and device link steps, the $<DEVICE_LINK> and $<HOST_LINK> generator expressions can be used. Fixes: #18265
Diffstat (limited to 'Source')
-rw-r--r--Source/cmGeneratorTarget.cxx214
-rw-r--r--Source/cmLocalGenerator.cxx40
-rw-r--r--Source/cmLocalGenerator.h5
-rw-r--r--Source/cmMakefileExecutableTargetGenerator.cxx26
-rw-r--r--Source/cmMakefileLibraryTargetGenerator.cxx15
-rw-r--r--Source/cmMakefileTargetGenerator.cxx12
-rw-r--r--Source/cmMakefileTargetGenerator.h2
-rw-r--r--Source/cmNinjaNormalTargetGenerator.cxx36
-rw-r--r--Source/cmPolicies.h9
-rw-r--r--Source/cmVisualStudio10TargetGenerator.cxx22
10 files changed, 243 insertions, 138 deletions
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
index 8a7f094..fd863a3 100644
--- a/Source/cmGeneratorTarget.cxx
+++ b/Source/cmGeneratorTarget.cxx
@@ -21,6 +21,8 @@
#include "cmsys/RegularExpression.hxx"
+#include "cm_static_string_view.hxx"
+
#include "cmAlgorithms.h"
#include "cmComputeLinkInformation.h"
#include "cmCustomCommand.h"
@@ -3392,22 +3394,38 @@ enum class OptionsParse
};
namespace {
+const auto DL_BEGIN = "<DEVICE_LINK>"_s;
+const auto DL_END = "</DEVICE_LINK>"_s;
+
void processOptions(cmGeneratorTarget const* tgt,
std::vector<EvaluatedTargetPropertyEntry> const& entries,
std::vector<BT<std::string>>& options,
std::unordered_set<std::string>& uniqueOptions,
- bool debugOptions, const char* logName, OptionsParse parse)
+ bool debugOptions, const char* logName, OptionsParse parse,
+ bool processDeviceOptions = false)
{
+ bool splitOption = !processDeviceOptions;
for (EvaluatedTargetPropertyEntry const& entry : entries) {
std::string usedOptions;
for (std::string const& opt : entry.Values) {
+ if (processDeviceOptions && (opt == DL_BEGIN || opt == DL_END)) {
+ options.emplace_back(opt, entry.Backtrace);
+ splitOption = opt == DL_BEGIN;
+ continue;
+ }
+
if (uniqueOptions.insert(opt).second) {
if (parse == OptionsParse::Shell &&
cmHasLiteralPrefix(opt, "SHELL:")) {
- std::vector<std::string> tmp;
- cmSystemTools::ParseUnixCommandLine(opt.c_str() + 6, tmp);
- for (std::string& o : tmp) {
- options.emplace_back(std::move(o), entry.Backtrace);
+ if (splitOption) {
+ std::vector<std::string> tmp;
+ cmSystemTools::ParseUnixCommandLine(opt.c_str() + 6, tmp);
+ for (std::string& o : tmp) {
+ options.emplace_back(std::move(o), entry.Backtrace);
+ }
+ } else {
+ options.emplace_back(std::string(opt.c_str() + 6),
+ entry.Backtrace);
}
} else {
options.emplace_back(opt, entry.Backtrace);
@@ -3426,6 +3444,63 @@ void processOptions(cmGeneratorTarget const* tgt,
}
}
}
+
+std::vector<BT<std::string>> wrapOptions(
+ std::vector<std::string>& options, const cmListFileBacktrace& bt,
+ const std::vector<std::string>& wrapperFlag, const std::string& wrapperSep,
+ bool concatFlagAndArgs)
+{
+ std::vector<BT<std::string>> result;
+
+ if (options.empty()) {
+ return result;
+ }
+
+ if (wrapperFlag.empty() || cmHasLiteralPrefix(options.front(), "LINKER:")) {
+ // nothing specified or LINKER wrapper, insert elements as is
+ result.reserve(options.size());
+ for (std::string& o : options) {
+ result.emplace_back(std::move(o), bt);
+ }
+ } else {
+ if (!wrapperSep.empty()) {
+ if (concatFlagAndArgs) {
+ // insert flag elements except last one
+ for (auto i = wrapperFlag.begin(); i != wrapperFlag.end() - 1; ++i) {
+ result.emplace_back(*i, bt);
+ }
+ // concatenate last flag element and all list values
+ // in one option
+ result.emplace_back(wrapperFlag.back() + cmJoin(options, 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);
+ }
+ } else {
+ // prefix each element of list with wrapper
+ if (concatFlagAndArgs) {
+ std::transform(options.begin(), options.end(), options.begin(),
+ [&wrapperFlag](std::string const& o) -> std::string {
+ return wrapperFlag.back() + o;
+ });
+ }
+ for (std::string& o : options) {
+ for (auto i = wrapperFlag.begin(),
+ e = concatFlagAndArgs ? wrapperFlag.end() - 1
+ : wrapperFlag.end();
+ i != e; ++i) {
+ result.emplace_back(*i, bt);
+ }
+ result.emplace_back(std::move(o), bt);
+ }
+ }
+ }
+ return result;
+}
}
void cmGeneratorTarget::GetCompileOptions(std::vector<std::string>& result,
@@ -3958,6 +4033,12 @@ void cmGeneratorTarget::GetLinkOptions(std::vector<std::string>& result,
const std::string& config,
const std::string& language) const
{
+ if (this->IsDeviceLink() &&
+ this->GetPolicyStatusCMP0105() != cmPolicies::NEW) {
+ // link options are not propagated to the device link step
+ return;
+ }
+
std::vector<BT<std::string>> tmp = this->GetLinkOptions(config, language);
result.reserve(tmp.size());
for (BT<std::string>& v : tmp) {
@@ -3997,15 +4078,65 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetLinkOptions(
this->GetPolicyStatusCMP0099() != cmPolicies::NEW);
processOptions(this, entries, result, uniqueOptions, debugOptions,
- "link options", OptionsParse::Shell);
+ "link options", OptionsParse::Shell, this->IsDeviceLink());
+
+ if (this->IsDeviceLink()) {
+ // wrap host link options
+ const std::string wrapper(this->Makefile->GetSafeDefinition(
+ "CMAKE_" + language + "_DEVICE_COMPILER_WRAPPER_FLAG"));
+ std::vector<std::string> wrapperFlag = cmExpandedList(wrapper);
+ const std::string wrapperSep(this->Makefile->GetSafeDefinition(
+ "CMAKE_" + language + "_DEVICE_COMPILER_WRAPPER_FLAG_SEP"));
+ bool concatFlagAndArgs = true;
+ if (!wrapperFlag.empty() && wrapperFlag.back() == " ") {
+ concatFlagAndArgs = false;
+ wrapperFlag.pop_back();
+ }
+
+ auto it = result.begin();
+ while (it != result.end()) {
+ if (it->Value == DL_BEGIN) {
+ // device link options, no treatment
+ it = result.erase(it);
+ it = std::find_if(it, result.end(), [](const BT<std::string>& item) {
+ return item.Value == DL_END;
+ });
+ if (it != result.end()) {
+ it = result.erase(it);
+ }
+ } else {
+ // host link options must be wrapped
+ std::vector<std::string> options;
+ cmSystemTools::ParseUnixCommandLine(it->Value.c_str(), options);
+ auto hostOptions = wrapOptions(options, it->Backtrace, wrapperFlag,
+ wrapperSep, concatFlagAndArgs);
+ it = result.erase(it);
+ // some compilers (like gcc 4.8 or Intel 19.0 or XLC 16) do not respect
+ // C++11 standard: 'std::vector::insert()' do not returns an iterator,
+ // so need to recompute the iterator after insertion.
+ if (it == result.end()) {
+ cm::append(result, hostOptions);
+ it = result.end();
+ } else {
+ auto index = it - result.begin();
+ result.insert(it, hostOptions.begin(), hostOptions.end());
+ it = result.begin() + index + hostOptions.size();
+ }
+ }
+ }
+ }
// Last step: replace "LINKER:" prefixed elements by
// actual linker wrapper
const std::string wrapper(this->Makefile->GetSafeDefinition(
- "CMAKE_" + language + "_LINKER_WRAPPER_FLAG"));
+ "CMAKE_" + language +
+ (this->IsDeviceLink() ? "_DEVICE_LINKER_WRAPPER_FLAG"
+ : "_LINKER_WRAPPER_FLAG")));
std::vector<std::string> wrapperFlag = cmExpandedList(wrapper);
const std::string wrapperSep(this->Makefile->GetSafeDefinition(
- "CMAKE_" + language + "_LINKER_WRAPPER_FLAG_SEP"));
+ "CMAKE_" + language +
+ (this->IsDeviceLink() ? "_DEVICE_LINKER_WRAPPER_FLAG_SEP"
+ : "_LINKER_WRAPPER_FLAG_SEP")));
bool concatFlagAndArgs = true;
if (!wrapperFlag.empty() && wrapperFlag.back() == " ") {
concatFlagAndArgs = false;
@@ -4051,51 +4182,8 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetLinkOptions(
return result;
}
- std::vector<BT<std::string>> options;
- if (wrapperFlag.empty()) {
- // nothing specified, insert elements as is
- options.reserve(linkerOptions.size());
- for (std::string& o : linkerOptions) {
- options.emplace_back(std::move(o), bt);
- }
- } else {
- if (!wrapperSep.empty()) {
- if (concatFlagAndArgs) {
- // insert flag elements except last one
- for (auto i = wrapperFlag.begin(); i != wrapperFlag.end() - 1; ++i) {
- options.emplace_back(*i, bt);
- }
- // concatenate last flag element and all LINKER list values
- // in one option
- options.emplace_back(
- wrapperFlag.back() + cmJoin(linkerOptions, wrapperSep), bt);
- } else {
- for (std::string const& i : wrapperFlag) {
- options.emplace_back(i, bt);
- }
- // concatenate all LINKER list values in one option
- options.emplace_back(cmJoin(linkerOptions, wrapperSep), bt);
- }
- } else {
- // prefix each element of LINKER list with wrapper
- if (concatFlagAndArgs) {
- std::transform(linkerOptions.begin(), linkerOptions.end(),
- linkerOptions.begin(),
- [&wrapperFlag](std::string const& o) -> std::string {
- return wrapperFlag.back() + o;
- });
- }
- for (std::string& o : linkerOptions) {
- for (auto i = wrapperFlag.begin(),
- e = concatFlagAndArgs ? wrapperFlag.end() - 1
- : wrapperFlag.end();
- i != e; ++i) {
- options.emplace_back(*i, bt);
- }
- options.emplace_back(std::move(o), bt);
- }
- }
- }
+ std::vector<BT<std::string>> options = wrapOptions(
+ linkerOptions, bt, wrapperFlag, wrapperSep, concatFlagAndArgs);
result.insert(entry, options.begin(), options.end());
}
return result;
@@ -4651,9 +4739,9 @@ void cmGeneratorTarget::GetFullNameInternal(
outBase += this->GetOutputName(config, artifact);
// Append the per-configuration postfix.
- // When using Xcode, the postfix should be part of the suffix rather than the
- // base, because the suffix ends up being used in Xcode's EXECUTABLE_SUFFIX
- // attribute.
+ // When using Xcode, the postfix should be part of the suffix rather than
+ // the base, because the suffix ends up being used in Xcode's
+ // EXECUTABLE_SUFFIX attribute.
if (this->IsFrameworkOnApple() &&
GetGlobalGenerator()->GetName() == "Xcode") {
targetSuffix = configPostfix.c_str();
@@ -5150,7 +5238,8 @@ void cmGeneratorTarget::CheckPropertyCompatibility(
std::ostringstream e;
e << "Property \"" << prop << "\" appears in both the " << propsString
<< " property in the dependencies of target \"" << this->GetName()
- << "\". This is not allowed. A property may only require compatibility "
+ << "\". This is not allowed. A property may only require "
+ "compatibility "
"in a boolean interpretation, a numeric minimum, a numeric maximum "
"or a "
"string interpretation, but not a mixture.";
@@ -5800,8 +5889,9 @@ void cmGeneratorTarget::ExpandLinkItems(
// Keep this logic in sync with ComputeLinkImplementationLibraries.
cmGeneratorExpression ge;
cmGeneratorExpressionDAGChecker dagChecker(this, prop, nullptr, nullptr);
- // The $<LINK_ONLY> expression may be in a link interface to specify private
- // link dependencies that are otherwise excluded from usage requirements.
+ // The $<LINK_ONLY> expression may be in a link interface to specify
+ // private link dependencies that are otherwise excluded from usage
+ // requirements.
if (usage_requirements_only) {
dagChecker.SetTransitivePropertiesOnly();
}
@@ -5899,9 +5989,9 @@ void cmGeneratorTarget::ComputeLinkInterface(
}
} else {
// TODO: Recognize shared library file names. Perhaps this
- // should be moved to cmComputeLinkInformation, but that creates
- // a chicken-and-egg problem since this list is needed for its
- // construction.
+ // should be moved to cmComputeLinkInformation, but that
+ // creates a chicken-and-egg problem since this list is needed
+ // for its construction.
}
}
}
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index e07cbb0..22e5d32 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -34,7 +34,6 @@
#include "cmInstallScriptGenerator.h"
#include "cmInstallTargetGenerator.h"
#include "cmLinkLineComputer.h"
-#include "cmLinkLineDeviceComputer.h"
#include "cmMakefile.h"
#include "cmRulePlaceholderExpander.h"
#include "cmSourceFile.h"
@@ -1423,6 +1422,30 @@ std::vector<BT<std::string>> cmLocalGenerator::GetStaticLibraryFlags(
return flags;
}
+void cmLocalGenerator::GetDeviceLinkFlags(
+ 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 cuda device link libraries when
+ // resolving cuda device symbols
+ this->OutputLinkLibraries(pcli, linkLineComputer, linkLibs, frameworkPath,
+ linkPath);
+ }
+
+ std::vector<std::string> linkOpts;
+ target->GetLinkOptions(linkOpts, config, linkLanguage);
+ // LINK_OPTIONS are escaped.
+ this->AppendCompileOptions(linkFlags, linkOpts);
+}
+
void cmLocalGenerator::GetTargetFlags(
cmLinkLineComputer* linkLineComputer, const std::string& config,
std::string& linkLibs, std::string& flags, std::string& linkFlags,
@@ -1455,12 +1478,6 @@ void cmLocalGenerator::GetTargetFlags(
switch (target->GetType()) {
case cmStateEnums::STATIC_LIBRARY:
linkFlags = this->GetStaticLibraryFlags(config, linkLanguage, target);
- if (pcli && dynamic_cast<cmLinkLineDeviceComputer*>(linkLineComputer)) {
- // Compute the required cuda device link libraries when
- // resolving cuda device symbols
- this->OutputLinkLibraries(pcli, linkLineComputer, linkLibs,
- frameworkPath, linkPath);
- }
break;
case cmStateEnums::MODULE_LIBRARY:
libraryLinkVariable = "CMAKE_MODULE_LINKER_FLAGS";
@@ -1827,10 +1844,10 @@ std::string cmLocalGenerator::GetLinkLibsCMP0065(
"CMAKE_POLICY_WARNING_CMP0065")) {
std::ostringstream w;
/* clang-format off */
- w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0065) << "\n"
- "For compatibility with older versions of CMake, "
- "additional flags may be added to export symbols on all "
- "executables regardless of their ENABLE_EXPORTS property.";
+ w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0065) << "\n"
+ "For compatibility with older versions of CMake, "
+ "additional flags may be added to export symbols on all "
+ "executables regardless of their ENABLE_EXPORTS property.";
/* clang-format on */
this->IssueMessage(MessageType::AUTHOR_WARNING, w.str());
}
@@ -2033,7 +2050,6 @@ bool cmLocalGenerator::GetRealDependency(const std::string& inName,
if (name.empty()) {
return false;
}
-
if (cmSystemTools::GetFilenameLastExtension(name) == ".exe") {
name = cmSystemTools::GetFilenameWithoutLastExtension(name);
}
diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h
index 5fb9337..baa6812 100644
--- a/Source/cmLocalGenerator.h
+++ b/Source/cmLocalGenerator.h
@@ -421,6 +421,11 @@ public:
/** Fill out these strings for the given target. Libraries to link,
* flags, and linkflags. */
+ void GetDeviceLinkFlags(cmLinkLineComputer* linkLineComputer,
+ const std::string& config, std::string& linkLibs,
+ std::string& linkFlags, std::string& frameworkPath,
+ std::string& linkPath, cmGeneratorTarget* target);
+
void GetTargetFlags(cmLinkLineComputer* linkLineComputer,
const std::string& config, std::string& linkLibs,
std::string& flags, std::string& linkFlags,
diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx
index 4fe10ad..e15b016 100644
--- a/Source/cmMakefileExecutableTargetGenerator.cxx
+++ b/Source/cmMakefileExecutableTargetGenerator.cxx
@@ -122,31 +122,15 @@ void cmMakefileExecutableTargetGenerator::WriteDeviceExecutableRule(
}
// Build a list of compiler flags and linker flags.
- std::string flags;
+ std::string langFlags;
std::string linkFlags;
- // Add flags to create an executable.
- // Add symbol export flags if necessary.
- if (this->GeneratorTarget->IsExecutableWithExports()) {
- std::string export_flag_var =
- cmStrCat("CMAKE_EXE_EXPORTS_", linkLanguage, "_FLAG");
- this->LocalGenerator->AppendFlags(
- linkFlags, this->Makefile->GetSafeDefinition(export_flag_var));
- }
-
- this->LocalGenerator->AppendFlags(linkFlags,
- this->LocalGenerator->GetLinkLibsCMP0065(
- linkLanguage, *this->GeneratorTarget));
-
// Add language feature flags.
this->LocalGenerator->AddLanguageFlagsForLinking(
- flags, this->GeneratorTarget, linkLanguage, this->GetConfigName());
-
- this->LocalGenerator->AddArchitectureFlags(
- flags, this->GeneratorTarget, linkLanguage, this->GetConfigName());
+ langFlags, this->GeneratorTarget, linkLanguage, this->GetConfigName());
- // Add target-specific linker flags.
- this->GetTargetLinkFlags(linkFlags, linkLanguage);
+ // Add device-specific linker flags.
+ this->GetDeviceLinkFlags(linkFlags, linkLanguage);
// Construct a list of files associated with this executable that
// may need to be cleaned.
@@ -226,7 +210,7 @@ void cmMakefileExecutableTargetGenerator::WriteDeviceExecutableRule(
vars.ObjectDir = objectDir.c_str();
vars.Target = target.c_str();
vars.LinkLibraries = linkLibs.c_str();
- vars.Flags = flags.c_str();
+ vars.LanguageCompileFlags = langFlags.c_str();
vars.LinkFlags = linkFlags.c_str();
vars.TargetCompilePDB = targetOutPathCompilePDB.c_str();
diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx
index 372b43b..2d360e6 100644
--- a/Source/cmMakefileLibraryTargetGenerator.cxx
+++ b/Source/cmMakefileLibraryTargetGenerator.cxx
@@ -249,9 +249,14 @@ void cmMakefileLibraryTargetGenerator::WriteDeviceLibraryRules(
std::vector<std::string> depends;
this->AppendLinkDepends(depends, linkLanguage);
+ // Add language-specific flags.
+ std::string langFlags;
+ this->LocalGenerator->AddLanguageFlagsForLinking(
+ langFlags, this->GeneratorTarget, linkLanguage, this->GetConfigName());
+
// Create set of linking flags.
std::string linkFlags;
- this->GetTargetLinkFlags(linkFlags, linkLanguage);
+ this->GetDeviceLinkFlags(linkFlags, linkLanguage);
// Get the name of the device object to generate.
std::string const targetOutputReal =
@@ -344,16 +349,10 @@ void cmMakefileLibraryTargetGenerator::WriteDeviceLibraryRules(
vars.Target = target.c_str();
vars.LinkLibraries = linkLibs.c_str();
vars.ObjectsQuoted = buildObjs.c_str();
+ vars.LanguageCompileFlags = langFlags.c_str();
vars.LinkFlags = linkFlags.c_str();
vars.TargetCompilePDB = targetOutPathCompilePDB.c_str();
- // Add language-specific flags.
- std::string langFlags;
- this->LocalGenerator->AddLanguageFlagsForLinking(
- langFlags, this->GeneratorTarget, linkLanguage, this->GetConfigName());
-
- vars.LanguageCompileFlags = langFlags.c_str();
-
std::string launcher;
const char* val = this->LocalGenerator->GetRuleLauncher(
this->GeneratorTarget, "RULE_LAUNCH_LINK");
diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx
index ee87044..b21946c 100644
--- a/Source/cmMakefileTargetGenerator.cxx
+++ b/Source/cmMakefileTargetGenerator.cxx
@@ -87,6 +87,18 @@ std::string cmMakefileTargetGenerator::GetConfigName()
return configNames.front();
}
+void cmMakefileTargetGenerator::GetDeviceLinkFlags(
+ std::string& linkFlags, const std::string& linkLanguage)
+{
+ cmGeneratorTarget::DeviceLinkSetter setter(*this->GetGeneratorTarget());
+
+ std::vector<std::string> linkOpts;
+ this->GeneratorTarget->GetLinkOptions(linkOpts, this->GetConfigName(),
+ linkLanguage);
+ // LINK_OPTIONS are escaped.
+ this->LocalGenerator->AppendCompileOptions(linkFlags, linkOpts);
+}
+
void cmMakefileTargetGenerator::GetTargetLinkFlags(
std::string& flags, const std::string& linkLanguage)
{
diff --git a/Source/cmMakefileTargetGenerator.h b/Source/cmMakefileTargetGenerator.h
index ec6b314..f38f862 100644
--- a/Source/cmMakefileTargetGenerator.h
+++ b/Source/cmMakefileTargetGenerator.h
@@ -60,6 +60,8 @@ public:
std::string GetConfigName();
protected:
+ void GetDeviceLinkFlags(std::string& linkFlags,
+ const std::string& linkLanguage);
void GetTargetLinkFlags(std::string& flags, const std::string& linkLanguage);
// create the file and directory etc
diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx
index 9c4ff83..49e8af9 100644
--- a/Source/cmNinjaNormalTargetGenerator.cxx
+++ b/Source/cmNinjaNormalTargetGenerator.cxx
@@ -233,11 +233,7 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkRule(
vars.LinkFlags = "$LINK_FLAGS";
vars.Manifests = "$MANIFESTS";
- std::string langFlags;
- if (this->GetGeneratorTarget()->GetType() != cmStateEnums::EXECUTABLE) {
- langFlags += "$LANGUAGE_COMPILE_FLAGS $ARCH_FLAGS";
- vars.LanguageCompileFlags = langFlags.c_str();
- }
+ vars.LanguageCompileFlags = "$LANGUAGE_COMPILE_FLAGS";
std::string launcher;
const char* val = this->GetLocalGenerator()->GetRuleLauncher(
@@ -590,8 +586,6 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement(
return;
}
- // Now we can do device linking
-
// First and very important step is to make sure while inside this
// step our link language is set to CUDA
std::string cudaLinkLanguage = "CUDA";
@@ -677,9 +671,9 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement(
linkLineComputer->SetUseWatcomQuote(useWatcomQuote);
linkLineComputer->SetUseNinjaMulti(globalGen->IsMultiConfig());
- localGen.GetTargetFlags(
- linkLineComputer.get(), config, vars["LINK_LIBRARIES"], vars["FLAGS"],
- vars["LINK_FLAGS"], frameworkPath, linkPath, genTarget);
+ localGen.GetDeviceLinkFlags(linkLineComputer.get(), config,
+ vars["LINK_LIBRARIES"], vars["LINK_FLAGS"],
+ frameworkPath, linkPath, genTarget);
this->addPoolNinjaVariable("JOB_POOL_LINK", genTarget, vars);
@@ -689,22 +683,12 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement(
vars["LINK_PATH"] = frameworkPath + linkPath;
- // Compute architecture specific link flags. Yes, these go into a different
- // variable for executables, probably due to a mistake made when duplicating
- // code between the Makefile executable and library generators.
- if (targetType == cmStateEnums::EXECUTABLE) {
- std::string t = vars["FLAGS"];
- localGen.AddArchitectureFlags(t, genTarget, cudaLinkLanguage, config);
- vars["FLAGS"] = t;
- } else {
- std::string t = vars["ARCH_FLAGS"];
- localGen.AddArchitectureFlags(t, genTarget, cudaLinkLanguage, config);
- vars["ARCH_FLAGS"] = t;
- t.clear();
- localGen.AddLanguageFlagsForLinking(t, genTarget, cudaLinkLanguage,
- config);
- vars["LANGUAGE_COMPILE_FLAGS"] = t;
- }
+ // Compute language specific link flags.
+ std::string langFlags;
+ localGen.AddLanguageFlagsForLinking(langFlags, genTarget, cudaLinkLanguage,
+ config);
+ vars["LANGUAGE_COMPILE_FLAGS"] = langFlags;
+
auto const tgtNames = this->TargetNames(config);
if (genTarget->HasSOName(config)) {
vars["SONAME_FLAG"] =
diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h
index 0eb42bf..cdf3f71 100644
--- a/Source/cmPolicies.h
+++ b/Source/cmPolicies.h
@@ -307,12 +307,14 @@ class cmMakefile;
"mark_as_advanced() does nothing if a cache entry does not exist.", \
3, 17, 0, cmPolicies::WARN) \
SELECT(POLICY, CMP0103, \
- "multiple export() with same FILE without APPEND is not allowed.", \
+ "Multiple export() with same FILE without APPEND is not allowed.", \
3, 18, 0, cmPolicies::WARN) \
SELECT(POLICY, CMP0104, \
"CMAKE_CUDA_ARCHITECTURES now detected for NVCC, empty " \
"CUDA_ARCHITECTURES not allowed.", \
- 3, 18, 0, cmPolicies::WARN)
+ 3, 18, 0, cmPolicies::WARN) \
+ SELECT(POLICY, CMP0105, "Device link step uses the link options.", 3, 18, \
+ 0, cmPolicies::WARN)
#define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
#define CM_FOR_EACH_POLICY_ID(POLICY) \
@@ -343,7 +345,8 @@ class cmMakefile;
F(CMP0083) \
F(CMP0095) \
F(CMP0099) \
- F(CMP0104)
+ F(CMP0104) \
+ F(CMP0105)
/** \class cmPolicies
* \brief Handles changes in CMake behavior and policies
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx
index e01e090..930db41 100644
--- a/Source/cmVisualStudio10TargetGenerator.cxx
+++ b/Source/cmVisualStudio10TargetGenerator.cxx
@@ -3184,6 +3184,8 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions(
this->LocalGenerator, Options::CudaCompiler, gg->GetCudaFlagTable());
Options& cudaLinkOptions = *pOptions;
+ cmGeneratorTarget::DeviceLinkSetter setter(*this->GeneratorTarget);
+
// Determine if we need to do a device link
const bool doDeviceLinking = requireDeviceLinking(
*this->GeneratorTarget, *this->LocalGenerator, configName);
@@ -3191,12 +3193,20 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions(
cudaLinkOptions.AddFlag("PerformDeviceLink",
doDeviceLinking ? "true" : "false");
- // Suppress deprecation warnings for default GPU targets during device link.
- if (cmSystemTools::VersionCompareGreaterEq(
- this->GlobalGenerator->GetPlatformToolsetCudaString(), "8.0")) {
- cudaLinkOptions.AppendFlagString("AdditionalOptions",
- "-Wno-deprecated-gpu-targets");
- }
+ // Add extra flags for device linking
+ cudaLinkOptions.AppendFlagString(
+ "AdditionalOptions",
+ this->Makefile->GetSafeDefinition("_CMAKE_CUDA_EXTRA_FLAGS"));
+ cudaLinkOptions.AppendFlagString(
+ "AdditionalOptions",
+ this->Makefile->GetSafeDefinition("_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS"));
+
+ std::vector<std::string> linkOpts;
+ std::string linkFlags;
+ this->GeneratorTarget->GetLinkOptions(linkOpts, configName, "CUDA");
+ // LINK_OPTIONS are escaped.
+ this->LocalGenerator->AppendCompileOptions(linkFlags, linkOpts);
+ cudaLinkOptions.AppendFlagString("AdditionalOptions", linkFlags);
// For static libraries that have device linking enabled compute
// the libraries