Przeglądaj źródła

Merge topic 'cuda-nvcc-system-includes' into release-4.0

d2be863b5e CUDA: Add include paths from nvcc SYSTEM_INCLUDES entry

Acked-by: Kitware Robot <[email protected]>
Merge-request: !10857
Brad King 7 miesięcy temu
rodzic
commit
dc646156d0

+ 13 - 1
Modules/FindCUDAToolkit.cmake

@@ -694,9 +694,21 @@ else()
             get_filename_component(line "${line}" ABSOLUTE)
             list(APPEND _cmake_CUDAToolkit_include_directories "${line}")
           endforeach()
+        endif()
+        if(_CUDA_NVCC_OUT MATCHES "\\#\\$ SYSTEM_INCLUDES=([^\r\n]*)")
+          unset(_nvcc_output)
+          separate_arguments(_nvcc_output NATIVE_COMMAND "${CMAKE_MATCH_1}")
+          foreach(line IN LISTS _nvcc_output)
+            string(REGEX REPLACE "^-isystem" "" line "${line}")
+            if(line)
+              get_filename_component(line "${line}" ABSOLUTE)
+              list(APPEND _cmake_CUDAToolkit_include_directories "${line}")
+            endif()
+          endforeach()
+        endif()
+        if(DEFINED _cmake_CUDAToolkit_include_directories)
           message(CONFIGURE_LOG
             "Parsed CUDAToolkit nvcc implicit include information:\n${_cmake_CUDAToolkit_include_directories}\n\n")
-
           set(_cmake_CUDAToolkit_include_directories "${_cmake_CUDAToolkit_include_directories}" CACHE INTERNAL "CUDAToolkit internal list of include directories")
         endif()
         if(_CUDA_NVCC_OUT MATCHES "\\#\\$ LIBRARIES=([^\r\n]*)")

+ 20 - 1
Modules/Internal/CMakeNVCCParseImplicitInfo.cmake

@@ -29,6 +29,14 @@ macro(cmake_nvcc_parse_implicit_info lang lang_var_)
     string(REPLACE "\n" "\n    " _nvcc_output_log "\n${_nvcc_output_orig}")
     string(APPEND _nvcc_log "  no 'INCLUDES=' string found in nvcc output:${_nvcc_output_log}\n")
   endif()
+  if(_nvcc_output_orig MATCHES "#\\\$ +SYSTEM_INCLUDES= *([^\n]*)\n")
+    set(_nvcc_system_includes "${CMAKE_MATCH_1}")
+    string(APPEND _nvcc_log "  found 'SYSTEM_INCLUDES=' string: [${_nvcc_system_includes}]\n")
+  else()
+    set(_nvcc_system_includes "")
+    string(REPLACE "\n" "\n    " _nvcc_output_log "\n${_nvcc_output_orig}")
+    string(APPEND _nvcc_log "  no 'SYSTEM_INCLUDES=' string found in nvcc output:${_nvcc_output_log}\n")
+  endif()
   string(REGEX MATCHALL "-arch compute_([0-9]+)" _nvcc_target_cpus "${_nvcc_output_orig}")
   foreach(_nvcc_target_cpu ${_nvcc_target_cpus})
     if(_nvcc_target_cpu MATCHES "-arch compute_([0-9]+)")
@@ -134,7 +142,7 @@ macro(cmake_nvcc_parse_implicit_info lang lang_var_)
   endif()
 
   set(${lang_var_}TOOLKIT_INCLUDE_DIRECTORIES)
-  if(_nvcc_includes)
+  if(_nvcc_includes OR _nvcc_system_includes)
     # across all operating system each include directory is prefixed with -I
     separate_arguments(_nvcc_output NATIVE_COMMAND "${_nvcc_includes}")
     foreach(line IN LISTS _nvcc_output)
@@ -143,6 +151,17 @@ macro(cmake_nvcc_parse_implicit_info lang lang_var_)
       list(APPEND ${lang_var_}TOOLKIT_INCLUDE_DIRECTORIES "${line}")
     endforeach()
 
+    # across all operating system each system include directory is prefixed with -isystem
+    unset(_nvcc_output)
+    separate_arguments(_nvcc_output NATIVE_COMMAND "${_nvcc_system_includes}")
+    foreach(line IN LISTS _nvcc_output)
+      string(REGEX REPLACE "^-isystem" "" line "${line}")
+      if(line)
+        get_filename_component(line "${line}" ABSOLUTE)
+        list(APPEND ${lang_var_}TOOLKIT_INCLUDE_DIRECTORIES "${line}")
+      endif()
+    endforeach()
+
     message(CONFIGURE_LOG
       "Parsed CUDA nvcc include information:\n${_nvcc_log}\n${log}\n\n")
   else()

+ 4 - 0
Tests/Cuda/IncludePathNoToolkit/main.cpp

@@ -1,6 +1,10 @@
 // Only thing we care about is that these headers are found
 #include <cuda.h>
 #include <cuda_runtime_api.h>
+#if CUDA_VERSION >= 11040
+#  include <nv/target>
+#endif
+#include <thrust/version.h>
 
 int main()
 {

+ 4 - 0
Tests/Cuda/Toolkit/main.cpp

@@ -1,6 +1,10 @@
 // Only thing we care about is that these headers are found
 #include <cuda.h>
 #include <cuda_runtime_api.h>
+#if CUDA_VERSION >= 11040
+#  include <nv/target>
+#endif
+#include <thrust/version.h>
 
 int main()
 {

+ 4 - 0
Tests/Cuda/ToolkitBeforeLang/main.cpp

@@ -1,6 +1,10 @@
 // Only thing we care about is that these headers are found
 #include <cuda.h>
 #include <cuda_runtime_api.h>
+#if CUDA_VERSION >= 11040
+#  include <nv/target>
+#endif
+#include <thrust/version.h>
 
 int main()
 {

+ 4 - 0
Tests/CudaOnly/Toolkit/main.cu

@@ -1,6 +1,10 @@
 // Only thing we care about is that these headers are found
 #include <cuda.h>
 #include <cuda_runtime_api.h>
+#if CUDA_VERSION >= 11040
+#  include <nv/target>
+#endif
+#include <thrust/version.h>
 
 int main(int argc, char** argv)
 {

+ 4 - 0
Tests/CudaOnly/ToolkitBeforeLang/main.cu

@@ -1,6 +1,10 @@
 // Only thing we care about is that these headers are found
 #include <cuda.h>
 #include <cuda_runtime_api.h>
+#if CUDA_VERSION >= 11040
+#  include <nv/target>
+#endif
+#include <thrust/version.h>
 
 int main(int argc, char** argv)
 {

+ 4 - 0
Tests/CudaOnly/ToolkitMultipleDirs/main.cu

@@ -1,6 +1,10 @@
 // Only thing we care about is that these headers are found
 #include <cuda.h>
 #include <cuda_runtime_api.h>
+#if CUDA_VERSION >= 11040
+#  include <nv/target>
+#endif
+#include <thrust/version.h>
 
 int main(int argc, char** argv)
 {