From 8fbd25772f7db4c6f152a28b0050e6b263951049 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 26 Jun 2019 07:41:21 -0400 Subject: CUDA: Implement MSVC runtime library abstraction In commit fb3370b6a1 (MSVC: Add abstraction for runtime library selection, 2019-04-10, v3.15.0-rc1~229^2) we overlooked updating flags for CUDA on Windows, where nvcc uses MSVC as the host compiler. Add them now and update the MSVCRuntimeLibrary test to cover CUDA. Fixes: #19428 --- Modules/Platform/Windows-NVIDIA-CUDA.cmake | 23 +++++++++++++++++++---- Tests/CMakeLists.txt | 1 + Tests/MSVCRuntimeLibrary/CMakeLists.txt | 7 +++++++ Tests/MSVCRuntimeLibrary/verify.cu | 1 + 4 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 Tests/MSVCRuntimeLibrary/verify.cu diff --git a/Modules/Platform/Windows-NVIDIA-CUDA.cmake b/Modules/Platform/Windows-NVIDIA-CUDA.cmake index f160c7b..94d77b9 100644 --- a/Modules/Platform/Windows-NVIDIA-CUDA.cmake +++ b/Modules/Platform/Windows-NVIDIA-CUDA.cmake @@ -60,6 +60,14 @@ unset(__IMPLICT_DLINK_FLAGS) string(REPLACE "/D" "-D" _PLATFORM_DEFINES_CUDA "${_PLATFORM_DEFINES}${_PLATFORM_DEFINES_CXX}") +if(CMAKE_MSVC_RUNTIME_LIBRARY_DEFAULT) + set(_MDd "") + set(_MD "") +else() + set(_MDd "-MDd ") + set(_MD "-MD ") +endif() + cmake_policy(GET CMP0092 _cmp0092) if(_cmp0092 STREQUAL "NEW") set(_W3 "") @@ -69,11 +77,18 @@ endif() unset(_cmp0092) string(APPEND CMAKE_CUDA_FLAGS_INIT " ${PLATFORM_DEFINES_CUDA} -D_WINDOWS -Xcompiler=\"${_W3}${_FLAGS_CXX}\"") -string(APPEND CMAKE_CUDA_FLAGS_DEBUG_INIT " -Xcompiler=\"-MDd -Zi -Ob0 -Od ${_RTC1}\"") -string(APPEND CMAKE_CUDA_FLAGS_RELEASE_INIT " -Xcompiler=\"-MD -O2 -Ob2\" -DNDEBUG") -string(APPEND CMAKE_CUDA_FLAGS_RELWITHDEBINFO_INIT " -Xcompiler=\"-MD -Zi -O2 -Ob1\" -DNDEBUG") -string(APPEND CMAKE_CUDA_FLAGS_MINSIZEREL_INIT " -Xcompiler=\"-MD -O1 -Ob1\" -DNDEBUG") +string(APPEND CMAKE_CUDA_FLAGS_DEBUG_INIT " -Xcompiler=\"${_MDd}-Zi -Ob0 -Od ${_RTC1}\"") +string(APPEND CMAKE_CUDA_FLAGS_RELEASE_INIT " -Xcompiler=\"${_MD}-O2 -Ob2\" -DNDEBUG") +string(APPEND CMAKE_CUDA_FLAGS_RELWITHDEBINFO_INIT " -Xcompiler=\"${_MD}-Zi -O2 -Ob1\" -DNDEBUG") +string(APPEND CMAKE_CUDA_FLAGS_MINSIZEREL_INIT " -Xcompiler=\"${_MD}-O1 -Ob1\" -DNDEBUG") unset(_W3) +unset(_MDd) +unset(_MD) + +set(CMAKE_CUDA_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreaded -Xcompiler=-MT) +set(CMAKE_CUDA_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL -Xcompiler=-MD) +set(CMAKE_CUDA_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebug -Xcompiler=-MTd) +set(CMAKE_CUDA_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebugDLL -Xcompiler=-MDd) set(CMAKE_CUDA_STANDARD_LIBRARIES_INIT "${CMAKE_C_STANDARD_LIBRARIES_INIT}") diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 920af04..e73b277 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -2001,6 +2001,7 @@ ${CMake_SOURCE_DIR}/Utilities/Release/push.bash --dir dev -- '${CMake_BUILD_NIGH if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang") ADD_TEST_MACRO(PrecompiledHeader foo) endif() + set(MSVCRuntimeLibrary_BUILD_OPTIONS -DCMake_TEST_CUDA=${CMake_TEST_CUDA}) ADD_TEST_MACRO(MSVCRuntimeLibrary) if(CMAKE_Fortran_COMPILER) ADD_TEST_MACRO(MSVCRuntimeLibrary.Fortran) diff --git a/Tests/MSVCRuntimeLibrary/CMakeLists.txt b/Tests/MSVCRuntimeLibrary/CMakeLists.txt index 6994d8d..f7d9fec 100644 --- a/Tests/MSVCRuntimeLibrary/CMakeLists.txt +++ b/Tests/MSVCRuntimeLibrary/CMakeLists.txt @@ -2,6 +2,10 @@ cmake_minimum_required(VERSION 3.14) cmake_policy(SET CMP0091 NEW) project(MSVCRuntimeLibrary) +if(CMake_TEST_CUDA) + enable_language(CUDA) +endif() + function(verify_combinations threads lang src) set(verify_tc_config_ Release) set(verify_tc_config_Debug Debug) @@ -62,3 +66,6 @@ endfunction() verify(C verify.c) verify(CXX verify.cxx) +if(CMake_TEST_CUDA) + verify(CUDA verify.cu) +endif() diff --git a/Tests/MSVCRuntimeLibrary/verify.cu b/Tests/MSVCRuntimeLibrary/verify.cu new file mode 100644 index 0000000..741bca6 --- /dev/null +++ b/Tests/MSVCRuntimeLibrary/verify.cu @@ -0,0 +1 @@ +#include "verify.h" -- cgit v0.12