diff options
author | Robert Maynard <rmaynard@nvidia.com> | 2021-02-08 16:37:02 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-02-09 14:39:20 (GMT) |
commit | cd89d1c328439709eb090e099774bbb6ddf8eb95 (patch) | |
tree | ab54414e545d79be1757a3217a903b9297c0a0ae /Tests/CudaOnly/ToolkitBeforeLang | |
parent | b06a480b5726a44cefb98cf84f0d874c37d1a95c (diff) | |
download | CMake-cd89d1c328439709eb090e099774bbb6ddf8eb95.zip CMake-cd89d1c328439709eb090e099774bbb6ddf8eb95.tar.gz CMake-cd89d1c328439709eb090e099774bbb6ddf8eb95.tar.bz2 |
FindCUDAToolkit: Robust version checks when CUDA lang is not enabled
Previously if you set `CMAKE_CUDA_COMPILER` but hadn't enabled
the CUDA language, FindCUDAToolkit would not correctly compute
the version information.
Diffstat (limited to 'Tests/CudaOnly/ToolkitBeforeLang')
-rw-r--r-- | Tests/CudaOnly/ToolkitBeforeLang/CMakeLists.txt | 26 | ||||
-rw-r--r-- | Tests/CudaOnly/ToolkitBeforeLang/main.cu | 8 |
2 files changed, 34 insertions, 0 deletions
diff --git a/Tests/CudaOnly/ToolkitBeforeLang/CMakeLists.txt b/Tests/CudaOnly/ToolkitBeforeLang/CMakeLists.txt new file mode 100644 index 0000000..8dff6cc --- /dev/null +++ b/Tests/CudaOnly/ToolkitBeforeLang/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required(VERSION 3.15) +project(CudaOnlyToolkitBeforeLang CXX) + +# Validate that CUDAToolkit gets the correct version +# when called before CUDA the language is enabled +find_package(CUDAToolkit REQUIRED) +enable_language(CUDA) + +if(NOT DEFINED CUDAToolkit_VERSION) + message(FATAL_ERROR "expected CUDAToolkit variable CUDAToolkit_VERSION not found") +endif() + +set(cuda_libs cudart cuda_driver) + +# Verify that all the CUDA:: targets and variables exist +foreach (cuda_lib IN LISTS cuda_libs) + if(NOT CUDA_${cuda_lib}_LIBRARY) + message(FATAL_ERROR "expected CUDAToolkit variable CUDA_${cuda_lib}_LIBRARY not found") + endif() + if(NOT TARGET CUDA::${cuda_lib}) + message(FATAL_ERROR "expected CUDAToolkit target CUDA::${cuda_lib} not found") + endif() +endforeach() + +add_executable(CudaOnlyToolkitBeforeLang main.cu) +target_link_libraries(CudaOnlyToolkitBeforeLang PRIVATE CUDA::toolkit) diff --git a/Tests/CudaOnly/ToolkitBeforeLang/main.cu b/Tests/CudaOnly/ToolkitBeforeLang/main.cu new file mode 100644 index 0000000..0f3ccdc --- /dev/null +++ b/Tests/CudaOnly/ToolkitBeforeLang/main.cu @@ -0,0 +1,8 @@ +// Only thing we care about is that these headers are found +#include <cuda.h> +#include <cuda_runtime_api.h> + +int main(int argc, char** argv) +{ + return 0; +} |