diff options
author | Robert Maynard <robert.maynard@kitware.com> | 2019-03-11 16:33:43 (GMT) |
---|---|---|
committer | Robert Maynard <robert.maynard@kitware.com> | 2019-03-11 16:33:43 (GMT) |
commit | b53766b2058160853a29c2bbf8dbfef7345552a4 (patch) | |
tree | f3d7cdfadccdbee4f783cfafa1e16a94455bc41c | |
parent | b544e34af61d2f12a5da62e29de5d635171b2b1d (diff) | |
download | CMake-b53766b2058160853a29c2bbf8dbfef7345552a4.zip CMake-b53766b2058160853a29c2bbf8dbfef7345552a4.tar.gz CMake-b53766b2058160853a29c2bbf8dbfef7345552a4.tar.bz2 |
CUDA: Support compiler id and version generator expressions
Introduce the CUDA_COMPILER_ID and CUDA_COMPILER_VERSION generator
expressions.
-rw-r--r-- | Help/manual/cmake-generator-expressions.7.rst | 12 | ||||
-rw-r--r-- | Source/cmGeneratorExpressionNode.cxx | 46 | ||||
-rw-r--r-- | Tests/CudaOnly/WithDefs/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Tests/CudaOnly/WithDefs/main.notcu | 8 |
4 files changed, 68 insertions, 0 deletions
diff --git a/Help/manual/cmake-generator-expressions.7.rst b/Help/manual/cmake-generator-expressions.7.rst index 7f484a4..47409ab 100644 --- a/Help/manual/cmake-generator-expressions.7.rst +++ b/Help/manual/cmake-generator-expressions.7.rst @@ -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. diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index 6ee7fa5..0ba662d 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -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 }, diff --git a/Tests/CudaOnly/WithDefs/CMakeLists.txt b/Tests/CudaOnly/WithDefs/CMakeLists.txt index e58204d..00fd7d2 100644 --- a/Tests/CudaOnly/WithDefs/CMakeLists.txt +++ b/Tests/CudaOnly/WithDefs/CMakeLists.txt @@ -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 diff --git a/Tests/CudaOnly/WithDefs/main.notcu b/Tests/CudaOnly/WithDefs/main.notcu index 98f73ce..68a296b 100644 --- a/Tests/CudaOnly/WithDefs/main.notcu +++ b/Tests/CudaOnly/WithDefs/main.notcu @@ -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() { } |