From 3e04ed22274569fcca731830c7673fbb87018776 Mon Sep 17 00:00:00 2001 From: Zhou Wei <52485244+zhouwei25@users.noreply.github.com> Date: Wed, 10 Jun 2020 12:03:13 +0800 Subject: [PATCH] fix bug in CUDA_NVCC_FALS and CMAKE_CUDA_FLAGS, and eliminate some warning,test=develop (#24982) fix bug in CUDA_NVCC_FALS and CMAKE_CUDA_FLAGS --- cmake/cuda.cmake | 28 ++++++++++++++++------------ cmake/flags.cmake | 6 ++++-- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/cmake/cuda.cmake b/cmake/cuda.cmake index 38eab3597b6..ac6dab86fd3 100644 --- a/cmake/cuda.cmake +++ b/cmake/cuda.cmake @@ -213,24 +213,28 @@ set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -w") # Set :expt-relaxed-constexpr to suppress Eigen warnings set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-relaxed-constexpr") -if (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(WIN32) + set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler \"/wd4244 /wd4267 /wd4819 \"") + set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler /bigobj") if(CMAKE_BUILD_TYPE STREQUAL "Debug") - list(APPEND CUDA_NVCC_FLAGS "-g -G") # match the cl's _ITERATOR_DEBUG_LEVEL - list(APPEND CUDA_NVCC_FLAGS "-D_DEBUG") + set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler \"-g -G -D_DEBUG\"") + if(MSVC_STATIC_CRT) + set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler /MTd") + else() + set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler /MDd") + endif() elseif(CMAKE_BUILD_TYPE STREQUAL "Release") - list(APPEND CUDA_NVCC_FLAGS "-O3 -DNDEBUG") + set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler \"-DNDEBUG\"") + if(MSVC_STATIC_CRT) + set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler /MT") + else() + set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler /MD") + endif() else() message(FATAL "Windows only support Release or Debug build now. Please set visual studio build type to Release/Debug, x64 build.") endif() -endif(WIN32) +endif() mark_as_advanced(CUDA_BUILD_CUBIN CUDA_BUILD_EMULATION CUDA_VERBOSE_BUILD) mark_as_advanced(CUDA_SDK_ROOT_DIR CUDA_SEPARABLE_COMPILATION) diff --git a/cmake/flags.cmake b/cmake/flags.cmake index 9b04ad913b0..0c12846efe5 100644 --- a/cmake/flags.cmake +++ b/cmake/flags.cmake @@ -220,9 +220,11 @@ endforeach() set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} ${SAFE_GPU_COMMON_FLAGS}") -if(WIN32 AND MSVC_STATIC_CRT) +if(WIN32) # windows build turn off warnings. - safe_set_static_flag() + if(MSVC_STATIC_CRT) + safe_set_static_flag() + endif() foreach(flag_var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO -- GitLab