summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Modules/CMakeDetermineCUDACompiler.cmake4
-rw-r--r--Modules/CMakeDetermineCompilerId.cmake2
-rw-r--r--Tests/RunCMake/CUDA_architectures/RunCMakeTest.cmake15
-rw-r--r--Tests/RunCMake/CUDA_architectures/architectures-not-set.cmake7
-rw-r--r--Tests/RunCMake/CUDA_architectures/architectures-off.cmake2
5 files changed, 27 insertions, 3 deletions
diff --git a/Modules/CMakeDetermineCUDACompiler.cmake b/Modules/CMakeDetermineCUDACompiler.cmake
index 8c01ea4..2649441 100644
--- a/Modules/CMakeDetermineCUDACompiler.cmake
+++ b/Modules/CMakeDetermineCUDACompiler.cmake
@@ -289,7 +289,7 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN)
set(architectures_test ${CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR})
endif()
endif()
- else()
+ elseif(CMAKE_CUDA_ARCHITECTURES OR "${CMAKE_CUDA_ARCHITECTURES}" STREQUAL "")
# Explicit architectures. Test them during detection.
set(architectures_explicit TRUE)
set(architectures_test ${CMAKE_CUDA_ARCHITECTURES})
@@ -633,7 +633,7 @@ if("${CMAKE_CUDA_ARCHITECTURES}" STREQUAL "")
message(FATAL_ERROR "Failed to detect a default CUDA architecture.\n\nCompiler output:\n${CMAKE_CUDA_COMPILER_PRODUCED_OUTPUT}")
endif()
endif()
-elseif(NOT "${architectures_tested}" MATCHES "^(all|all-major)$")
+elseif(CMAKE_CUDA_ARCHITECTURES AND NOT "${architectures_tested}" MATCHES "^(all|all-major)$")
# Sort since order mustn't matter.
list(SORT architectures_detected)
list(SORT architectures_tested)
diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake
index e0aa483..5670509 100644
--- a/Modules/CMakeDetermineCompilerId.cmake
+++ b/Modules/CMakeDetermineCompilerId.cmake
@@ -495,7 +495,7 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS}
if(CMAKE_VS_PLATFORM_NAME STREQUAL x64)
set(cuda_target "<TargetMachinePlatform>64</TargetMachinePlatform>")
endif()
- if(NOT CMAKE_CUDA_ARCHITECTURES MATCHES "^(all|all-major)$")
+ if(CMAKE_CUDA_ARCHITECTURES AND NOT CMAKE_CUDA_ARCHITECTURES MATCHES "^(all|all-major)$")
foreach(arch ${CMAKE_CUDA_ARCHITECTURES})
string(REGEX MATCH "[0-9]+" arch_name "${arch}")
string(APPEND cuda_codegen "compute_${arch_name},sm_${arch_name};")
diff --git a/Tests/RunCMake/CUDA_architectures/RunCMakeTest.cmake b/Tests/RunCMake/CUDA_architectures/RunCMakeTest.cmake
index d16156e..6fecae7 100644
--- a/Tests/RunCMake/CUDA_architectures/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CUDA_architectures/RunCMakeTest.cmake
@@ -4,3 +4,18 @@ run_cmake(architectures-all)
run_cmake(architectures-all-major)
run_cmake(architectures-empty)
run_cmake(architectures-invalid)
+
+run_cmake(architectures-not-set)
+include("${RunCMake_BINARY_DIR}/architectures-not-set-build/info.cmake" OPTIONAL)
+message(STATUS " CMAKE_CUDA_COMPILER_ID='${CMAKE_CUDA_COMPILER_ID}'")
+message(STATUS " CMAKE_CUDA_COMPILER_VERSION='${CMAKE_CUDA_COMPILER_VERSION}'")
+message(STATUS " CMAKE_CUDA_ARCHITECTURES='${CMAKE_CUDA_ARCHITECTURES}'")
+
+if(CMAKE_CUDA_COMPILER_ID STREQUAL "Clang" AND CMAKE_CUDA_ARCHITECTURES)
+ list(GET CMAKE_CUDA_ARCHITECTURES 0 arch)
+ set(CMAKE_CUDA_FLAGS --cuda-gpu-arch=sm_${arch})
+ message(STATUS "Adding CMAKE_CUDA_FLAGS='${CMAKE_CUDA_FLAGS}' for CMAKE_CUDA_ARCHITECTURES=OFF with Clang.")
+ set(RunCMake_TEST_OPTIONS "-DCMAKE_CUDA_FLAGS=${CMAKE_CUDA_FLAGS}")
+endif()
+run_cmake(architectures-off)
+unset(RunCMake_TEST_OPTIONS)
diff --git a/Tests/RunCMake/CUDA_architectures/architectures-not-set.cmake b/Tests/RunCMake/CUDA_architectures/architectures-not-set.cmake
new file mode 100644
index 0000000..1be5491
--- /dev/null
+++ b/Tests/RunCMake/CUDA_architectures/architectures-not-set.cmake
@@ -0,0 +1,7 @@
+unset(CMAKE_CUDA_ARCHITECTURES)
+enable_language(CUDA)
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/info.cmake" "
+set(CMAKE_CUDA_COMPILER_ID \"${CMAKE_CUDA_COMPILER_ID}\")
+set(CMAKE_CUDA_COMPILER_VERSION \"${CMAKE_CUDA_COMPILER_VERSION}\")
+set(CMAKE_CUDA_ARCHITECTURES \"${CMAKE_CUDA_ARCHITECTURES}\")
+")
diff --git a/Tests/RunCMake/CUDA_architectures/architectures-off.cmake b/Tests/RunCMake/CUDA_architectures/architectures-off.cmake
new file mode 100644
index 0000000..99881d3
--- /dev/null
+++ b/Tests/RunCMake/CUDA_architectures/architectures-off.cmake
@@ -0,0 +1,2 @@
+set(CMAKE_CUDA_ARCHITECTURES OFF)
+enable_language(CUDA)