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.
This commit is contained in:
Robert Maynard
2019-11-29 13:51:32 -05:00
parent 4dbc9dfc7a
commit 0d0145138f
41 changed files with 911 additions and 51 deletions
+24 -14
View File
@@ -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()