mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-11 00:11:07 -06:00
CUDA: Factor out helper to validate CMAKE_CUDA_ARCHITECTURES
Prepare to use it for other languages.
This commit is contained in:
@@ -111,23 +111,9 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Rest of the code treats an empty value as equivalent to "use the defaults".
|
||||
# Error out early to prevent confusing errors as a result of this.
|
||||
# Note that this also catches invalid non-numerical values such as "a".
|
||||
if(DEFINED CMAKE_CUDA_ARCHITECTURES)
|
||||
if(CMAKE_CUDA_ARCHITECTURES STREQUAL "")
|
||||
message(FATAL_ERROR "CMAKE_CUDA_ARCHITECTURES must be non-empty if set.")
|
||||
elseif(CMAKE_CUDA_ARCHITECTURES AND NOT CMAKE_CUDA_ARCHITECTURES MATCHES "^([0-9]+a?(-real|-virtual)?(;[0-9]+a?(-real|-virtual)?|;)*|all|all-major|native)$")
|
||||
message(FATAL_ERROR
|
||||
"CMAKE_CUDA_ARCHITECTURES:\n"
|
||||
" ${CMAKE_CUDA_ARCHITECTURES}\n"
|
||||
"is not one of the following:\n"
|
||||
" * a semicolon-separated list of integers, each optionally\n"
|
||||
" followed by '-real' or '-virtual'\n"
|
||||
" * a special value: all, all-major, native\n"
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
# If the user set CMAKE_CUDA_ARCHITECTURES, validate its value.
|
||||
include(Internal/CMakeCUDAArchitecturesValidate)
|
||||
cmake_cuda_architectures_validate(CUDA)
|
||||
|
||||
if(CMAKE_CUDA_COMPILER_ID STREQUAL "Clang")
|
||||
# Clang doesn't automatically select an architecture supported by the SDK.
|
||||
|
||||
19
Modules/Internal/CMakeCUDAArchitecturesValidate.cmake
Normal file
19
Modules/Internal/CMakeCUDAArchitecturesValidate.cmake
Normal file
@@ -0,0 +1,19 @@
|
||||
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
# file Copyright.txt or https://cmake.org/licensing for details.
|
||||
|
||||
function(cmake_cuda_architectures_validate lang)
|
||||
if(DEFINED CMAKE_${lang}_ARCHITECTURES)
|
||||
if(CMAKE_${lang}_ARCHITECTURES STREQUAL "")
|
||||
message(FATAL_ERROR "CMAKE_${lang}_ARCHITECTURES must be non-empty if set.")
|
||||
elseif(CMAKE_${lang}_ARCHITECTURES AND NOT CMAKE_${lang}_ARCHITECTURES MATCHES "^([0-9]+a?(-real|-virtual)?(;[0-9]+a?(-real|-virtual)?|;)*|all|all-major|native)$")
|
||||
message(FATAL_ERROR
|
||||
"CMAKE_${lang}_ARCHITECTURES:\n"
|
||||
" ${CMAKE_${lang}_ARCHITECTURES}\n"
|
||||
"is not one of the following:\n"
|
||||
" * a semicolon-separated list of integers, each optionally\n"
|
||||
" followed by '-real' or '-virtual'\n"
|
||||
" * a special value: all, all-major, native\n"
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
@@ -1,5 +1,7 @@
|
||||
^CMake Error at .*/Modules/CMakeDetermineCUDACompiler\.cmake:[0-9]+ \(message\):
|
||||
^CMake Error at .*/Internal/CMakeCUDAArchitecturesValidate\.cmake:[0-9]+ \(message\):
|
||||
CMAKE_CUDA_ARCHITECTURES must be non-empty if set\.
|
||||
Call Stack \(most recent call first\):
|
||||
[^
|
||||
]*/Modules/CMakeDetermineCUDACompiler.cmake:[0-9]+ \(cmake_cuda_architectures_validate\)
|
||||
architectures-empty\.cmake:2 \(enable_language\)
|
||||
CMakeLists\.txt:3 \(include\)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
^CMake Error at .*/Modules/CMakeDetermineCUDACompiler\.cmake:[0-9]+ \(message\):
|
||||
^CMake Error at .*/Internal/CMakeCUDAArchitecturesValidate\.cmake:[0-9]+ \(message\):
|
||||
CMAKE_CUDA_ARCHITECTURES:
|
||||
|
||||
invalid
|
||||
@@ -10,5 +10,7 @@
|
||||
\* a special value: all, all-major, native
|
||||
|
||||
Call Stack \(most recent call first\):
|
||||
[^
|
||||
]*/Modules/CMakeDetermineCUDACompiler.cmake:[0-9]+ \(cmake_cuda_architectures_validate\)
|
||||
architectures-invalid\.cmake:2 \(enable_language\)
|
||||
CMakeLists\.txt:3 \(include\)$
|
||||
|
||||
Reference in New Issue
Block a user