2020-10-07 15:25:01 +08:00
function ( vcpkg_find_cuda )
2021-04-14 06:15:32 +08:00
cmake_parse_arguments ( PARSE_ARGV 0 vfc "" "OUT_CUDA_TOOLKIT_ROOT;OUT_CUDA_VERSION" "" )
2020-10-07 15:25:01 +08:00
if ( NOT vfc_OUT_CUDA_TOOLKIT_ROOT )
message ( FATAL_ERROR "vcpkg_find_cuda() requres an OUT_CUDA_TOOLKIT_ROOT argument" )
endif ( )
set ( CUDA_REQUIRED_VERSION "10.1.0" )
2021-04-14 06:15:32 +08:00
set ( CUDA_PATHS
2020-10-07 15:25:01 +08:00
E N V C U D A _ P A T H
2020-12-05 08:38:44 +08:00
E N V C U D A _ H O M E
2020-10-07 15:25:01 +08:00
E N V C U D A _ B I N _ P A T H
2021-04-14 06:15:32 +08:00
E N V C U D A _ T O O L K I T _ R O O T _ D I R )
2020-10-07 15:25:01 +08:00
if ( VCPKG_TARGET_IS_WINDOWS )
find_program ( NVCC
N A M E S n v c c . e x e
P A T H S
$ { C U D A _ P A T H S }
P A T H _ S U F F I X E S b i n b i n 6 4
D O C " T o o l k i t l o c a t i o n . "
N O _ D E F A U L T _ P A T H
)
else ( )
if ( VCPKG_TARGET_IS_LINUX )
set ( platform_base "/usr/local/cuda-" )
else ( )
set ( platform_base "/Developer/NVIDIA/CUDA-" )
endif ( )
2021-04-14 06:15:32 +08:00
2020-10-07 15:25:01 +08:00
file ( GLOB possible_paths "${platform_base}*" )
set ( FOUND_PATH )
foreach ( p ${ possible_paths } )
# Extract version number from end of string
string ( REGEX MATCH "[0-9][0-9]?\\.[0-9]$" p_version ${ p } )
if ( IS_DIRECTORY ${ p } AND p_version )
if ( p_version VERSION_GREATER_EQUAL CUDA_REQUIRED_VERSION )
set ( FOUND_PATH ${ p } )
break ( )
endif ( )
endif ( )
endforeach ( )
2021-04-14 06:15:32 +08:00
2022-07-16 12:11:16 +08:00
vcpkg_list ( APPEND CUDA_PATHS /usr/bin )
2020-10-07 15:25:01 +08:00
find_program ( NVCC
N A M E S n v c c
P A T H S
$ { C U D A _ P A T H S }
P A T H S $ { F O U N D _ P A T H }
P A T H _ S U F F I X E S b i n b i n 6 4
D O C " T o o l k i t l o c a t i o n . "
N O _ D E F A U L T _ P A T H
)
endif ( )
set ( error_code 1 )
if ( NVCC )
execute_process (
C O M M A N D $ { N V C C } - - v e r s i o n
O U T P U T _ V A R I A B L E N V C C _ O U T P U T
R E S U L T _ V A R I A B L E e r r o r _ c o d e )
endif ( )
if ( error_code )
message ( STATUS "Executing ${NVCC} --version resulted in error: ${error_code}" )
message ( FATAL_ERROR "Could not find CUDA. Before continuing, please download and install CUDA (v${CUDA_REQUIRED_VERSION} or higher) from:"
" \ n h t t p s : / / d e v e l o p e r . n v i d i a . c o m / c u d a - d o w n l o a d s \ n " )
endif ( )
# Sample output:
# NVIDIA (R) Cuda compiler driver
# Copyright (c) 2005-2016 NVIDIA Corporation
# Built on Sat_Sep__3_19:05:48_CDT_2016
# Cuda compilation tools, release 8.0, V8.0.44
string ( REGEX MATCH "V([0-9]+)\\.([0-9]+)\\.([0-9]+)" CUDA_VERSION ${ NVCC_OUTPUT } )
message ( STATUS "Found CUDA ${CUDA_VERSION}" )
2021-04-14 06:15:32 +08:00
set ( CUDA_VERSION_MAJOR "${CMAKE_MATCH_1}" )
set ( CUDA_VERSION_MINOR "${CMAKE_MATCH_2}" )
set ( CUDA_VERSION_MAJOR_MINOR "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}" )
2020-10-07 15:25:01 +08:00
2021-04-14 06:15:32 +08:00
if ( CUDA_VERSION_MAJOR_MINOR VERSION_LESS CUDA_REQUIRED_VERSION )
message ( FATAL_ERROR "CUDA v${CUDA_VERSION_MAJOR_MINOR} found, but v${CUDA_REQUIRED_VERSION} is required. Please download and install a more recent version of CUDA from:"
2020-10-07 15:25:01 +08:00
" \ n h t t p s : / / d e v e l o p e r . n v i d i a . c o m / c u d a - d o w n l o a d s \ n " )
endif ( )
get_filename_component ( CUDA_TOOLKIT_ROOT "${NVCC}" DIRECTORY )
get_filename_component ( CUDA_TOOLKIT_ROOT "${CUDA_TOOLKIT_ROOT}" DIRECTORY )
set ( ${ vfc_OUT_CUDA_TOOLKIT_ROOT } "${CUDA_TOOLKIT_ROOT}" PARENT_SCOPE )
2021-04-14 06:15:32 +08:00
if ( DEFINED vfc_OUT_CUDA_VERSION )
set ( ${ vfc_OUT_CUDA_VERSION } "${CUDA_VERSION_MAJOR_MINOR}" PARENT_SCOPE )
endif ( )
2020-10-07 15:25:01 +08:00
endfunction ( )