Commit f3623d9d authored by Robert Maynard's avatar Robert Maynard

FindCUDAToolkit: correct searches for Toolkit components

parent 16cf221c
Pipeline #154678 failed with stage
......@@ -453,24 +453,27 @@ Result variables
#
###############################################################################
if(CMAKE_CUDA_COMPILER)
if(CMAKE_CUDA_COMPILER_LOADED AND NOT CUDAToolkit_BIN_DIR)
get_filename_component(cuda_dir "${CMAKE_CUDA_COMPILER}" DIRECTORY)
# use the already detected cuda compiler
set(CUDAToolkit_BIN_DIR "${cuda_dir}" CACHE PATH "")
else()
# Try user provided paths first.
find_path(CUDAToolkit_BIN_DIR
unset(cuda_dir)
endif()
# Try language- or user-provided path first.
if(CUDAToolkit_BIN_DIR)
find_program(CUDAToolkit_NVCC_EXECUTABLE
NAMES nvcc nvcc.exe
PATHS
${CUDAToolkit_ROOT}
ENV CUDAToolkit_ROOT
PATH_SUFFIXES bin bin64
PATHS ${CUDAToolkit_BIN_DIR}
NO_DEFAULT_PATH
)
)
endif()
find_program(CUDAToolkit_NVCC_EXECUTABLE
NAMES nvcc nvcc.exe
)
# If the user specified CUDAToolkit_ROOT but nvcc could not be found, this is an error.
if (NOT CUDAToolkit_BIN_DIR AND (DEFINED CUDAToolkit_ROOT OR DEFINED ENV{CUDAToolkit_ROOT}))
if (NOT CUDAToolkit_NVCC_EXECUTABLE AND (DEFINED CUDAToolkit_ROOT OR DEFINED ENV{CUDAToolkit_ROOT}))
# Declare error messages now, print later depending on find_package args.
set(fail_base "Could not find nvcc executable in path specified by")
set(cuda_root_fail "${fail_base} CUDAToolkit_ROOT=${CUDAToolkit_ROOT}")
......@@ -507,7 +510,7 @@ endif()
# We will also search the default symlink location /usr/local/cuda first since
# if CUDAToolkit_ROOT is not specified, it is assumed that the symlinked
# directory is the desired location.
if (NOT CUDAToolkit_BIN_DIR)
if (NOT CUDAToolkit_NVCC_EXECUTABLE)
if (UNIX)
if (NOT APPLE)
set(platform_base "/usr/local/cuda-")
......@@ -574,11 +577,9 @@ if (NOT CUDAToolkit_BIN_DIR)
endif()
# Now search for nvcc again using the platform default search paths.
find_path(CUDAToolkit_BIN_DIR
find_program(CUDAToolkit_NVCC_EXECUTABLE
NAMES nvcc nvcc.exe
PATHS ${search_paths}
PATH_SUFFIXES bin bin64
NO_DEFAULT_PATH
)
# We are done with these variables now, cleanup for caller.
......@@ -590,7 +591,7 @@ if (NOT CUDAToolkit_BIN_DIR)
unset(early_terminate)
unset(search_paths)
if (NOT CUDAToolkit_BIN_DIR)
if (NOT CUDAToolkit_NVCC_EXECUTABLE)
if (CUDAToolkit_FIND_REQUIRED)
message(FATAL_ERROR "Could not find nvcc, please set CUDAToolkit_ROOT.")
elseif(NOT CUDAToolkit_FIND_QUIETLY)
......@@ -602,11 +603,12 @@ if (NOT CUDAToolkit_BIN_DIR)
endif()
endif()
find_program(CUDAToolkit_NVCC_EXECUTABLE
NAMES nvcc nvcc.exe
PATHS ${CUDAToolkit_BIN_DIR}
NO_DEFAULT_PATH
)
if(NOT CUDAToolkit_BIN_DIR AND CUDAToolkit_NVCC_EXECUTABLE)
get_filename_component(cuda_dir "${CUDAToolkit_NVCC_EXECUTABLE}" DIRECTORY)
set(CUDAToolkit_BIN_DIR "${cuda_dir}" CACHE PATH "" FORCE)
unset(cuda_dir)
endif()
if(CUDAToolkit_NVCC_EXECUTABLE AND
CUDAToolkit_NVCC_EXECUTABLE STREQUAL CMAKE_CUDA_COMPILER)
# Need to set these based off the already computed CMAKE_CUDA_COMPILER_VERSION value
......@@ -632,27 +634,24 @@ endif()
get_filename_component(CUDAToolkit_ROOT_DIR ${CUDAToolkit_BIN_DIR} DIRECTORY ABSOLUTE)
# Now that we have the real ROOT_DIR, find the include/ directory
# Now that we have the real ROOT_DIR, find components inside it.
list(APPEND CMAKE_PREFIX_PATH ${CUDAToolkit_ROOT_DIR})
# Find the include/ directory
find_path(CUDAToolkit_INCLUDE_DIR
cuda_runtime.h
# TODO: FindCUDA.cmake has special TARGET_DIR for cross compiling, is that needed?
PATHS ${CUDAToolkit_ROOT_DIR}
PATH_SUFFIXES include
NO_DEFAULT_PATH
NAMES cuda_runtime.h
)
# And find the CUDA Runtime Library libcudart
find_library(CUDA_CUDART
cudart
PATHS ${CUDAToolkit_ROOT_DIR}
PATH_SUFFIXES lib lib64
NO_DEFAULT_PATH
NAMES cudart
)
if (NOT CUDA_CUDART AND NOT CUDAToolkit_FIND_QUIETLY)
message(STATUS "Unable to find cudart library under ${CUDAToolkit_ROOT_DIR}/lib[64].")
message(STATUS "Unable to find cudart library.")
endif()
unset(CUDAToolkit_ROOT_DIR)
list(REMOVE_AT CMAKE_PREFIX_PATH -1)
#-----------------------------------------------------------------------------
# Perform version comparison and validate all required variables are set.
......@@ -688,6 +687,7 @@ if(CUDAToolkit_FOUND)
find_library(CUDA_${lib_name}_LIBRARY
NAMES ${search_names}
PATHS ${CUDAToolkit_LIBRARY_DIR}
PATH_SUFFIXES nvidia/current
)
if (NOT CUDA::${lib_name} AND CUDA_${lib_name}_LIBRARY)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment