summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorRobert Maynard <robert.maynard@kitware.com>2020-01-21 15:27:07 (GMT)
committerRobert Maynard <robert.maynard@kitware.com>2020-01-23 17:51:29 (GMT)
commit69fcad93322e20f1b0c171c582f28bd97fc6132d (patch)
treeb2ae79bd1b0e2097cf072c673b9e54060006621d /Modules
parentab2fc918216011a03f0fe7696e7bba67fc2627b3 (diff)
downloadCMake-69fcad93322e20f1b0c171c582f28bd97fc6132d.zip
CMake-69fcad93322e20f1b0c171c582f28bd97fc6132d.tar.gz
CMake-69fcad93322e20f1b0c171c582f28bd97fc6132d.tar.bz2
CUDAToolkit: Add support for cross-compiling
CUDAToolkit now searches the correct targets folder based on what platform we are cross-compiling for. Fixes: #20232
Diffstat (limited to 'Modules')
-rw-r--r--Modules/FindCUDAToolkit.cmake46
1 files changed, 43 insertions, 3 deletions
diff --git a/Modules/FindCUDAToolkit.cmake b/Modules/FindCUDAToolkit.cmake
index f7f68ca..48893bd 100644
--- a/Modules/FindCUDAToolkit.cmake
+++ b/Modules/FindCUDAToolkit.cmake
@@ -408,6 +408,11 @@ Result variables
The path to the CUDA Toolkit library directory that contains the CUDA
Runtime library ``cudart``.
+``CUDAToolkit_TARGET_DIR``
+ The path to the CUDA Toolkit directory including the target architecture
+ when cross-compiling. When not cross-compiling this will be equivalant to
+ ``CUDAToolkit_ROOT_DIR``.
+
``CUDAToolkit_NVCC_EXECUTABLE``
The path to the NVIDIA CUDA compiler ``nvcc``. Note that this path may
**not** be the same as
@@ -641,8 +646,37 @@ endif()
get_filename_component(CUDAToolkit_ROOT_DIR ${CUDAToolkit_BIN_DIR} DIRECTORY ABSOLUTE)
-# Now that we have the real ROOT_DIR, find components inside it.
-list(APPEND CMAKE_PREFIX_PATH ${CUDAToolkit_ROOT_DIR})
+# Handle cross compilation
+if(CMAKE_CROSSCOMPILING)
+ if(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7-a")
+ # Support for NVPACK
+ set (CUDAToolkit_TARGET_NAME "armv7-linux-androideabi")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm")
+ # Support for arm cross compilation
+ set(CUDAToolkit_TARGET_NAME "armv7-linux-gnueabihf")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
+ # Support for aarch64 cross compilation
+ if (ANDROID_ARCH_NAME STREQUAL "arm64")
+ set(CUDAToolkit_TARGET_NAME "aarch64-linux-androideabi")
+ else()
+ set(CUDAToolkit_TARGET_NAME "aarch64-linux")
+ endif (ANDROID_ARCH_NAME STREQUAL "arm64")
+ elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
+ set(CUDAToolkit_TARGET_NAME "x86_64-linux")
+ endif()
+
+ if (EXISTS "${CUDAToolkit_ROOT_DIR}/targets/${CUDAToolkit_TARGET_NAME}")
+ set(CUDAToolkit_TARGET_DIR "${CUDAToolkit_ROOT_DIR}/targets/${CUDAToolkit_TARGET_NAME}")
+ # add known CUDA target root path to the set of directories we search for programs, libraries and headers
+ list(APPEND CMAKE_FIND_ROOT_PATH "${CUDAToolkit_TARGET_DIR}")
+ endif()
+else()
+ # Not cross compiling
+ set(CUDAToolkit_TARGET_DIR "${CUDAToolkit_ROOT_DIR}")
+ # Now that we have the real ROOT_DIR, find components inside it.
+ list(APPEND CMAKE_PREFIX_PATH ${CUDAToolkit_ROOT_DIR})
+endif()
+
# Find the include/ directory
find_path(CUDAToolkit_INCLUDE_DIR
@@ -659,7 +693,13 @@ if (NOT CUDA_CUDART AND NOT CUDAToolkit_FIND_QUIETLY)
endif()
unset(CUDAToolkit_ROOT_DIR)
-list(REMOVE_AT CMAKE_PREFIX_PATH -1)
+if(CMAKE_CROSSCOMPILING)
+ if(CUDAToolkit_TARGET_DIR)
+ list(REMOVE_AT CMAKE_FIND_ROOT_PATH -1)
+ endif()
+else()
+ list(REMOVE_AT CMAKE_PREFIX_PATH -1)
+endif()
#-----------------------------------------------------------------------------
# Perform version comparison and validate all required variables are set.