浏览代码

CUDA: Link to standard system libraries when linking as CUDA

On Windows with MSVC-like host compilers we must honor the standard
libraries chosen by the `Platform/Windows-MSVC` module.  Otherwise C
code linked into the CUDA binary that expects to have these libraries
available may not link.
Brad King 8 年之前
父节点
当前提交
1c60231ca5
共有 3 个文件被更改,包括 16 次插入0 次删除
  1. 6 0
      Modules/CMakeCUDAInformation.cmake
  2. 2 0
      Modules/Platform/Windows-NVIDIA-CUDA.cmake
  3. 8 0
      Tests/Cuda/WithC/main.c

+ 6 - 0
Modules/CMakeCUDAInformation.cmake

@@ -93,6 +93,12 @@ if(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
 
 
 endif()
 endif()
 
 
+if(CMAKE_CUDA_STANDARD_LIBRARIES_INIT)
+  set(CMAKE_CUDA_STANDARD_LIBRARIES "${CMAKE_CUDA_STANDARD_LIBRARIES_INIT}"
+    CACHE STRING "Libraries linked by default with all CUDA applications.")
+  mark_as_advanced(CMAKE_CUDA_STANDARD_LIBRARIES)
+endif()
+
 include(CMakeCommonLanguageInclude)
 include(CMakeCommonLanguageInclude)
 
 
 # now define the following rules:
 # now define the following rules:

+ 2 - 0
Modules/Platform/Windows-NVIDIA-CUDA.cmake

@@ -40,3 +40,5 @@ string(APPEND CMAKE_CUDA_FLAGS_DEBUG_INIT " -Xcompiler=-MDd,-Zi,-RTC1")
 string(APPEND CMAKE_CUDA_FLAGS_RELEASE_INIT " -Xcompiler=-MD")
 string(APPEND CMAKE_CUDA_FLAGS_RELEASE_INIT " -Xcompiler=-MD")
 string(APPEND CMAKE_CUDA_FLAGS_RELWITHDEBINFO_INIT " -Xcompiler=-MD")
 string(APPEND CMAKE_CUDA_FLAGS_RELWITHDEBINFO_INIT " -Xcompiler=-MD")
 string(APPEND CMAKE_CUDA_FLAGS_MINSIZEREL_INIT " -Xcompiler=-MD")
 string(APPEND CMAKE_CUDA_FLAGS_MINSIZEREL_INIT " -Xcompiler=-MD")
+
+set(CMAKE_CUDA_STANDARD_LIBRARIES_INIT "${CMAKE_C_STANDARD_LIBRARIES_INIT}")

+ 8 - 0
Tests/Cuda/WithC/main.c

@@ -1,6 +1,14 @@
 extern int use_cuda(void);
 extern int use_cuda(void);
 
 
+#ifdef _WIN32
+#include <windows.h>
+#endif
+
 int main()
 int main()
 {
 {
+#ifdef _WIN32
+  /* Use an API that requires CMake's "standard" C libraries.  */
+  GetOpenFileName(NULL);
+#endif
   return use_cuda();
   return use_cuda();
 }
 }