diff options
| author | ras0219 <533828+ras0219@users.noreply.github.com> | 2020-10-07 00:25:01 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-07 00:25:01 -0700 |
| commit | b7b552d31ca4b34b9afb9633594d445a1ef23600 (patch) | |
| tree | be3823fa58eee416d437124a0e4400913e1d1178 | |
| parent | 59a20fb164e18fca708a384a92c7d38d328ee0f2 (diff) | |
| download | vcpkg-b7b552d31ca4b34b9afb9633594d445a1ef23600.tar.gz vcpkg-b7b552d31ca4b34b9afb9633594d445a1ef23600.zip | |
[cuda] Export vcpkg_find_cuda.cmake (#13440)
Co-authored-by: Robert Schumacher <roschuma@microsoft.com>
Co-authored-by: Billy Robert O'Neal III <bion@microsoft.com>
| -rw-r--r-- | ports/cuda/CONTROL | 2 | ||||
| -rw-r--r-- | ports/cuda/portfile.cmake | 81 | ||||
| -rw-r--r-- | ports/cuda/vcpkg_find_cuda.cmake | 91 |
3 files changed, 96 insertions, 78 deletions
diff --git a/ports/cuda/CONTROL b/ports/cuda/CONTROL index 00b422df8..348fc9ae3 100644 --- a/ports/cuda/CONTROL +++ b/ports/cuda/CONTROL @@ -1,5 +1,5 @@ Source: cuda Version: 10.1 -Port-Version: 2 +Port-Version: 3 Description: A parallel computing platform and programming model Homepage: https://developer.nvidia.com/cuda-toolkit diff --git a/ports/cuda/portfile.cmake b/ports/cuda/portfile.cmake index 0dd768e29..6e5a497da 100644 --- a/ports/cuda/portfile.cmake +++ b/ports/cuda/portfile.cmake @@ -3,84 +3,11 @@ # If this package is installed, we assume that CUDA is properly installed. #note: this port must be kept in sync with CUDNN port: every time one is upgraded, the other must be too -set(CUDA_REQUIRED_VERSION "10.1.0") -set(CUDA_PATHS - ENV CUDA_PATH - ENV CUDA_BIN_PATH - ENV CUDA_PATH_V11_0 - ENV CUDA_PATH_V10_2 - ENV CUDA_PATH_V10_1) +include(${CMAKE_CURRENT_LIST_DIR}/vcpkg_find_cuda.cmake) -if (VCPKG_TARGET_IS_WINDOWS) - find_program(NVCC - NAMES nvcc.exe - PATHS - ${CUDA_PATHS} - PATH_SUFFIXES bin bin64 - DOC "Toolkit location." - NO_DEFAULT_PATH - ) -else() - if (VCPKG_TARGET_IS_LINUX) - set(platform_base "/usr/local/cuda-") - else() - set(platform_base "/Developer/NVIDIA/CUDA-") - endif() - - 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() - - find_program(NVCC - NAMES nvcc - PATHS - ${CUDA_PATHS} - PATHS ${FOUND_PATH} - PATH_SUFFIXES bin bin64 - DOC "Toolkit location." - NO_DEFAULT_PATH - ) -endif() +vcpkg_find_cuda(OUT_CUDA_TOOLKIT_ROOT CUDA_TOOLKIT_ROOT) -set(error_code 1) -if (NVCC) - execute_process( - COMMAND ${NVCC} --version - OUTPUT_VARIABLE NVCC_OUTPUT - RESULT_VARIABLE error_code) -endif() +file(COPY ${CMAKE_CURRENT_LIST_DIR}/vcpkg_find_cuda.cmake DESTINATION ${CURRENT_PACKAGES_DIR}/share/vcpkg_find_cuda) - -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 https://developer.nvidia.com/cuda-downloads\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}") -set(CUDA_VERSION_MAJOR ${CMAKE_MATCH_1}) -set(CUDA_VERSION_MINOR ${CMAKE_MATCH_2}) -set(CUDA_VERSION_PATCH ${CMAKE_MATCH_3}) - -if (CUDA_VERSION_MAJOR LESS 10 AND CUDA_VERSION_MINOR LESS 1) - message(FATAL_ERROR "CUDA ${CUDA_VERSION} found, but v${CUDA_REQUIRED_VERSION} is required. Please download and install a more recent version of CUDA from:" - "\n https://developer.nvidia.com/cuda-downloads\n") -endif() - -SET(VCPKG_POLICY_EMPTY_PACKAGE enabled) +set(VCPKG_POLICY_EMPTY_PACKAGE enabled) diff --git a/ports/cuda/vcpkg_find_cuda.cmake b/ports/cuda/vcpkg_find_cuda.cmake new file mode 100644 index 000000000..14719b0f3 --- /dev/null +++ b/ports/cuda/vcpkg_find_cuda.cmake @@ -0,0 +1,91 @@ +function(vcpkg_find_cuda)
+ cmake_parse_arguments(PARSE_ARGV 0 vfc "" "OUT_CUDA_TOOLKIT_ROOT" "")
+
+ 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")
+
+ set(CUDA_PATHS
+ ENV CUDA_PATH
+ ENV CUDA_BIN_PATH
+ ENV CUDA_PATH_V11_0
+ ENV CUDA_PATH_V10_2
+ ENV CUDA_PATH_V10_1)
+
+ if (VCPKG_TARGET_IS_WINDOWS)
+ find_program(NVCC
+ NAMES nvcc.exe
+ PATHS
+ ${CUDA_PATHS}
+ PATH_SUFFIXES bin bin64
+ DOC "Toolkit location."
+ NO_DEFAULT_PATH
+ )
+ else()
+ if (VCPKG_TARGET_IS_LINUX)
+ set(platform_base "/usr/local/cuda-")
+ else()
+ set(platform_base "/Developer/NVIDIA/CUDA-")
+ endif()
+
+ 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()
+
+ find_program(NVCC
+ NAMES nvcc
+ PATHS
+ ${CUDA_PATHS}
+ PATHS ${FOUND_PATH}
+ PATH_SUFFIXES bin bin64
+ DOC "Toolkit location."
+ NO_DEFAULT_PATH
+ )
+ endif()
+
+ set(error_code 1)
+ if (NVCC)
+ execute_process(
+ COMMAND ${NVCC} --version
+ OUTPUT_VARIABLE NVCC_OUTPUT
+ RESULT_VARIABLE error_code)
+ 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 https://developer.nvidia.com/cuda-downloads\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}")
+ set(CUDA_VERSION_MAJOR ${CMAKE_MATCH_1})
+ set(CUDA_VERSION_MINOR ${CMAKE_MATCH_2})
+ set(CUDA_VERSION_PATCH ${CMAKE_MATCH_3})
+
+ if (CUDA_VERSION_MAJOR LESS 10 AND CUDA_VERSION_MINOR LESS 1)
+ message(FATAL_ERROR "CUDA ${CUDA_VERSION} found, but v${CUDA_REQUIRED_VERSION} is required. Please download and install a more recent version of CUDA from:"
+ "\n https://developer.nvidia.com/cuda-downloads\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)
+endfunction()
|
