summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Modules/CMakeDetermineCUDACompiler.cmake20
-rw-r--r--Modules/Internal/CMakeCUDAArchitecturesValidate.cmake19
-rw-r--r--Tests/RunCMake/CUDA_architectures/architectures-empty-stderr.txt4
-rw-r--r--Tests/RunCMake/CUDA_architectures/architectures-invalid-stderr.txt4
4 files changed, 28 insertions, 19 deletions
diff --git a/Modules/CMakeDetermineCUDACompiler.cmake b/Modules/CMakeDetermineCUDACompiler.cmake
index 481a15b..585b2aa 100644
--- a/Modules/CMakeDetermineCUDACompiler.cmake
+++ b/Modules/CMakeDetermineCUDACompiler.cmake
@@ -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.
diff --git a/Modules/Internal/CMakeCUDAArchitecturesValidate.cmake b/Modules/Internal/CMakeCUDAArchitecturesValidate.cmake
new file mode 100644
index 0000000..b6997d2
--- /dev/null
+++ b/Modules/Internal/CMakeCUDAArchitecturesValidate.cmake
@@ -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()
diff --git a/Tests/RunCMake/CUDA_architectures/architectures-empty-stderr.txt b/Tests/RunCMake/CUDA_architectures/architectures-empty-stderr.txt
index 6c42612..dbadd048 100644
--- a/Tests/RunCMake/CUDA_architectures/architectures-empty-stderr.txt
+++ b/Tests/RunCMake/CUDA_architectures/architectures-empty-stderr.txt
@@ -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\)
diff --git a/Tests/RunCMake/CUDA_architectures/architectures-invalid-stderr.txt b/Tests/RunCMake/CUDA_architectures/architectures-invalid-stderr.txt
index 14c76d2..891aa40 100644
--- a/Tests/RunCMake/CUDA_architectures/architectures-invalid-stderr.txt
+++ b/Tests/RunCMake/CUDA_architectures/architectures-invalid-stderr.txt
@@ -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\)$