VS: Select the CUDA runtime library

Parse the `-cudart=` option and add a corresponding `CudaRuntime`
field to the generated project file.  Also add a matching `.lib`
to the list of libraries linked.
This commit is contained in:
Brad King 2017-03-07 16:19:22 -05:00
parent 4def02a385
commit 253594d0ae
4 changed files with 70 additions and 2 deletions

View File

@ -5,5 +5,14 @@ static cmVS7FlagTable cmVS10CudaFlagTable[] = {
{ "AdditionalCompilerOptions", "Xcompiler", "Host compiler options", "",
cmVS7FlagTable::UserFollowing | cmVS7FlagTable::SpaceAppendable },
// Select the CUDA runtime library.
{ "CudaRuntime", "cudart=none", "No CUDA runtime library", "None", 0 },
{ "CudaRuntime", "cudart=shared", "Shared/dynamic CUDA runtime library",
"Shared", 0 },
{ "CudaRuntime", "cudart=static", "Static CUDA runtime library", "Static",
0 },
{ "CudaRuntime", "cudart", "CUDA runtime library", "",
cmVS7FlagTable::UserFollowing },
{ 0, 0, 0, 0, 0 }
};

View File

@ -2855,8 +2855,10 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions(
this->LocalGenerator, Options::Linker, gg->GetLinkFlagTable(), 0, this));
Options& linkOptions = *pOptions;
const std::string& linkLanguage =
this->GeneratorTarget->GetLinkerLanguage(config.c_str());
cmGeneratorTarget::LinkClosure const* linkClosure =
this->GeneratorTarget->GetLinkClosure(config);
const std::string& linkLanguage = linkClosure->LinkerLanguage;
if (linkLanguage.empty()) {
cmSystemTools::Error(
"CMake can not determine linker language for target: ",
@ -2911,6 +2913,19 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions(
std::vector<std::string> libVec;
std::vector<std::string> vsTargetVec;
this->AddLibraries(cli, libVec, vsTargetVec);
if (std::find(linkClosure->Languages.begin(), linkClosure->Languages.end(),
"CUDA") != linkClosure->Languages.end()) {
switch (this->CudaOptions[config]->GetCudaRuntime()) {
case cmVisualStudioGeneratorOptions::CudaRuntimeStatic:
libVec.push_back("cudart_static.lib");
break;
case cmVisualStudioGeneratorOptions::CudaRuntimeShared:
libVec.push_back("cudart.lib");
break;
case cmVisualStudioGeneratorOptions::CudaRuntimeNone:
break;
}
}
std::string standardLibsVar = "CMAKE_";
standardLibsVar += linkLanguage;
standardLibsVar += "_STANDARD_LIBRARIES";

View File

@ -187,6 +187,27 @@ bool cmVisualStudioGeneratorOptions::UsingSBCS() const
return false;
}
cmVisualStudioGeneratorOptions::CudaRuntime
cmVisualStudioGeneratorOptions::GetCudaRuntime() const
{
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;
}
}
// nvcc default is static
return CudaRuntimeStatic;
}
void cmVisualStudioGeneratorOptions::Parse(const char* flags)
{
// Parse the input string as a windows command line since the string
@ -220,6 +241,21 @@ void cmVisualStudioGeneratorOptions::ParseFinish()
rl += this->FortranRuntimeDLL ? "DLL" : "";
this->FlagMap["RuntimeLibrary"] = rl;
}
if (this->CurrentTool == CudaCompiler) {
std::map<std::string, FlagValue>::iterator i =
this->FlagMap.find("CudaRuntime");
if (i != this->FlagMap.end() && i->second.size() == 1) {
std::string& cudaRuntime = i->second[0];
if (cudaRuntime == "static") {
cudaRuntime = "Static";
} else if (cudaRuntime == "shared") {
cudaRuntime = "Shared";
} else if (cudaRuntime == "none") {
cudaRuntime = "None";
}
}
}
}
void cmVisualStudioGeneratorOptions::PrependInheritedString(

View File

@ -67,6 +67,14 @@ public:
bool UsingUnicode() const;
bool UsingSBCS() const;
enum CudaRuntime
{
CudaRuntimeStatic,
CudaRuntimeShared,
CudaRuntimeNone
};
CudaRuntime GetCudaRuntime() const;
bool IsDebug() const;
bool IsWinRt() const;
bool IsManaged() const;