summaryrefslogtreecommitdiffstats
path: root/Tests/CudaOnly
diff options
context:
space:
mode:
authorRobert Maynard <rmaynard@nvidia.com>2021-02-08 16:37:02 (GMT)
committerBrad King <brad.king@kitware.com>2021-02-09 14:39:20 (GMT)
commitcd89d1c328439709eb090e099774bbb6ddf8eb95 (patch)
treeab54414e545d79be1757a3217a903b9297c0a0ae /Tests/CudaOnly
parentb06a480b5726a44cefb98cf84f0d874c37d1a95c (diff)
downloadCMake-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')
-rw-r--r--Tests/CudaOnly/CMakeLists.txt1
-rw-r--r--Tests/CudaOnly/Toolkit/CMakeLists.txt4
-rw-r--r--Tests/CudaOnly/ToolkitBeforeLang/CMakeLists.txt26
-rw-r--r--Tests/CudaOnly/ToolkitBeforeLang/main.cu8
4 files changed, 39 insertions, 0 deletions
diff --git a/Tests/CudaOnly/CMakeLists.txt b/Tests/CudaOnly/CMakeLists.txt
index 033f197..fdb7a6e 100644
--- a/Tests/CudaOnly/CMakeLists.txt
+++ b/Tests/CudaOnly/CMakeLists.txt
@@ -11,6 +11,7 @@ add_cuda_test_macro(CudaOnly.ExportPTX CudaOnlyExportPTX)
add_cuda_test_macro(CudaOnly.SharedRuntimePlusToolkit CudaOnlySharedRuntimePlusToolkit)
add_cuda_test_macro(CudaOnly.Standard98 CudaOnlyStandard98)
add_cuda_test_macro(CudaOnly.Toolkit CudaOnlyToolkit)
+add_cuda_test_macro(CudaOnly.ToolkitBeforeLang CudaOnlyToolkitBeforeLang)
add_cuda_test_macro(CudaOnly.WithDefs CudaOnlyWithDefs)
add_cuda_test_macro(CudaOnly.CircularLinkLine CudaOnlyCircularLinkLine)
add_cuda_test_macro(CudaOnly.ResolveDeviceSymbols CudaOnlyResolveDeviceSymbols)
diff --git a/Tests/CudaOnly/Toolkit/CMakeLists.txt b/Tests/CudaOnly/Toolkit/CMakeLists.txt
index bb06ba8..1486c1a 100644
--- a/Tests/CudaOnly/Toolkit/CMakeLists.txt
+++ b/Tests/CudaOnly/Toolkit/CMakeLists.txt
@@ -2,6 +2,10 @@ cmake_minimum_required(VERSION 3.15)
project(CudaOnlyToolkit CUDA)
find_package(CUDAToolkit REQUIRED)
+if(NOT DEFINED CUDAToolkit_VERSION)
+ message(FATAL_ERROR "expected CUDAToolkit variable CUDAToolkit_VERSION not found")
+endif()
+
message(STATUS "CUDAToolkit_VERSION: ${CUDAToolkit_VERSION}")
message(STATUS "CUDAToolkit_VERSION_MAJOR: ${CUDAToolkit_VERSION_MAJOR}")
message(STATUS "CUDAToolkit_VERSION_MINOR: ${CUDAToolkit_VERSION_MINOR}")
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;
+}