diff --git a/Modules/CMakeDetermineCUDACompiler.cmake b/Modules/CMakeDetermineCUDACompiler.cmake index 70528da3d0..cad26da4e1 100644 --- a/Modules/CMakeDetermineCUDACompiler.cmake +++ b/Modules/CMakeDetermineCUDACompiler.cmake @@ -112,9 +112,14 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN) cmake_cuda_architectures_validate(CUDA) if(CMAKE_CUDA_COMPILER_ID STREQUAL "Clang") - # Clang doesn't automatically select an architecture supported by the SDK. - # Try in reverse order of deprecation with the most recent at front (i.e. the most likely to work for new setups). - foreach(arch "52" "30" "20") + # Clang does not automatically select an architecture supported by the SDK. + # Prefer NVCC's default for each SDK version, and fall back to older archs. + set(archs "") + if(NOT CMAKE_CUDA_COMPILER_TOOLKIT_VERSION VERSION_LESS 11.0) + list(APPEND archs 52) + endif() + list(APPEND archs 30 20) + foreach(arch IN LISTS archs) list(APPEND CMAKE_CUDA_COMPILER_ID_TEST_FLAGS_FIRST "${clang_test_flags} --cuda-gpu-arch=sm_${arch}") endforeach() elseif(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA")