CUDA: Add support for the CUDA_SEPARABLE_COMPILATION target property

This commit is contained in:
Robert Maynard 2016-11-09 15:39:55 -05:00 committed by Brad King
parent ae05fcc63f
commit 4b31609710
4 changed files with 44 additions and 9 deletions

View File

@ -143,6 +143,7 @@ Properties on Targets
/prop_tgt/CONFIG_OUTPUT_NAME
/prop_tgt/CONFIG_POSTFIX
/prop_tgt/CROSSCOMPILING_EMULATOR
/prop_tgt/CUDA_SEPARABLE_COMPILATION
/prop_tgt/CXX_EXTENSIONS
/prop_tgt/CXX_STANDARD
/prop_tgt/CXX_STANDARD_REQUIRED

View File

@ -0,0 +1,13 @@
CUDA_SEPARABLE_COMPILATION
--------------------------
CUDA only: Enables separate compilation of device code
If set this will enable separable compilation for all CUDA files for
the given target.
For instance:
.. code-block:: cmake
set_property(TARGET myexe PROPERTY CUDA_SEPARABLE_COMPILATION ON)

View File

@ -596,13 +596,22 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile(
// Construct the compile rules.
{
std::string compileRuleVar = "CMAKE_";
compileRuleVar += lang;
compileRuleVar += "_COMPILE_OBJECT";
std::string compileRule =
this->Makefile->GetRequiredDefinition(compileRuleVar);
std::vector<std::string> compileCommands;
cmSystemTools::ExpandListArgument(compileRule, compileCommands);
if (lang == "CUDA") {
std::string cmdVar;
if (this->GeneratorTarget->GetProperty("CUDA_SEPARABLE_COMPILATION")) {
cmdVar = std::string("CMAKE_CUDA_COMPILE_SEPARABLE_COMPILATION");
} else {
cmdVar = std::string("CMAKE_CUDA_COMPILE_WHOLE_COMPILATION");
}
std::string compileRule = this->Makefile->GetRequiredDefinition(cmdVar);
cmSystemTools::ExpandListArgument(compileRule, compileCommands);
} else {
const std::string cmdVar =
std::string("CMAKE_") + lang + "_COMPILE_OBJECT";
std::string compileRule = this->Makefile->GetRequiredDefinition(cmdVar);
cmSystemTools::ExpandListArgument(compileRule, compileCommands);
}
if (this->Makefile->IsOn("CMAKE_EXPORT_COMPILE_COMMANDS") &&
lang_can_export_cmds && compileCommands.size() == 1) {

View File

@ -583,10 +583,22 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang)
}
// Rule for compiling object file.
const std::string cmdVar = std::string("CMAKE_") + lang + "_COMPILE_OBJECT";
std::string compileCmd = mf->GetRequiredDefinition(cmdVar);
std::vector<std::string> compileCmds;
cmSystemTools::ExpandListArgument(compileCmd, compileCmds);
if (lang == "CUDA") {
std::string cmdVar;
if (this->GeneratorTarget->GetProperty("CUDA_SEPARABLE_COMPILATION")) {
cmdVar = std::string("CMAKE_CUDA_COMPILE_SEPARABLE_COMPILATION");
} else {
cmdVar = std::string("CMAKE_CUDA_COMPILE_WHOLE_COMPILATION");
}
std::string compileCmd = mf->GetRequiredDefinition(cmdVar);
cmSystemTools::ExpandListArgument(compileCmd, compileCmds);
} else {
const std::string cmdVar =
std::string("CMAKE_") + lang + "_COMPILE_OBJECT";
std::string compileCmd = mf->GetRequiredDefinition(cmdVar);
cmSystemTools::ExpandListArgument(compileCmd, compileCmds);
}
// Maybe insert an include-what-you-use runner.
if (!compileCmds.empty() && (lang == "C" || lang == "CXX")) {