Merge topic 'check_cuda_helpers'

5c66ac31e6 CUDA: CheckLinkerFlag now supports CUDA
da2622ff36 CUDA: Add Support to SourceCompiles|Runs and CheckCompilerFlags

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5338
This commit is contained in:
Brad King
2020-10-08 13:21:57 +00:00
committed by Kitware Robot
16 changed files with 137 additions and 4 deletions

View File

@@ -0,0 +1,14 @@
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'.
* The :module:`CheckLinkerFlag` module has been extended to
support the validity of CUDA link flags.

View File

@@ -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")

View File

@@ -66,6 +66,8 @@ function(CHECK_LINKER_FLAG _lang _flag _var)
set (_source "int main() { return 0; }")
elseif (_lang STREQUAL "Fortran")
set (_source " program test\n stop\n end program")
elseif (_lang MATCHES "CUDA")
set (_source "__host__ int main() { return 0; }")
elseif (_lang MATCHES "^(OBJC|OBJCXX)$")
set (_source "#ifndef __OBJC__\n# error \"Not an Objective-C++ compiler\"\n#endif\nint main(void) { return 0; }")
else()

View File

@@ -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")

View File

@@ -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")

View File

@@ -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()

View File

@@ -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()

View File

@@ -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")
@@ -549,7 +555,9 @@ add_RunCMake_test(CheckIPOSupported)
if (CMAKE_SYSTEM_NAME MATCHES "(Linux|Darwin)"
AND (CMAKE_C_COMPILER_ID MATCHES "Clang|GNU" OR CMAKE_Fortran_COMPILER_ID MATCHES "GNU"))
add_RunCMake_test(CheckLinkerFlag -DCMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_ID}
-DCMAKE_Fortran_COMPILER_ID=${CMAKE_Fortran_COMPILER_ID})
-DCMAKE_Fortran_COMPILER_ID=${CMAKE_Fortran_COMPILER_ID}
-DCMake_TEST_CUDA=${CMake_TEST_CUDA})
set_property(TEST RunCMake.CheckLinkerFlag APPEND PROPERTY LABELS "CUDA")
endif()

View File

@@ -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()

View File

@@ -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()

View File

@@ -0,0 +1,3 @@
set (CHECK_LANGUAGE CUDA)
include ("${CMAKE_CURRENT_SOURCE_DIR}/CheckLinkerFlag.cmake")

View File

@@ -12,3 +12,7 @@ endif()
if (CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
run_cmake(CheckFortranLinkerFlag)
endif()
if (CMake_TEST_CUDA)
run_cmake(CheckCUDALinkerFlag)
endif()

View File

@@ -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()

View File

@@ -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()

View File

@@ -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()

View File

@@ -14,3 +14,7 @@ endif()
if (CMAKE_Fortran_COMPILER_ID)
run_cmake(CheckFortranSourceRuns)
endif()
if (CMake_TEST_CUDA)
run_cmake(CheckCUDASourceRuns)
endif()