cuda: Extend toolset argument to accept path

Previously cuda could only be used with cmake if it is
installed globally on the system. Sometimes this is not
possible (eg docker, packaging with conan, etc.).
Thus the cuda toolset argument is extended to take
a path to a cuda install directory.
This commit is contained in:
Benjamin Wozniak 2019-08-21 15:27:42 +02:00
parent a04b852a7b
commit df0247a371
2 changed files with 61 additions and 2 deletions

View File

@ -232,7 +232,15 @@ bool cmGlobalVisualStudio10Generator::SetGeneratorToolset(
if (this->GeneratorToolsetCuda.empty()) {
// Find the highest available version of the CUDA tools.
std::vector<std::string> cudaTools;
std::string const bcDir = this->VCTargetsPath + "/BuildCustomizations";
std::string bcDir;
if (this->GeneratorToolsetCudaCustomDir.empty()) {
bcDir = this->VCTargetsPath + "/BuildCustomizations";
} else {
bcDir = this->GetPlatformToolsetCudaCustomDirString() +
"CUDAVisualStudioIntegration\\extras\\"
"visual_studio_integration\\MSBuildExtensions";
cmSystemTools::ConvertToUnixSlashes(bcDir);
}
cmsys::Glob gl;
gl.SetRelative(bcDir.c_str());
if (gl.FindFiles(bcDir + "/CUDA *.props")) {
@ -243,6 +251,24 @@ bool cmGlobalVisualStudio10Generator::SetGeneratorToolset(
std::sort(cudaTools.begin(), cudaTools.end(),
cmSystemTools::VersionCompareGreater);
this->GeneratorToolsetCuda = cudaTools.at(0);
} else if (!this->GeneratorToolsetCudaCustomDir.empty()) {
// Generate an error if Visual Studio integration files are not found
// inside of custom cuda toolset.
std::ostringstream e;
/* clang-format off */
e <<
"Generator\n"
" " << this->GetName() << "\n"
"given toolset\n"
" cuda=" << this->GeneratorToolsetCudaCustomDir << "\n"
"cannot detect Visual Studio integration files in path\n"
" " << bcDir;
/* clang-format on */
mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
// Clear the configured tool-set
this->GeneratorToolsetCuda.clear();
}
}
@ -319,6 +345,9 @@ bool cmGlobalVisualStudio10Generator::SetGeneratorToolset(
if (const char* cuda = this->GetPlatformToolsetCuda()) {
mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_CUDA", cuda);
}
if (const char* cudaDir = this->GetPlatformToolsetCudaCustomDir()) {
mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR", cudaDir);
}
return true;
}
@ -395,7 +424,17 @@ bool cmGlobalVisualStudio10Generator::ProcessGeneratorToolsetField(
std::string const& key, std::string const& value)
{
if (key == "cuda") {
this->GeneratorToolsetCuda = value;
/* test if cuda toolset is path to custom dir or cuda version */
auto pos = value.find_first_not_of("0123456789.");
if (pos != std::string::npos) {
this->GeneratorToolsetCudaCustomDir = value;
/* ensure trailing backslash for easy path joining */
if (this->GeneratorToolsetCudaCustomDir.back() != '\\') {
this->GeneratorToolsetCudaCustomDir.push_back('\\');
}
} else {
this->GeneratorToolsetCuda = value;
}
return true;
}
if (key == "version") {
@ -643,6 +682,21 @@ cmGlobalVisualStudio10Generator::GetPlatformToolsetCudaString() const
return this->GeneratorToolsetCuda;
}
const char* cmGlobalVisualStudio10Generator::GetPlatformToolsetCudaCustomDir()
const
{
if (!this->GeneratorToolsetCudaCustomDir.empty()) {
return this->GeneratorToolsetCudaCustomDir.c_str();
}
return nullptr;
}
std::string const&
cmGlobalVisualStudio10Generator::GetPlatformToolsetCudaCustomDirString() const
{
return this->GeneratorToolsetCudaCustomDir;
}
bool cmGlobalVisualStudio10Generator::IsDefaultToolset(
const std::string&) const
{

View File

@ -61,6 +61,10 @@ public:
const char* GetPlatformToolsetCuda() const;
std::string const& GetPlatformToolsetCudaString() const;
/** The custom cuda install directory */
const char* GetPlatformToolsetCudaCustomDir() const;
std::string const& GetPlatformToolsetCudaCustomDirString() const;
/** Return whether we need to use No/Debug instead of false/true
for GenerateDebugInformation. */
bool GetPlatformToolsetNeedsDebugEnum() const
@ -152,6 +156,7 @@ protected:
std::string GeneratorToolsetVersion;
std::string GeneratorToolsetHostArchitecture;
std::string GeneratorToolsetCuda;
std::string GeneratorToolsetCudaCustomDir;
std::string DefaultPlatformToolset;
std::string DefaultPlatformToolsetHostArchitecture;
std::string WindowsTargetPlatformVersion;