From 343687c3263bfe3cd2c4807ada039a0c350535e7 Mon Sep 17 00:00:00 2001 From: Zhou Wei <52485244+zhouwei25@users.noreply.github.com> Date: Tue, 2 Jun 2020 11:03:08 +0800 Subject: [PATCH] [CHERRY-PICK 1.8]fix windows bug that compile .cu files use MSVC dynamic C runtime (#24826) * cherry-pick #24729 --- cmake/cuda.cmake | 11 ++++++++--- cmake/flags.cmake | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/cmake/cuda.cmake b/cmake/cuda.cmake index 514937f760d..e069c799b4b 100644 --- a/cmake/cuda.cmake +++ b/cmake/cuda.cmake @@ -202,9 +202,9 @@ set(CUDA_PROPAGATE_HOST_FLAGS OFF) # Release/Debug flags set by cmake. Such as -O3 -g -DNDEBUG etc. # So, don't set these flags here. if (NOT WIN32) # windows msvc2015 support c++11 natively. -# -std=c++11 -fPIC not recoginize by msvc, -Xcompiler will be added by cmake. -list(APPEND CUDA_NVCC_FLAGS "-std=c++11") -list(APPEND CUDA_NVCC_FLAGS "-Xcompiler -fPIC") + # -std=c++11 -fPIC not recoginize by msvc, -Xcompiler will be added by cmake. + list(APPEND CUDA_NVCC_FLAGS "-std=c++11") + list(APPEND CUDA_NVCC_FLAGS "-Xcompiler -fPIC") endif(NOT WIN32) # in cuda9, suppress cuda warning on eigen @@ -226,6 +226,11 @@ if (NOT WIN32) else(NOT WIN32) list(APPEND CUDA_NVCC_FLAGS "-Xcompiler \"/wd 4244 /wd 4267 /wd 4819\"") list(APPEND CUDA_NVCC_FLAGS "--compiler-options;/bigobj") + if(MSVC_STATIC_CRT) + list(APPEND CUDA_NVCC_FLAGS "-Xcompiler" "-MT$<$:d>") + else() + list(APPEND CUDA_NVCC_FLAGS "-Xcompiler" "-MD$<$:d>") + endif() if(CMAKE_BUILD_TYPE STREQUAL "Debug") list(APPEND CUDA_NVCC_FLAGS "-g -G") # match the cl's _ITERATOR_DEBUG_LEVEL diff --git a/cmake/flags.cmake b/cmake/flags.cmake index 884e5d45a6a..f3a0660900b 100644 --- a/cmake/flags.cmake +++ b/cmake/flags.cmake @@ -217,8 +217,8 @@ foreach(flag ${GPU_COMMON_FLAGS}) endforeach() if(WIN32 AND MSVC_STATIC_CRT) -# windows build turn off warnings. -safe_set_static_flag() + # windows build turn off warnings. + safe_set_static_flag() foreach(flag_var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO -- GitLab