mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-19 02:17:27 +08:00
VS: Add basic infrastructure for CUDA generation
Generate the `CudaCompile` elements in `.vcxproj` files.
This commit is contained in:
@@ -112,6 +112,10 @@ cmVisualStudio10TargetGenerator::~cmVisualStudio10TargetGenerator()
|
|||||||
i != this->LinkOptions.end(); ++i) {
|
i != this->LinkOptions.end(); ++i) {
|
||||||
delete i->second;
|
delete i->second;
|
||||||
}
|
}
|
||||||
|
for (OptionsMap::iterator i = this->CudaOptions.begin();
|
||||||
|
i != this->CudaOptions.end(); ++i) {
|
||||||
|
delete i->second;
|
||||||
|
}
|
||||||
if (!this->BuildFileStream) {
|
if (!this->BuildFileStream) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -206,6 +210,9 @@ void cmVisualStudio10TargetGenerator::Generate()
|
|||||||
if (!this->ComputeRcOptions()) {
|
if (!this->ComputeRcOptions()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!this->ComputeCudaOptions()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!this->ComputeMasmOptions()) {
|
if (!this->ComputeMasmOptions()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -454,6 +461,14 @@ void cmVisualStudio10TargetGenerator::Generate()
|
|||||||
this->WriteString("<Import Project=\"" VS10_CXX_PROPS "\" />\n", 1);
|
this->WriteString("<Import Project=\"" VS10_CXX_PROPS "\" />\n", 1);
|
||||||
}
|
}
|
||||||
this->WriteString("<ImportGroup Label=\"ExtensionSettings\">\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()) {
|
if (this->GlobalGenerator->IsMasmEnabled()) {
|
||||||
this->WriteString("<Import Project=\"$(VCTargetsPath)\\"
|
this->WriteString("<Import Project=\"$(VCTargetsPath)\\"
|
||||||
"BuildCustomizations\\masm.props\" />\n",
|
"BuildCustomizations\\masm.props\" />\n",
|
||||||
@@ -524,6 +539,14 @@ void cmVisualStudio10TargetGenerator::Generate()
|
|||||||
this->WriteTargetSpecificReferences();
|
this->WriteTargetSpecificReferences();
|
||||||
this->WriteString("<ImportGroup Label=\"ExtensionTargets\">\n", 1);
|
this->WriteString("<ImportGroup Label=\"ExtensionTargets\">\n", 1);
|
||||||
this->WriteTargetsFileReferences();
|
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()) {
|
if (this->GlobalGenerator->IsMasmEnabled()) {
|
||||||
this->WriteString("<Import Project=\"$(VCTargetsPath)\\"
|
this->WriteString("<Import Project=\"$(VCTargetsPath)\\"
|
||||||
"BuildCustomizations\\masm.targets\" />\n",
|
"BuildCustomizations\\masm.targets\" />\n",
|
||||||
@@ -1772,6 +1795,8 @@ void cmVisualStudio10TargetGenerator::WriteAllSources()
|
|||||||
tool = "ResourceCompile";
|
tool = "ResourceCompile";
|
||||||
} else if (lang == "CSharp") {
|
} else if (lang == "CSharp") {
|
||||||
tool = "Compile";
|
tool = "Compile";
|
||||||
|
} else if (lang == "CUDA" && this->GlobalGenerator->IsCudaEnabled()) {
|
||||||
|
tool = "CudaCompile";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tool.empty()) {
|
if (!tool.empty()) {
|
||||||
@@ -2401,6 +2426,83 @@ void cmVisualStudio10TargetGenerator::WriteRCOptions(
|
|||||||
this->WriteString("</ResourceCompile>\n", 2);
|
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()
|
bool cmVisualStudio10TargetGenerator::ComputeMasmOptions()
|
||||||
{
|
{
|
||||||
if (!this->GlobalGenerator->IsMasmEnabled()) {
|
if (!this->GlobalGenerator->IsMasmEnabled()) {
|
||||||
@@ -3142,6 +3244,7 @@ void cmVisualStudio10TargetGenerator::WriteItemDefinitionGroups()
|
|||||||
this->WriteClOptions(*i, includes);
|
this->WriteClOptions(*i, includes);
|
||||||
// output rc compile flags <ResourceCompile></ResourceCompile>
|
// output rc compile flags <ResourceCompile></ResourceCompile>
|
||||||
this->WriteRCOptions(*i, includes);
|
this->WriteRCOptions(*i, includes);
|
||||||
|
this->WriteCudaOptions(*i, includes);
|
||||||
this->WriteMasmOptions(*i, includes);
|
this->WriteMasmOptions(*i, includes);
|
||||||
this->WriteNasmOptions(*i, includes);
|
this->WriteNasmOptions(*i, includes);
|
||||||
}
|
}
|
||||||
|
@@ -98,6 +98,10 @@ private:
|
|||||||
bool ComputeRcOptions(std::string const& config);
|
bool ComputeRcOptions(std::string const& config);
|
||||||
void WriteRCOptions(std::string const& config,
|
void WriteRCOptions(std::string const& config,
|
||||||
std::vector<std::string> const& includes);
|
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();
|
||||||
bool ComputeMasmOptions(std::string const& config);
|
bool ComputeMasmOptions(std::string const& config);
|
||||||
void WriteMasmOptions(std::string const& config,
|
void WriteMasmOptions(std::string const& config,
|
||||||
@@ -150,6 +154,7 @@ private:
|
|||||||
typedef std::map<std::string, Options*> OptionsMap;
|
typedef std::map<std::string, Options*> OptionsMap;
|
||||||
OptionsMap ClOptions;
|
OptionsMap ClOptions;
|
||||||
OptionsMap RcOptions;
|
OptionsMap RcOptions;
|
||||||
|
OptionsMap CudaOptions;
|
||||||
OptionsMap MasmOptions;
|
OptionsMap MasmOptions;
|
||||||
OptionsMap NasmOptions;
|
OptionsMap NasmOptions;
|
||||||
OptionsMap LinkOptions;
|
OptionsMap LinkOptions;
|
||||||
|
@@ -299,6 +299,9 @@ void cmVisualStudioGeneratorOptions::OutputPreprocessorDefinitions(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const char* tag = "PreprocessorDefinitions";
|
const char* tag = "PreprocessorDefinitions";
|
||||||
|
if (lang == "CUDA") {
|
||||||
|
tag = "Defines";
|
||||||
|
}
|
||||||
if (this->Version >= cmGlobalVisualStudioGenerator::VS10) {
|
if (this->Version >= cmGlobalVisualStudioGenerator::VS10) {
|
||||||
// if there are configuration specific flags, then
|
// if there are configuration specific flags, then
|
||||||
// use the configuration specific tag for PreprocessorDefinitions
|
// use the configuration specific tag for PreprocessorDefinitions
|
||||||
|
@@ -26,6 +26,7 @@ public:
|
|||||||
{
|
{
|
||||||
Compiler,
|
Compiler,
|
||||||
ResourceCompiler,
|
ResourceCompiler,
|
||||||
|
CudaCompiler,
|
||||||
MasmCompiler,
|
MasmCompiler,
|
||||||
NasmCompiler,
|
NasmCompiler,
|
||||||
Linker,
|
Linker,
|
||||||
|
Reference in New Issue
Block a user