CUDA: Support compiler id and version generator expressions
Introduce the CUDA_COMPILER_ID and CUDA_COMPILER_VERSION generator expressions.
This commit is contained in:
parent
b544e34af6
commit
b53766b205
@ -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.
|
||||
|
@ -690,6 +690,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)
|
||||
@ -793,6 +815,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)
|
||||
@ -2066,6 +2110,7 @@ const cmGeneratorExpressionNode* cmGeneratorExpressionNode::GetNode(
|
||||
{ "NOT", ¬Node },
|
||||
{ "C_COMPILER_ID", &cCompilerIdNode },
|
||||
{ "CXX_COMPILER_ID", &cxxCompilerIdNode },
|
||||
{ "CUDA_COMPILER_ID", &cudaCompilerIdNode },
|
||||
{ "Fortran_COMPILER_ID", &fortranCompilerIdNode },
|
||||
{ "VERSION_GREATER", &versionGreaterNode },
|
||||
{ "VERSION_GREATER_EQUAL", &versionGreaterEqNode },
|
||||
@ -2074,6 +2119,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 },
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
{
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user