summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2017-03-07 20:59:33 (GMT)
committerBrad King <brad.king@kitware.com>2017-03-10 15:19:56 (GMT)
commitb64b4629ea8aa669d652ffb32fe7a7336bd8ea8c (patch)
treec47630b950558eba7f1883109e6e6caad6e163bc
parent041ebda25bef6c142ac80135b0b59d88acbc0f1f (diff)
downloadCMake-b64b4629ea8aa669d652ffb32fe7a7336bd8ea8c.zip
CMake-b64b4629ea8aa669d652ffb32fe7a7336bd8ea8c.tar.gz
CMake-b64b4629ea8aa669d652ffb32fe7a7336bd8ea8c.tar.bz2
VS: Add basic infrastructure for CUDA generation
Generate the `CudaCompile` elements in `.vcxproj` files.
-rw-r--r--Source/cmVisualStudio10TargetGenerator.cxx103
-rw-r--r--Source/cmVisualStudio10TargetGenerator.h5
-rw-r--r--Source/cmVisualStudioGeneratorOptions.cxx3
-rw-r--r--Source/cmVisualStudioGeneratorOptions.h1
4 files changed, 112 insertions, 0 deletions
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx
index fbf7447..613c825 100644
--- a/Source/cmVisualStudio10TargetGenerator.cxx
+++ b/Source/cmVisualStudio10TargetGenerator.cxx
@@ -112,6 +112,10 @@ cmVisualStudio10TargetGenerator::~cmVisualStudio10TargetGenerator()
i != this->LinkOptions.end(); ++i) {
delete i->second;
}
+ for (OptionsMap::iterator i = this->CudaOptions.begin();
+ i != this->CudaOptions.end(); ++i) {
+ delete i->second;
+ }
if (!this->BuildFileStream) {
return;
}
@@ -206,6 +210,9 @@ void cmVisualStudio10TargetGenerator::Generate()
if (!this->ComputeRcOptions()) {
return;
}
+ if (!this->ComputeCudaOptions()) {
+ return;
+ }
if (!this->ComputeMasmOptions()) {
return;
}
@@ -454,6 +461,14 @@ void cmVisualStudio10TargetGenerator::Generate()
this->WriteString("<Import Project=\"" VS10_CXX_PROPS "\" />\n", 1);
}
this->WriteString("<ImportGroup Label=\"ExtensionSettings\">\n", 1);
+ if (this->GlobalGenerator->IsCudaEnabled()) {
+ this->WriteString("<Import Project=\"$(VCTargetsPath)\\"
+ "BuildCustomizations\\CUDA ",
+ 2);
+ (*this->BuildFileStream)
+ << cmVS10EscapeXML(this->GlobalGenerator->GetPlatformToolsetCudaString())
+ << ".props\" />\n";
+ }
if (this->GlobalGenerator->IsMasmEnabled()) {
this->WriteString("<Import Project=\"$(VCTargetsPath)\\"
"BuildCustomizations\\masm.props\" />\n",
@@ -524,6 +539,14 @@ void cmVisualStudio10TargetGenerator::Generate()
this->WriteTargetSpecificReferences();
this->WriteString("<ImportGroup Label=\"ExtensionTargets\">\n", 1);
this->WriteTargetsFileReferences();
+ if (this->GlobalGenerator->IsCudaEnabled()) {
+ this->WriteString("<Import Project=\"$(VCTargetsPath)\\"
+ "BuildCustomizations\\CUDA ",
+ 2);
+ (*this->BuildFileStream)
+ << cmVS10EscapeXML(this->GlobalGenerator->GetPlatformToolsetCudaString())
+ << ".targets\" />\n";
+ }
if (this->GlobalGenerator->IsMasmEnabled()) {
this->WriteString("<Import Project=\"$(VCTargetsPath)\\"
"BuildCustomizations\\masm.targets\" />\n",
@@ -1772,6 +1795,8 @@ void cmVisualStudio10TargetGenerator::WriteAllSources()
tool = "ResourceCompile";
} else if (lang == "CSharp") {
tool = "Compile";
+ } else if (lang == "CUDA" && this->GlobalGenerator->IsCudaEnabled()) {
+ tool = "CudaCompile";
}
if (!tool.empty()) {
@@ -2401,6 +2426,83 @@ void cmVisualStudio10TargetGenerator::WriteRCOptions(
this->WriteString("</ResourceCompile>\n", 2);
}
+bool cmVisualStudio10TargetGenerator::ComputeCudaOptions()
+{
+ if (!this->GlobalGenerator->IsCudaEnabled()) {
+ return true;
+ }
+ for (std::vector<std::string>::const_iterator i =
+ this->Configurations.begin();
+ i != this->Configurations.end(); ++i) {
+ if (!this->ComputeCudaOptions(*i)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+bool cmVisualStudio10TargetGenerator::ComputeCudaOptions(
+ std::string const& configName)
+{
+ cmGlobalVisualStudio10Generator* gg =
+ static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
+ CM_AUTO_PTR<Options> pOptions(new Options(
+ this->LocalGenerator, Options::CudaCompiler, gg->GetCudaFlagTable()));
+ Options& cudaOptions = *pOptions;
+
+ // Get compile flags for CUDA in this directory.
+ std::string CONFIG = cmSystemTools::UpperCase(configName);
+ std::string configFlagsVar = std::string("CMAKE_CUDA_FLAGS_") + CONFIG;
+ std::string flags =
+ std::string(this->Makefile->GetSafeDefinition("CMAKE_CUDA_FLAGS")) +
+ std::string(" ") +
+ std::string(this->Makefile->GetSafeDefinition(configFlagsVar));
+
+ // Get preprocessor definitions for this directory.
+ std::string defineFlags =
+ this->GeneratorTarget->Target->GetMakefile()->GetDefineFlags();
+
+ cudaOptions.Parse(flags.c_str());
+ cudaOptions.Parse(defineFlags.c_str());
+ cudaOptions.ParseFinish();
+
+ std::vector<std::string> targetDefines;
+ this->GeneratorTarget->GetCompileDefinitions(targetDefines,
+ configName.c_str(), "CUDA");
+ cudaOptions.AddDefines(targetDefines);
+
+ // Add a definition for the configuration name.
+ std::string configDefine = "CMAKE_INTDIR=\"";
+ configDefine += configName;
+ configDefine += "\"";
+ cudaOptions.AddDefine(configDefine);
+ if (const char* exportMacro = this->GeneratorTarget->GetExportMacro()) {
+ cudaOptions.AddDefine(exportMacro);
+ }
+
+ this->CudaOptions[configName] = pOptions.release();
+ return true;
+}
+
+void cmVisualStudio10TargetGenerator::WriteCudaOptions(
+ std::string const& configName, std::vector<std::string> const& includes)
+{
+ if (!this->MSTools || !this->GlobalGenerator->IsCudaEnabled()) {
+ return;
+ }
+ this->WriteString("<CudaCompile>\n", 2);
+
+ Options& cudaOptions = *(this->CudaOptions[configName]);
+ cudaOptions.AppendFlag("Include", includes);
+ cudaOptions.AppendFlag("Include", "%(Include)");
+ cudaOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
+ "\n", "CUDA");
+ cudaOptions.PrependInheritedString("AdditionalOptions");
+ cudaOptions.OutputFlagMap(*this->BuildFileStream, " ");
+
+ this->WriteString("</CudaCompile>\n", 2);
+}
+
bool cmVisualStudio10TargetGenerator::ComputeMasmOptions()
{
if (!this->GlobalGenerator->IsMasmEnabled()) {
@@ -3142,6 +3244,7 @@ void cmVisualStudio10TargetGenerator::WriteItemDefinitionGroups()
this->WriteClOptions(*i, includes);
// output rc compile flags <ResourceCompile></ResourceCompile>
this->WriteRCOptions(*i, includes);
+ this->WriteCudaOptions(*i, includes);
this->WriteMasmOptions(*i, includes);
this->WriteNasmOptions(*i, includes);
}
diff --git a/Source/cmVisualStudio10TargetGenerator.h b/Source/cmVisualStudio10TargetGenerator.h
index 0ebb4e4..52d5550 100644
--- a/Source/cmVisualStudio10TargetGenerator.h
+++ b/Source/cmVisualStudio10TargetGenerator.h
@@ -98,6 +98,10 @@ private:
bool ComputeRcOptions(std::string const& config);
void WriteRCOptions(std::string const& config,
std::vector<std::string> const& includes);
+ bool ComputeCudaOptions();
+ bool ComputeCudaOptions(std::string const& config);
+ void WriteCudaOptions(std::string const& config,
+ std::vector<std::string> const& includes);
bool ComputeMasmOptions();
bool ComputeMasmOptions(std::string const& config);
void WriteMasmOptions(std::string const& config,
@@ -150,6 +154,7 @@ private:
typedef std::map<std::string, Options*> OptionsMap;
OptionsMap ClOptions;
OptionsMap RcOptions;
+ OptionsMap CudaOptions;
OptionsMap MasmOptions;
OptionsMap NasmOptions;
OptionsMap LinkOptions;
diff --git a/Source/cmVisualStudioGeneratorOptions.cxx b/Source/cmVisualStudioGeneratorOptions.cxx
index 3007f14..125d2c4 100644
--- a/Source/cmVisualStudioGeneratorOptions.cxx
+++ b/Source/cmVisualStudioGeneratorOptions.cxx
@@ -299,6 +299,9 @@ void cmVisualStudioGeneratorOptions::OutputPreprocessorDefinitions(
return;
}
const char* tag = "PreprocessorDefinitions";
+ if (lang == "CUDA") {
+ tag = "Defines";
+ }
if (this->Version >= cmGlobalVisualStudioGenerator::VS10) {
// if there are configuration specific flags, then
// use the configuration specific tag for PreprocessorDefinitions
diff --git a/Source/cmVisualStudioGeneratorOptions.h b/Source/cmVisualStudioGeneratorOptions.h
index e79c977..e19d2dd 100644
--- a/Source/cmVisualStudioGeneratorOptions.h
+++ b/Source/cmVisualStudioGeneratorOptions.h
@@ -26,6 +26,7 @@ public:
{
Compiler,
ResourceCompiler,
+ CudaCompiler,
MasmCompiler,
NasmCompiler,
Linker,