diff options
author | Brad King <brad.king@kitware.com> | 2022-02-28 18:23:14 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2022-03-01 02:30:23 (GMT) |
commit | fe64c49e72ec025965bc9fe1a733859c025f68b1 (patch) | |
tree | 7fe823ffe65eb5370c807a3e0e5010f05d72f83f /Modules/CMakeDetermineCUDACompiler.cmake | |
parent | 07a7772968a17e804fc7c450a0a3a00a7203410d (diff) | |
download | CMake-fe64c49e72ec025965bc9fe1a733859c025f68b1.zip CMake-fe64c49e72ec025965bc9fe1a733859c025f68b1.tar.gz CMake-fe64c49e72ec025965bc9fe1a733859c025f68b1.tar.bz2 |
CUDA: Simplify CMAKE_CUDA_ARCHITECTURES special value logic
Refactor the logic checking `CMAKE_CUDA_ARCHITECTURES` special values.
Switch on the value first, and then make other decisions for each case.
This makes room for other special values to be added later.
Diffstat (limited to 'Modules/CMakeDetermineCUDACompiler.cmake')
-rw-r--r-- | Modules/CMakeDetermineCUDACompiler.cmake | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/Modules/CMakeDetermineCUDACompiler.cmake b/Modules/CMakeDetermineCUDACompiler.cmake index c21d622..d8fc66f 100644 --- a/Modules/CMakeDetermineCUDACompiler.cmake +++ b/Modules/CMakeDetermineCUDACompiler.cmake @@ -272,26 +272,24 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN) endif() endif() - # Detect explicit architectures and add them during detection. - if(DEFINED CMAKE_CUDA_ARCHITECTURES AND NOT "${CMAKE_CUDA_ARCHITECTURES}" STREQUAL "all" AND NOT "${CMAKE_CUDA_ARCHITECTURES}" STREQUAL "all-major") - set(architectures_explicit TRUE) - set(architectures_test ${CMAKE_CUDA_ARCHITECTURES}) - endif() - - # For sufficiently new NVCC we can just use the all and all-major flags. - # For VS we don't test since we can't figure out the version this early (see #23161). - # For others select based on version. - if(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA" AND CMAKE_CUDA_COMPILER_TOOLKIT_VERSION VERSION_GREATER_EQUAL 11.5) - if("${CMAKE_CUDA_ARCHITECTURES}" STREQUAL "all") - string(APPEND nvcc_test_flags " -arch=all") - elseif("${CMAKE_CUDA_ARCHITECTURES}" STREQUAL "all-major") - string(APPEND nvcc_test_flags " -arch=all-major") - endif() - elseif(NOT CMAKE_GENERATOR MATCHES "Visual Studio") - if("${CMAKE_CUDA_ARCHITECTURES}" STREQUAL "all") - set(architectures_test ${CMAKE_CUDA_ARCHITECTURES_ALL}) - elseif("${CMAKE_CUDA_ARCHITECTURES}" STREQUAL "all-major") - set(architectures_test ${CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR}) + if(DEFINED CMAKE_CUDA_ARCHITECTURES) + if(CMAKE_CUDA_ARCHITECTURES MATCHES "^(all|all-major)$") + # For sufficiently new NVCC we can just use the all and all-major flags. + # For VS we don't test since we can't figure out the version this early (see #23161). + # For others select based on version. + if(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA" AND CMAKE_CUDA_COMPILER_TOOLKIT_VERSION VERSION_GREATER_EQUAL 11.5) + string(APPEND nvcc_test_flags " -arch=${CMAKE_CUDA_ARCHITECTURES}") + elseif(NOT CMAKE_GENERATOR MATCHES "Visual Studio") + if(CMAKE_CUDA_ARCHITECTURES STREQUAL "all") + set(architectures_test ${CMAKE_CUDA_ARCHITECTURES_ALL}) + elseif(CMAKE_CUDA_ARCHITECTURES STREQUAL "all-major") + set(architectures_test ${CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR}) + endif() + endif() + else() + # Explicit architectures. Test them during detection. + set(architectures_explicit TRUE) + set(architectures_test ${CMAKE_CUDA_ARCHITECTURES}) endif() endif() |