Merge topic 'cuda_compiler_generator_expressions'

b53766b205 CUDA: Support compiler id and version generator expressions
b544e34af6 All VersionNode use the same capitalization pattern

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !3085
This commit is contained in:
Brad King
2019-03-13 14:16:16 +00:00
committed by Kitware Robot
4 changed files with 70 additions and 2 deletions

View File

@@ -121,6 +121,9 @@ Variable Queries
``$<CXX_COMPILER_ID:compiler_id>``
``1`` if the CMake-id of the CXX compiler matches ``compiler_id``,
otherwise ``0``.
``$<CUDA_COMPILER_ID:compiler_id>``
``1`` if the CMake-id of the CUDA compiler matches ``compiler_id``,
otherwise ``0``.
See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable.
``$<Fortran_COMPILER_ID:compiler_id>``
``1`` if the CMake-id of the Fortran compiler matches ``compiler_id``,
@@ -132,6 +135,9 @@ Variable Queries
``$<CXX_COMPILER_VERSION:version>``
``1`` if the version of the CXX compiler matches ``version``, otherwise ``0``.
See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable.
``$<CUDA_COMPILER_VERSION:version>``
``1`` if the version of the CXX compiler matches ``version``, otherwise ``0``.
See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable.
``$<Fortran_COMPILER_VERSION:version>``
``1`` if the version of the Fortran compiler matches ``version``, otherwise ``0``.
See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable.
@@ -346,6 +352,9 @@ Variable Queries
``$<CXX_COMPILER_ID>``
The CMake-id of the CXX compiler used.
See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable.
``$<CUDA_COMPILER_ID>``
The CMake-id of the CUDA compiler used.
See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable.
``$<Fortran_COMPILER_ID>``
The CMake-id of the Fortran compiler used.
See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable.
@@ -355,6 +364,9 @@ Variable Queries
``$<CXX_COMPILER_VERSION>``
The version of the CXX compiler used.
See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable.
``$<CUDA_COMPILER_VERSION>``
The version of the CUDA compiler used.
See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable.
``$<Fortran_COMPILER_VERSION>``
The version of the Fortran compiler used.
See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable.

View File

@@ -692,6 +692,28 @@ static const struct CXXCompilerIdNode : public CompilerIdNode
}
} cxxCompilerIdNode;
static const struct CUDACompilerIdNode : public CompilerIdNode
{
CUDACompilerIdNode() {} // NOLINT(modernize-use-equals-default)
std::string Evaluate(
const std::vector<std::string>& parameters,
cmGeneratorExpressionContext* context,
const GeneratorExpressionContent* content,
cmGeneratorExpressionDAGChecker* dagChecker) const override
{
if (!context->HeadTarget) {
reportError(
context, content->GetOriginalExpression(),
"$<CUDA_COMPILER_ID> may only be used with binary targets. It may "
"not be used with add_custom_command or add_custom_target.");
return std::string();
}
return this->EvaluateWithLanguage(parameters, context, content, dagChecker,
"CUDA");
}
} cudaCompilerIdNode;
static const struct FortranCompilerIdNode : public CompilerIdNode
{
FortranCompilerIdNode() {} // NOLINT(modernize-use-equals-default)
@@ -773,9 +795,9 @@ static const struct CCompilerVersionNode : public CompilerVersionNode
}
} cCompilerVersionNode;
static const struct CxxCompilerVersionNode : public CompilerVersionNode
static const struct CXXCompilerVersionNode : public CompilerVersionNode
{
CxxCompilerVersionNode() {} // NOLINT(modernize-use-equals-default)
CXXCompilerVersionNode() {} // NOLINT(modernize-use-equals-default)
std::string Evaluate(
const std::vector<std::string>& parameters,
@@ -795,6 +817,28 @@ static const struct CxxCompilerVersionNode : public CompilerVersionNode
}
} cxxCompilerVersionNode;
static const struct CUDACompilerVersionNode : public CompilerVersionNode
{
CUDACompilerVersionNode() {} // NOLINT(modernize-use-equals-default)
std::string Evaluate(
const std::vector<std::string>& parameters,
cmGeneratorExpressionContext* context,
const GeneratorExpressionContent* content,
cmGeneratorExpressionDAGChecker* dagChecker) const override
{
if (!context->HeadTarget) {
reportError(
context, content->GetOriginalExpression(),
"$<CUDA_COMPILER_VERSION> may only be used with binary targets. It "
"may not be used with add_custom_command or add_custom_target.");
return std::string();
}
return this->EvaluateWithLanguage(parameters, context, content, dagChecker,
"CUDA");
}
} cudaCompilerVersionNode;
static const struct FortranCompilerVersionNode : public CompilerVersionNode
{
FortranCompilerVersionNode() {} // NOLINT(modernize-use-equals-default)
@@ -2082,6 +2126,7 @@ const cmGeneratorExpressionNode* cmGeneratorExpressionNode::GetNode(
{ "NOT", &notNode },
{ "C_COMPILER_ID", &cCompilerIdNode },
{ "CXX_COMPILER_ID", &cxxCompilerIdNode },
{ "CUDA_COMPILER_ID", &cudaCompilerIdNode },
{ "Fortran_COMPILER_ID", &fortranCompilerIdNode },
{ "VERSION_GREATER", &versionGreaterNode },
{ "VERSION_GREATER_EQUAL", &versionGreaterEqNode },
@@ -2090,6 +2135,7 @@ const cmGeneratorExpressionNode* cmGeneratorExpressionNode::GetNode(
{ "VERSION_EQUAL", &versionEqualNode },
{ "C_COMPILER_VERSION", &cCompilerVersionNode },
{ "CXX_COMPILER_VERSION", &cxxCompilerVersionNode },
{ "CUDA_COMPILER_VERSION", &cudaCompilerVersionNode },
{ "Fortran_COMPILER_VERSION", &fortranCompilerVersionNode },
{ "PLATFORM_ID", &platformIdNode },
{ "COMPILE_FEATURES", &compileFeaturesNode },

View File

@@ -37,6 +37,8 @@ target_compile_definitions(CudaOnlyWithDefs
$<$<CONFIG:RELEASE>:$<BUILD_INTERFACE:${release_compile_defs}>>
-DDEF_COMPILE_LANG_$<COMPILE_LANGUAGE>
-DDEF_LANG_IS_CUDA=$<COMPILE_LANGUAGE:CUDA>
-DDEF_CUDA_COMPILER=$<CUDA_COMPILER_ID>
-DDEF_CUDA_COMPILER_VERSION=$<CUDA_COMPILER_VERSION>
)
target_include_directories(CudaOnlyWithDefs

View File

@@ -39,6 +39,14 @@
# error "Expected DEF_LANG_IS_CUDA"
#endif
#ifndef DEF_CUDA_COMPILER
# error "DEF_CUDA_COMPILER not defined!"
#endif
#ifndef DEF_CUDA_COMPILER_VERSION
# error "DEF_CUDA_COMPILER_VERSION not defined!"
#endif
static __global__ void DetermineIfValidCudaDevice()
{
}