Commit bb68658e authored by Brad King's avatar Brad King Committed by Kitware Robot
Browse files

Merge topic 'findcudatoolkit_handle_cuda_compiler_without_enabled_lang'

cd89d1c3

 FindCUDAToolkit: Robust version checks when CUDA lang is not enabled
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Reviewed-by: Raul Tambre's avatarRaul Tambre <raul@tambre.ee>
Tested-by: Raul Tambre's avatarRaul Tambre <raul@tambre.ee>
Merge-request: !5787
parents 17c4ee40 cd89d1c3
Pipeline #213676 waiting for manual action with stages
in 5 minutes
......@@ -737,6 +737,7 @@ elseif(NOT CUDAToolkit_FIND_QUIETLY)
endif()
if(CUDAToolkit_NVCC_EXECUTABLE AND
CMAKE_CUDA_COMPILER_VERSION AND
CUDAToolkit_NVCC_EXECUTABLE STREQUAL CMAKE_CUDA_COMPILER)
# Need to set these based off the already computed CMAKE_CUDA_COMPILER_VERSION value
# This if statement will always match, but is used to provide variables for MATCH 1,2,3...
......
......@@ -5,6 +5,10 @@ project(Toolkit CXX)
# Validate that we can use CUDAToolkit to find cuda include paths
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}")
......
......@@ -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)
......
......@@ -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}")
......
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)
// 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;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment