|
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +# |
| 6 | +# In order to have Orochi compiled with CUDA, you need to define OROCHI_ENABLE_CUEW, and add the CUDA include path to your Orochi project. |
| 7 | +# |
| 8 | +# If your project is using cmake, this script can be included: |
| 9 | +# it helps to configure your Orochi project |
| 10 | +# for example, with a line looking like that: |
| 11 | +# include(${CMAKE_SOURCE_DIR}/contrib/Orochi/Orochi/enable_cuew.cmake) |
| 12 | +# |
| 13 | +# |
| 14 | + |
| 15 | + |
| 16 | +cmake_minimum_required(VERSION 3.10) |
| 17 | + |
| 18 | + |
| 19 | +# Function to join paths |
| 20 | +function(join_paths result basePath additionalPath) |
| 21 | + if(WIN32) |
| 22 | + set(pathSeparator "\\") |
| 23 | + else() |
| 24 | + set(pathSeparator "/") |
| 25 | + endif() |
| 26 | + |
| 27 | + string(REGEX REPLACE "[/\\]+$" "" basePath "${basePath}") |
| 28 | + set(joinedPath "${basePath}${pathSeparator}${additionalPath}") |
| 29 | + set(${result} "${joinedPath}" PARENT_SCOPE) |
| 30 | +endfunction() |
| 31 | + |
| 32 | +# Function to check if a path is valid |
| 33 | +function(path_ok result inPath) |
| 34 | + if(EXISTS "${inPath}" AND IS_DIRECTORY "${inPath}") |
| 35 | + set(${result} TRUE) |
| 36 | + else() |
| 37 | + set(${result} FALSE) |
| 38 | + endif() |
| 39 | +endfunction() |
| 40 | + |
| 41 | +# Region generated by Orochi Summoner |
| 42 | +#REGION_PREMAKE_START CudaPath |
| 43 | + |
| 44 | +set(BEST_CUDA_VERSION_NAME "12.2") |
| 45 | +set(BEST_CUDA_ENVVAR "CUDA_PATH_V12_2") |
| 46 | +set(BEST_CUDA_PATH_LINUX "/usr/local/cuda-12.2") |
| 47 | +set(BEST_CUDA_PATH_WINDOWS "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.2") |
| 48 | +set(BACKUP_CUDA_ENVVAR "CUDA_PATH") |
| 49 | +set(BACKUP_CUDA_PATH_LINUX "/usr/local/cuda") |
| 50 | + |
| 51 | +# REGION_PREMAKE_END |
| 52 | + |
| 53 | +# First, try the best CUDA paths |
| 54 | +if(DEFINED ENV{${BEST_CUDA_ENVVAR}}) |
| 55 | + set(cuda_path $ENV{${BEST_CUDA_ENVVAR}}) |
| 56 | +endif() |
| 57 | + |
| 58 | +if(NOT cuda_path) |
| 59 | + path_ok(cuda_path_ok ${BEST_CUDA_PATH_LINUX}) |
| 60 | + if(cuda_path_ok) |
| 61 | + set(cuda_path ${BEST_CUDA_PATH_LINUX}) |
| 62 | + endif() |
| 63 | +endif() |
| 64 | + |
| 65 | +if(NOT cuda_path) |
| 66 | + path_ok(cuda_path_ok ${BEST_CUDA_PATH_WINDOWS}) |
| 67 | + if(cuda_path_ok) |
| 68 | + set(cuda_path ${BEST_CUDA_PATH_WINDOWS}) |
| 69 | + endif() |
| 70 | +endif() |
| 71 | + |
| 72 | +if(NOT cuda_path) |
| 73 | + message(WARNING "The required version of CUDA for this Orochi is not found: ${BEST_CUDA_VERSION_NAME}. It's advised that you install this version.") |
| 74 | +endif() |
| 75 | + |
| 76 | +# If CUDA still not found, search the "backup" paths |
| 77 | +if(NOT cuda_path) |
| 78 | + if(DEFINED ENV{${BACKUP_CUDA_ENVVAR}}) |
| 79 | + set(cuda_path $ENV{${BACKUP_CUDA_ENVVAR}}) |
| 80 | + endif() |
| 81 | +endif() |
| 82 | + |
| 83 | +if(NOT cuda_path) |
| 84 | + path_ok(cuda_path_ok ${BACKUP_CUDA_PATH_LINUX}) |
| 85 | + if(cuda_path_ok) |
| 86 | + set(cuda_path ${BACKUP_CUDA_PATH_LINUX}) |
| 87 | + endif() |
| 88 | +endif() |
| 89 | + |
| 90 | +# Enable CUEW if CUDA is forced or if we find the CUDA SDK folder |
| 91 | +option(FORCE_CUDA "Force enable CUDA" OFF) |
| 92 | +if(FORCE_CUDA OR cuda_path) |
| 93 | + message(STATUS "CUEW is enabled.") |
| 94 | + add_definitions(-DOROCHI_ENABLE_CUEW) |
| 95 | +endif() |
| 96 | + |
| 97 | + |
| 98 | +# If we find the CUDA SDK folder, add it to the include dir |
| 99 | +if(cuda_path) |
| 100 | + message(STATUS "CUDA SDK install folder found: ${cuda_path}") |
| 101 | + join_paths(cuda_include_path ${cuda_path} "include") |
| 102 | + include_directories(${cuda_include_path}) |
| 103 | +else() |
| 104 | + if(FORCE_CUDA) |
| 105 | + message(WARNING "WARNING: CUEW is enabled but it may not compile because CUDA SDK folder (CUDA_PATH) not found. You should install the CUDA SDK, or set CUDA_PATH.") |
| 106 | + else() |
| 107 | + message(WARNING "WARNING: CUEW is automatically disabled because CUDA SDK folder (CUDA_PATH) not found. You can force CUEW with the --forceCuda argument.") |
| 108 | + endif() |
| 109 | +endif() |
0 commit comments