summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorRobert Maynard <robert.maynard@kitware.com>2019-11-29 18:51:32 (GMT)
committerRobert Maynard <robert.maynard@kitware.com>2020-01-27 21:02:26 (GMT)
commit0d0145138fe7cd60edc7f0b97e860e9a4fae1555 (patch)
treec013d23f71ec3e8b0e1ccbb632d3cbb0a560d91d /Source
parent4dbc9dfc7a1458878a26e1f0cec1a382e14bf48a (diff)
downloadCMake-0d0145138fe7cd60edc7f0b97e860e9a4fae1555.zip
CMake-0d0145138fe7cd60edc7f0b97e860e9a4fae1555.tar.gz
CMake-0d0145138fe7cd60edc7f0b97e860e9a4fae1555.tar.bz2
CUDA: Add abstraction for cuda runtime selection
Fixes #17559 Replace our hard-coded default of cudart=static with a first-class abstraction to select the runtime library from an enumeration of logical names.
Diffstat (limited to 'Source')
-rw-r--r--Source/cmComputeLinkInformation.cxx43
-rw-r--r--Source/cmComputeLinkInformation.h1
-rw-r--r--Source/cmTarget.cxx1
-rw-r--r--Source/cmVisualStudio10TargetGenerator.cxx13
-rw-r--r--Source/cmVisualStudioGeneratorOptions.cxx38
-rw-r--r--Source/cmVisualStudioGeneratorOptions.h10
6 files changed, 72 insertions, 34 deletions
diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx
index 8773d10..f9f5b72 100644
--- a/Source/cmComputeLinkInformation.cxx
+++ b/Source/cmComputeLinkInformation.cxx
@@ -10,6 +10,7 @@
#include "cmAlgorithms.h"
#include "cmComputeLinkDepends.h"
+#include "cmGeneratorExpression.h"
#include "cmGeneratorTarget.h"
#include "cmGlobalGenerator.h"
#include "cmListFileCache.h"
@@ -573,6 +574,15 @@ void cmComputeLinkInformation::AddImplicitLinkInfo()
cmGeneratorTarget::LinkClosure const* lc =
this->Target->GetLinkClosure(this->Config);
for (std::string const& li : lc->Languages) {
+
+ if (li == "CUDA") {
+ // These need to go before the other implicit link information
+ // as they could require symbols from those other library
+ // Currently restricted to CUDA as it is the only language
+ // we have documented runtime behavior controls for
+ this->AddRuntimeLinkLibrary(li);
+ }
+
// Skip those of the linker language. They are implicit.
if (li != this->LinkLanguage) {
this->AddImplicitLinkInfo(li);
@@ -580,6 +590,39 @@ void cmComputeLinkInformation::AddImplicitLinkInfo()
}
}
+void cmComputeLinkInformation::AddRuntimeLinkLibrary(std::string const& lang)
+{ // Add the lang runtime library flags. This is activated by the presence
+ // of a default selection whether or not it is overridden by a property.
+ std::string defaultVar =
+ cmStrCat("CMAKE_", lang, "_RUNTIME_LIBRARY_DEFAULT");
+ const char* langRuntimeLibraryDefault =
+ this->Makefile->GetDefinition(defaultVar);
+ if (langRuntimeLibraryDefault && *langRuntimeLibraryDefault) {
+ const char* runtimeLibraryValue =
+ this->Target->GetProperty(cmStrCat(lang, "_RUNTIME_LIBRARY"));
+ if (!runtimeLibraryValue) {
+ runtimeLibraryValue = langRuntimeLibraryDefault;
+ }
+
+ std::string runtimeLibrary =
+ cmSystemTools::UpperCase(cmGeneratorExpression::Evaluate(
+ runtimeLibraryValue, this->Target->GetLocalGenerator(), this->Config,
+ this->Target));
+ if (!runtimeLibrary.empty()) {
+ if (const char* runtimeLinkOptions = this->Makefile->GetDefinition(
+ "CMAKE_" + lang + "_RUNTIME_LIBRARY_LINK_OPTIONS_" +
+ runtimeLibrary)) {
+ std::vector<std::string> libsVec = cmExpandedList(runtimeLinkOptions);
+ for (std::string const& i : libsVec) {
+ if (!cmContains(this->ImplicitLinkLibs, i)) {
+ this->AddItem(i, nullptr);
+ }
+ }
+ }
+ }
+ }
+}
+
void cmComputeLinkInformation::AddImplicitLinkInfo(std::string const& lang)
{
// Add libraries for this language that are not implied by the
diff --git a/Source/cmComputeLinkInformation.h b/Source/cmComputeLinkInformation.h
index 92ab83b..46f6705 100644
--- a/Source/cmComputeLinkInformation.h
+++ b/Source/cmComputeLinkInformation.h
@@ -172,6 +172,7 @@ private:
void LoadImplicitLinkInfo();
void AddImplicitLinkInfo();
void AddImplicitLinkInfo(std::string const& lang);
+ void AddRuntimeLinkLibrary(std::string const& lang);
std::set<std::string> ImplicitLinkDirs;
std::set<std::string> ImplicitLinkLibs;
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index a0b3138..8f0a8e0 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -358,6 +358,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
initProp("CUDA_COMPILER_LAUNCHER");
initProp("CUDA_SEPARABLE_COMPILATION");
initProp("CUDA_RESOLVE_DEVICE_SYMBOLS");
+ initProp("CUDA_RUNTIME_LIBRARY");
initProp("LINK_SEARCH_START_STATIC");
initProp("LINK_SEARCH_END_STATIC");
initProp("Swift_LANGUAGE_VERSION");
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx
index f707bb4..2a09910 100644
--- a/Source/cmVisualStudio10TargetGenerator.cxx
+++ b/Source/cmVisualStudio10TargetGenerator.cxx
@@ -3636,18 +3636,7 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions(
this->AddLibraries(cli, libVec, vsTargetVec, config);
if (cmContains(linkClosure->Languages, "CUDA") &&
this->CudaOptions[config] != nullptr) {
- switch (this->CudaOptions[config]->GetCudaRuntime()) {
- case cmVisualStudioGeneratorOptions::CudaRuntimeStatic:
- libVec.push_back("cudadevrt.lib");
- libVec.push_back("cudart_static.lib");
- break;
- case cmVisualStudioGeneratorOptions::CudaRuntimeShared:
- libVec.push_back("cudadevrt.lib");
- libVec.push_back("cudart.lib");
- break;
- case cmVisualStudioGeneratorOptions::CudaRuntimeNone:
- break;
- }
+ this->CudaOptions[config]->FixCudaRuntime(this->GeneratorTarget);
}
std::string standardLibsVar =
cmStrCat("CMAKE_", linkLanguage, "_STANDARD_LIBRARIES");
diff --git a/Source/cmVisualStudioGeneratorOptions.cxx b/Source/cmVisualStudioGeneratorOptions.cxx
index 18c19b7..4004b66 100644
--- a/Source/cmVisualStudioGeneratorOptions.cxx
+++ b/Source/cmVisualStudioGeneratorOptions.cxx
@@ -3,6 +3,8 @@
#include <cm/iterator>
#include "cmAlgorithms.h"
+#include "cmGeneratorExpression.h"
+#include "cmGeneratorTarget.h"
#include "cmLocalVisualStudioGenerator.h"
#include "cmOutputConverter.h"
#include "cmSystemTools.h"
@@ -149,25 +151,33 @@ bool cmVisualStudioGeneratorOptions::UsingSBCS() const
return false;
}
-cmVisualStudioGeneratorOptions::CudaRuntime
-cmVisualStudioGeneratorOptions::GetCudaRuntime() const
+void cmVisualStudioGeneratorOptions::FixCudaRuntime(cmGeneratorTarget* target)
{
std::map<std::string, FlagValue>::const_iterator i =
this->FlagMap.find("CudaRuntime");
- if (i != this->FlagMap.end() && i->second.size() == 1) {
- std::string const& cudaRuntime = i->second[0];
- if (cudaRuntime == "Static") {
- return CudaRuntimeStatic;
- }
- if (cudaRuntime == "Shared") {
- return CudaRuntimeShared;
- }
- if (cudaRuntime == "None") {
- return CudaRuntimeNone;
+ if (i == this->FlagMap.end()) {
+ // User didn't provide am override so get the property value
+ const char* runtimeLibraryValue =
+ target->GetProperty("CUDA_RUNTIME_LIBRARY");
+ if (runtimeLibraryValue) {
+ std::string cudaRuntime =
+ cmSystemTools::UpperCase(cmGeneratorExpression::Evaluate(
+ runtimeLibraryValue, this->LocalGenerator, this->Configuration,
+ target));
+ if (cudaRuntime == "STATIC") {
+ this->AddFlag("CudaRuntime", "Static");
+ }
+ if (cudaRuntime == "SHARED") {
+ this->AddFlag("CudaRuntime", "Shared");
+ }
+ if (cudaRuntime == "NONE") {
+ this->AddFlag("CudaRuntime", "None");
+ }
+ } else {
+ // nvcc default is static
+ this->AddFlag("CudaRuntime", "Static");
}
}
- // nvcc default is static
- return CudaRuntimeStatic;
}
void cmVisualStudioGeneratorOptions::FixCudaCodeGeneration()
diff --git a/Source/cmVisualStudioGeneratorOptions.h b/Source/cmVisualStudioGeneratorOptions.h
index d8dcfe2..b335694 100644
--- a/Source/cmVisualStudioGeneratorOptions.h
+++ b/Source/cmVisualStudioGeneratorOptions.h
@@ -13,6 +13,7 @@
#include "cmIDEOptions.h"
class cmLocalVisualStudioGenerator;
+class cmGeneratorTarget;
using cmVS7FlagTable = cmIDEFlagTable;
@@ -61,15 +62,8 @@ public:
bool UsingUnicode() const;
bool UsingSBCS() const;
- enum CudaRuntime
- {
- CudaRuntimeStatic,
- CudaRuntimeShared,
- CudaRuntimeNone
- };
- CudaRuntime GetCudaRuntime() const;
-
void FixCudaCodeGeneration();
+ void FixCudaRuntime(cmGeneratorTarget* target);
void FixManifestUACFlags();