浏览代码

Merge topic 'cuda-msvc-runtime-library'

8fbd25772f CUDA: Implement MSVC runtime library abstraction
07807a2006 VS: Use AddLanguageFlags to de-duplicate CMAKE_{CUDA,ASM*}_FLAGS lookup

Acked-by: Kitware Robot <[email protected]>
Merge-request: !3485
Brad King 6 年之前
父节点
当前提交
6ddc0b4438

+ 19 - 4
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}")
 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)
 cmake_policy(GET CMP0092 _cmp0092)
 if(_cmp0092 STREQUAL "NEW")
 if(_cmp0092 STREQUAL "NEW")
   set(_W3 "")
   set(_W3 "")
@@ -69,11 +77,18 @@ endif()
 unset(_cmp0092)
 unset(_cmp0092)
 
 
 string(APPEND CMAKE_CUDA_FLAGS_INIT " ${PLATFORM_DEFINES_CUDA} -D_WINDOWS -Xcompiler=\"${_W3}${_FLAGS_CXX}\"")
 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(_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}")
 set(CMAKE_CUDA_STANDARD_LIBRARIES_INIT "${CMAKE_C_STANDARD_LIBRARIES_INIT}")
 
 

+ 11 - 15
Source/cmVisualStudio10TargetGenerator.cxx

@@ -2915,10 +2915,9 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaOptions(
   Options& cudaOptions = *pOptions;
   Options& cudaOptions = *pOptions;
 
 
   // Get compile flags for CUDA in this directory.
   // Get compile flags for CUDA in this directory.
-  std::string CONFIG = cmSystemTools::UpperCase(configName);
-  std::string configFlagsVar = "CMAKE_CUDA_FLAGS_" + CONFIG;
-  std::string flags = this->Makefile->GetSafeDefinition("CMAKE_CUDA_FLAGS") +
-    " " + this->Makefile->GetSafeDefinition(configFlagsVar);
+  std::string flags;
+  this->LocalGenerator->AddLanguageFlags(flags, this->GeneratorTarget, "CUDA",
+                                         configName);
   this->LocalGenerator->AddCompileOptions(flags, this->GeneratorTarget, "CUDA",
   this->LocalGenerator->AddCompileOptions(flags, this->GeneratorTarget, "CUDA",
                                           configName);
                                           configName);
 
 
@@ -3119,11 +3118,9 @@ bool cmVisualStudio10TargetGenerator::ComputeMasmOptions(
     this->LocalGenerator, Options::MasmCompiler, gg->GetMasmFlagTable());
     this->LocalGenerator, Options::MasmCompiler, gg->GetMasmFlagTable());
   Options& masmOptions = *pOptions;
   Options& masmOptions = *pOptions;
 
 
-  std::string CONFIG = cmSystemTools::UpperCase(configName);
-  std::string configFlagsVar = "CMAKE_ASM_MASM_FLAGS_" + CONFIG;
-  std::string flags =
-    this->Makefile->GetSafeDefinition("CMAKE_ASM_MASM_FLAGS") + " " +
-    this->Makefile->GetSafeDefinition(configFlagsVar);
+  std::string flags;
+  this->LocalGenerator->AddLanguageFlags(flags, this->GeneratorTarget,
+                                         "ASM_MASM", configName);
 
 
   masmOptions.Parse(flags);
   masmOptions.Parse(flags);
 
 
@@ -3173,12 +3170,11 @@ bool cmVisualStudio10TargetGenerator::ComputeNasmOptions(
     this->LocalGenerator, Options::NasmCompiler, gg->GetNasmFlagTable());
     this->LocalGenerator, Options::NasmCompiler, gg->GetNasmFlagTable());
   Options& nasmOptions = *pOptions;
   Options& nasmOptions = *pOptions;
 
 
-  std::string CONFIG = cmSystemTools::UpperCase(configName);
-  std::string configFlagsVar = "CMAKE_ASM_NASM_FLAGS_" + CONFIG;
-  std::string flags =
-    this->Makefile->GetSafeDefinition("CMAKE_ASM_NASM_FLAGS") + " -f" +
-    this->Makefile->GetSafeDefinition("CMAKE_ASM_NASM_OBJECT_FORMAT") + " " +
-    this->Makefile->GetSafeDefinition(configFlagsVar);
+  std::string flags;
+  this->LocalGenerator->AddLanguageFlags(flags, this->GeneratorTarget,
+                                         "ASM_NASM", configName);
+  flags += " -f";
+  flags += this->Makefile->GetSafeDefinition("CMAKE_ASM_NASM_OBJECT_FORMAT");
   nasmOptions.Parse(flags);
   nasmOptions.Parse(flags);
 
 
   // Get includes for this target
   // Get includes for this target

+ 1 - 0
Tests/CMakeLists.txt

@@ -1883,6 +1883,7 @@ ${CMake_SOURCE_DIR}/Utilities/Release/push.bash --dir dev -- '${CMake_BUILD_NIGH
     if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
     if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
       ADD_TEST_MACRO(PrecompiledHeader foo)
       ADD_TEST_MACRO(PrecompiledHeader foo)
     endif()
     endif()
+    set(MSVCRuntimeLibrary_BUILD_OPTIONS -DCMake_TEST_CUDA=${CMake_TEST_CUDA})
     ADD_TEST_MACRO(MSVCRuntimeLibrary)
     ADD_TEST_MACRO(MSVCRuntimeLibrary)
     if(CMAKE_Fortran_COMPILER)
     if(CMAKE_Fortran_COMPILER)
       ADD_TEST_MACRO(MSVCRuntimeLibrary.Fortran)
       ADD_TEST_MACRO(MSVCRuntimeLibrary.Fortran)

+ 7 - 0
Tests/MSVCRuntimeLibrary/CMakeLists.txt

@@ -2,6 +2,10 @@ cmake_minimum_required(VERSION 3.14)
 cmake_policy(SET CMP0091 NEW)
 cmake_policy(SET CMP0091 NEW)
 project(MSVCRuntimeLibrary)
 project(MSVCRuntimeLibrary)
 
 
+if(CMake_TEST_CUDA)
+  enable_language(CUDA)
+endif()
+
 function(verify_combinations threads lang src)
 function(verify_combinations threads lang src)
   set(verify_tc_config_ Release)
   set(verify_tc_config_ Release)
   set(verify_tc_config_Debug Debug)
   set(verify_tc_config_Debug Debug)
@@ -62,3 +66,6 @@ endfunction()
 
 
 verify(C verify.c)
 verify(C verify.c)
 verify(CXX verify.cxx)
 verify(CXX verify.cxx)
+if(CMake_TEST_CUDA)
+  verify(CUDA verify.cu)
+endif()

+ 1 - 0
Tests/MSVCRuntimeLibrary/verify.cu

@@ -0,0 +1 @@
+#include "verify.h"