Browse Source

FindCUDAToolkit: Compute CUDAToolkit_INCLUDE_DIR instead of searching

We can avoid searching for this since CUDAToolkit_TARGET_DIR always contains
the include/ directory. But add a warning just in case.

Also apply this in CMakeDetermineCUDACompiler for Clang code.
Raul Tambre 5 years ago
parent
commit
8c144fe9ad
2 changed files with 14 additions and 8 deletions
  1. 7 4
      Modules/CMakeDetermineCUDACompiler.cmake
  2. 7 4
      Modules/FindCUDAToolkit.cmake

+ 7 - 4
Modules/CMakeDetermineCUDACompiler.cmake

@@ -332,10 +332,13 @@ elseif(CMAKE_CUDA_COMPILER_ID STREQUAL "Clang")
     message(FATAL_ERROR "Unable to find _CUDA_LIBRARY_DIR based on _CUDA_TARGET_DIR=${_CUDA_TARGET_DIR}")
   endif()
 
-  find_path(_CUDA_INCLUDE_DIR
-    NAMES cuda_runtime.h
-    HINTS "${_CUDA_TARGET_DIR}/include"
-  )
+  # _CUDA_TARGET_DIR always points to the directory containing the include directory.
+  # On a scattered installation /usr, on a non-scattered something like /usr/local/cuda or /usr/local/cuda-10.2/targets/aarch64-linux.
+  if(EXISTS "${_CUDA_TARGET_DIR}/include/cuda_runtime.h")
+    set(_CUDA_INCLUDE_DIR "${_CUDA_TARGET_DIR}/include")
+  else()
+    message(FATAL_ERROR "Unable to find cuda_runtime.h in \"${_CUDA_TARGET_DIR}/include\" for _CUDA_INCLUDE_DIR.")
+  endif()
 
   # Clang does not add any CUDA SDK libraries or directories when invoking the host linker.
   # Add the CUDA toolkit library directory ourselves so that linking works.

+ 7 - 4
Modules/FindCUDAToolkit.cmake

@@ -694,10 +694,13 @@ else()
   set(_CUDAToolkit_Pop_Prefix True)
 endif()
 
-# Find the include/ directory
-find_path(CUDAToolkit_INCLUDE_DIR
-  NAMES cuda_runtime.h
-)
+# CUDAToolkit_TARGET_DIR always points to the directory containing the include directory.
+# On a scattered installation /usr, on a non-scattered something like /usr/local/cuda or /usr/local/cuda-10.2/targets/aarch64-linux.
+if(EXISTS "${CUDAToolkit_TARGET_DIR}/include/cuda_runtime.h")
+  set(CUDAToolkit_INCLUDE_DIR "${CUDAToolkit_TARGET_DIR}/include")
+elseif(NOT CUDAToolkit_FIND_QUIETLY)
+  message(STATUS "Unable to find cuda_runtime.h in \"${CUDAToolkit_TARGET_DIR}/include\" for CUDAToolkit_INCLUDE_DIR.")
+endif()
 
 if(CUDAToolkit_NVCC_EXECUTABLE AND
    CUDAToolkit_NVCC_EXECUTABLE STREQUAL CMAKE_CUDA_COMPILER)