summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Maynard <robert.maynard@kitware.com>2020-09-24 15:31:55 -0400
committerBrad King <brad.king@kitware.com>2020-10-08 08:30:59 -0400
commitda2622ff366e6089a98109c68ececac58d598b66 (patch)
tree8205c6455c1c996ccb39d6270b8de385a92e78bb
parentc61f820a7fb1b191fe5591805f7e53fc52424f93 (diff)
downloadcmake-da2622ff366e6089a98109c68ececac58d598b66.tar.gz
CUDA: Add Support to SourceCompiles|Runs and CheckCompilerFlags
-rw-r--r--Help/release/dev/cuda-check-support.rst11
-rw-r--r--Modules/CheckCompilerFlag.cmake4
-rw-r--r--Modules/CheckSourceCompiles.cmake3
-rw-r--r--Modules/CheckSourceRuns.cmake3
-rw-r--r--Tests/CMakeOnly/CMakeLists.txt5
-rw-r--r--Tests/CMakeOnly/CompilerIdCUDA/CMakeLists.txt14
-rw-r--r--Tests/RunCMake/CMakeLists.txt12
-rw-r--r--Tests/RunCMake/CheckCompilerFlag/CheckCUDACompilerFlag.cmake13
-rw-r--r--Tests/RunCMake/CheckCompilerFlag/RunCMakeTest.cmake4
-rw-r--r--Tests/RunCMake/CheckSourceCompiles/CheckCUDASourceCompiles.cmake27
-rw-r--r--Tests/RunCMake/CheckSourceCompiles/RunCMakeTest.cmake4
-rw-r--r--Tests/RunCMake/CheckSourceRuns/CheckCUDASourceRuns.cmake21
-rw-r--r--Tests/RunCMake/CheckSourceRuns/RunCMakeTest.cmake4
13 files changed, 122 insertions, 3 deletions
diff --git a/Help/release/dev/cuda-check-support.rst b/Help/release/dev/cuda-check-support.rst
new file mode 100644
index 0000000000..50a42d60da
--- /dev/null
+++ b/Help/release/dev/cuda-check-support.rst
@@ -0,0 +1,11 @@
+cuda-check-support
+------------------
+
+* The :module:`CheckCompilerFlag` module was extended to
+ support 'CUDA'.
+
+* The :module:`CheckSourceCompiles` module was extended to
+ support 'CUDA'.
+
+* The :module:`CheckSourceRuns` module was extended to
+ support 'CUDA'.
diff --git a/Modules/CheckCompilerFlag.cmake b/Modules/CheckCompilerFlag.cmake
index f2385d5e13..3ce1b9bd72 100644
--- a/Modules/CheckCompilerFlag.cmake
+++ b/Modules/CheckCompilerFlag.cmake
@@ -49,6 +49,10 @@ function(CHECK_COMPILER_FLAG _lang _flag _var)
elseif(_lang STREQUAL CXX)
set(_lang_src "int main() { return 0; }")
set(_lang_fail_regex FAIL_REGEX "command[ -]line option .* is valid for .* but not for C\\+\\+")
+ elseif(_lang STREQUAL CUDA)
+ set(_lang_src "__host__ int main() { return 0; }")
+ set(_lang_fail_regex FAIL_REGEX "command[ -]line option .* is valid for .* but not for C\\+\\+" # Host GNU
+ FAIL_REGEX "argument unused during compilation: .*") # Clang
elseif(_lang STREQUAL Fortran)
set(_lang_src " program test\n stop\n end program")
set(_lang_fail_regex FAIL_REGEX "command[ -]line option .* is valid for .* but not for Fortran")
diff --git a/Modules/CheckSourceCompiles.cmake b/Modules/CheckSourceCompiles.cmake
index 70a733d32a..08fc153499 100644
--- a/Modules/CheckSourceCompiles.cmake
+++ b/Modules/CheckSourceCompiles.cmake
@@ -89,6 +89,9 @@ function(CHECK_SOURCE_COMPILES _lang _source _var)
elseif(_lang STREQUAL CXX)
set(_lang_textual "C++")
set(_lang_ext "cxx")
+ elseif(_lang STREQUAL CUDA)
+ set(_lang_textual "CUDA")
+ set(_lang_ext "cu")
elseif(_lang STREQUAL Fortran)
set(_lang_textual "Fortran")
set(_lang_ext "F")
diff --git a/Modules/CheckSourceRuns.cmake b/Modules/CheckSourceRuns.cmake
index 61651231aa..20f3e1e09f 100644
--- a/Modules/CheckSourceRuns.cmake
+++ b/Modules/CheckSourceRuns.cmake
@@ -87,6 +87,9 @@ function(CHECK_SOURCE_RUNS _lang _source _var)
elseif(_lang STREQUAL CXX)
set(_lang_textual "C++")
set(_lang_ext "cxx")
+ elseif(_lang STREQUAL CUDA)
+ set(_lang_textual "CUDA")
+ set(_lang_ext "cu")
elseif(_lang STREQUAL Fortran)
set(_lang_textual "Fortran")
set(_lang_ext "F")
diff --git a/Tests/CMakeOnly/CMakeLists.txt b/Tests/CMakeOnly/CMakeLists.txt
index 361cf5f2cc..a41b44ed92 100644
--- a/Tests/CMakeOnly/CMakeLists.txt
+++ b/Tests/CMakeOnly/CMakeLists.txt
@@ -38,6 +38,11 @@ if (APPLE AND CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
add_CMakeOnly_test(CheckOBJCXXCompilerFlag)
endif()
+if(CMake_TEST_CUDA)
+ add_CMakeOnly_test(CompilerIdCUDA)
+endif()
+
+
if(CMAKE_Fortran_COMPILER)
add_CMakeOnly_test(CompilerIdFortran)
endif()
diff --git a/Tests/CMakeOnly/CompilerIdCUDA/CMakeLists.txt b/Tests/CMakeOnly/CompilerIdCUDA/CMakeLists.txt
new file mode 100644
index 0000000000..da14000249
--- /dev/null
+++ b/Tests/CMakeOnly/CompilerIdCUDA/CMakeLists.txt
@@ -0,0 +1,14 @@
+cmake_minimum_required(VERSION 3.18)
+project(CompilerIdCUDA CUDA)
+
+foreach(v
+ CMAKE_CUDA_COMPILER
+ CMAKE_CUDA_COMPILER_ID
+ CMAKE_CUDA_COMPILER_VERSION
+ )
+ if(${v})
+ message(STATUS "${v}=[${${v}}]")
+ else()
+ message(SEND_ERROR "${v} not set!")
+ endif()
+endforeach()
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
index 557808ed2a..68bd0d9147 100644
--- a/Tests/RunCMake/CMakeLists.txt
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -538,9 +538,15 @@ add_RunCMake_test(target_compile_features)
add_RunCMake_test(target_compile_options -DCMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_ID})
add_RunCMake_test(target_include_directories)
add_RunCMake_test(target_sources)
-add_RunCMake_test(CheckCompilerFlag)
-add_RunCMake_test(CheckSourceCompiles -DCMake_TEST_ISPC=${CMake_TEST_ISPC})
-add_RunCMake_test(CheckSourceRuns)
+add_RunCMake_test(CheckCompilerFlag -DCMake_TEST_CUDA=${CMake_TEST_CUDA}
+ -DCMake_TEST_ISPC=${CMake_TEST_ISPC})
+add_RunCMake_test(CheckSourceCompiles -DCMake_TEST_CUDA=${CMake_TEST_CUDA}
+ -DCMake_TEST_ISPC=${CMake_TEST_ISPC})
+add_RunCMake_test(CheckSourceRuns -DCMake_TEST_CUDA=${CMake_TEST_CUDA})
+set_property(TEST RunCMake.CheckCompilerFlag
+ RunCMake.CheckSourceCompiles
+ RunCMake.CheckSourceRuns
+ APPEND PROPERTY LABELS "CUDA")
set_property(TEST RunCMake.CheckSourceCompiles
RunCMake.CheckCompilerFlag
APPEND PROPERTY LABELS "ISPC")
diff --git a/Tests/RunCMake/CheckCompilerFlag/CheckCUDACompilerFlag.cmake b/Tests/RunCMake/CheckCompilerFlag/CheckCUDACompilerFlag.cmake
new file mode 100644
index 0000000000..a40699cad9
--- /dev/null
+++ b/Tests/RunCMake/CheckCompilerFlag/CheckCUDACompilerFlag.cmake
@@ -0,0 +1,13 @@
+
+enable_language (CUDA)
+include(CheckCompilerFlag)
+
+check_compiler_flag(CUDA "-_this_is_not_a_flag_" SHOULD_FAIL)
+if(SHOULD_FAIL)
+ message(SEND_ERROR "invalid CUDA compile flag didn't fail.")
+endif()
+
+check_compiler_flag(CUDA "-DFOO" SHOULD_WORK)
+if(NOT SHOULD_WORK)
+ message(SEND_ERROR "${CMAKE_CUDA_COMPILER_ID} compiler flag '-DFOO' check failed")
+endif()
diff --git a/Tests/RunCMake/CheckCompilerFlag/RunCMakeTest.cmake b/Tests/RunCMake/CheckCompilerFlag/RunCMakeTest.cmake
index e4d65b836d..7a4e2cebb6 100644
--- a/Tests/RunCMake/CheckCompilerFlag/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CheckCompilerFlag/RunCMakeTest.cmake
@@ -15,6 +15,10 @@ if (CMAKE_Fortran_COMPILER_ID)
run_cmake(CheckFortranCompilerFlag)
endif()
+if (CMake_TEST_CUDA)
+ run_cmake(CheckCUDACompilerFlag)
+endif()
+
if(CMake_TEST_ISPC)
run_cmake(CheckISPCCompilerFlag)
endif()
diff --git a/Tests/RunCMake/CheckSourceCompiles/CheckCUDASourceCompiles.cmake b/Tests/RunCMake/CheckSourceCompiles/CheckCUDASourceCompiles.cmake
new file mode 100644
index 0000000000..1e6e6b266b
--- /dev/null
+++ b/Tests/RunCMake/CheckSourceCompiles/CheckCUDASourceCompiles.cmake
@@ -0,0 +1,27 @@
+
+enable_language (CUDA)
+include(CheckSourceCompiles)
+
+check_source_compiles(CUDA "I don't build" SHOULD_FAIL)
+if(SHOULD_FAIL)
+ message(SEND_ERROR "invalid CUDA source didn't fail.")
+endif()
+
+check_source_compiles(CUDA [=[
+ #include <vector>
+ __device__ int d_func() { }
+ int main() {
+ return 0;
+ }
+]=]
+ SHOULD_BUILD)
+if(NOT SHOULD_BUILD)
+ message(SEND_ERROR "Test fail for valid CUDA source.")
+endif()
+
+check_source_compiles(CUDA "void l(char const (&x)[2]){}; int main() { l(\"\\n\"); return 0;}"
+ SHOULD_BUILD_COMPLEX)
+
+if(NOT SHOULD_BUILD_COMPLEX)
+ message(SEND_ERROR "Test fail for valid CUDA complex source.")
+endif()
diff --git a/Tests/RunCMake/CheckSourceCompiles/RunCMakeTest.cmake b/Tests/RunCMake/CheckSourceCompiles/RunCMakeTest.cmake
index a574d7d101..22cb4661b9 100644
--- a/Tests/RunCMake/CheckSourceCompiles/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CheckSourceCompiles/RunCMakeTest.cmake
@@ -15,6 +15,10 @@ if (CMAKE_Fortran_COMPILER_ID)
run_cmake(CheckFortranSourceCompiles)
endif()
+if (CMake_TEST_CUDA)
+ run_cmake(CheckCUDASourceCompiles)
+endif()
+
if(CMake_TEST_ISPC)
run_cmake(CheckISPCSourceCompiles)
endif()
diff --git a/Tests/RunCMake/CheckSourceRuns/CheckCUDASourceRuns.cmake b/Tests/RunCMake/CheckSourceRuns/CheckCUDASourceRuns.cmake
new file mode 100644
index 0000000000..01e5ac83c8
--- /dev/null
+++ b/Tests/RunCMake/CheckSourceRuns/CheckCUDASourceRuns.cmake
@@ -0,0 +1,21 @@
+
+enable_language (CUDA)
+include(CheckSourceRuns)
+
+check_source_runs(CUDA "int main() {return 2;}" SHOULD_FAIL)
+if(SHOULD_FAIL)
+ message(SEND_ERROR "CUDA check_source_runs succeeded, but should have failed.")
+endif()
+
+check_source_runs(CUDA
+[=[
+ #include <vector>
+ __device__ __host__ void fake_function();
+ __host__ int main() {
+ return 0;
+ }
+]=]
+ SHOULD_RUN)
+if(NOT SHOULD_RUN)
+ message(SEND_ERROR "CUDA check_source_runs failed for valid CUDA executable.")
+endif()
diff --git a/Tests/RunCMake/CheckSourceRuns/RunCMakeTest.cmake b/Tests/RunCMake/CheckSourceRuns/RunCMakeTest.cmake
index 8bcde6aa04..b27b08daa2 100644
--- a/Tests/RunCMake/CheckSourceRuns/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CheckSourceRuns/RunCMakeTest.cmake
@@ -14,3 +14,7 @@ endif()
if (CMAKE_Fortran_COMPILER_ID)
run_cmake(CheckFortranSourceRuns)
endif()
+
+if (CMake_TEST_CUDA)
+ run_cmake(CheckCUDASourceRuns)
+endif()