|
| 1 | +################################### |
| 2 | +# CCCL (Thrust, CUB and libcucxx) # |
| 3 | +################################### |
| 4 | + |
| 5 | +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/modules/ ${CMAKE_MODULE_PATH}) |
| 6 | + |
| 7 | +include(FetchContent) |
| 8 | +cmake_policy(SET CMP0079 NEW) |
| 9 | +# Temporary CMake >= 3.30 fix https://github.com/FLAMEGPU/FLAMEGPU2/issues/1223 |
| 10 | +if(POLICY CMP0169) |
| 11 | + cmake_policy(SET CMP0169 OLD) |
| 12 | +endif() |
| 13 | + |
| 14 | +# Set the minimum supported CCCL version, and the version to fetch |
| 15 | +# using find_package(version) means it's up to CCCL's cmake to determine if newer versions are compatible, but this will likely need changing for CUDA 13, when CCCL is planned to have a major version bump (and drop CUDA 11 support). |
| 16 | +set(MIN_REQUIRED_CCCL_VERSION 2.3.2) |
| 17 | +set(CCCL_DOWNLOAD_TAG v2.3.2) |
| 18 | + |
| 19 | +# Use the FindCUDATooklit package (CMake > 3.17) to get the CUDA version and CUDA include directories for cub/thrust location hints |
| 20 | +find_package(CUDAToolkit REQUIRED) |
| 21 | + |
| 22 | +# Quietly find CCCL, to check if the version included with CUDA (if CCCL) is sufficiently new. |
| 23 | +# Using CCCL avoids complex cub/thrust version workarounds previously required. |
| 24 | +# However we cannot find thrust due to a missing guard in CCCL's cmake config file, and cannot find cub without finding libcudacxx, so just find libcudacxx quietly. |
| 25 | +# The fix for this was first included in the 2.3.2 release |
| 26 | +find_package(CCCL ${MIN_REQUIRED_CCCL_VERSION} QUIET COMPONENTS libcudacxx CONFIG HINTS ${CUDAToolkit_INCLUDE_DIRS} ${CUDAToolkit_LIBRARY_DIR}/cmake) |
| 27 | + |
| 28 | +# If CCCL was found, find it again but loudly (with all components) |
| 29 | +if(CCCL_FOUND) |
| 30 | + # Find the packages again but less quietly (and include all components) |
| 31 | + find_package(CCCL ${MIN_REQUIRED_CCCL_VERSION} REQUIRED CONFIG COMPONENTS HINTS ${CUDAToolkit_INCLUDE_DIRS} ${CUDAToolkit_LIBRARY_DIR}/cmake) |
| 32 | +# If CCCL does need downloading, fetch it and find it (no need to add_subdirectory) |
| 33 | +else() |
| 34 | + # Declare information about where and what we want from thrust. |
| 35 | + FetchContent_Declare( |
| 36 | + cccl |
| 37 | + GIT_REPOSITORY https://github.com/NVIDIA/CCCL.git |
| 38 | + GIT_TAG ${CCCL_DOWNLOAD_TAG} |
| 39 | + GIT_SHALLOW 0 # @todo - set this back to 1. |
| 40 | + GIT_PROGRESS ON |
| 41 | + # UPDATE_DISCONNECTED ON |
| 42 | + ) |
| 43 | + # Fetch and populate the content if required. |
| 44 | + FetchContent_GetProperties(cccl) |
| 45 | + if(NOT cccl_POPULATED) |
| 46 | + message(STATUS "Fetching CCCL ${CCCL_DOWNLOAD_TAG}") |
| 47 | + FetchContent_Populate(cccl) |
| 48 | + # Use find_package for CCLL, only looking for the fetched version. |
| 49 | + # This creates a non-system target due to nvcc magic to avoid the cuda toolkit version being used instead, so warnings are not suppressible without push/pop macros. |
| 50 | + find_package(CCCL REQUIRED CONFIG |
| 51 | + PATHS "${cccl_SOURCE_DIR}" |
| 52 | + NO_CMAKE_PATH |
| 53 | + NO_CMAKE_ENVIRONMENT_PATH |
| 54 | + NO_SYSTEM_ENVIRONMENT_PATH |
| 55 | + NO_CMAKE_PACKAGE_REGISTRY |
| 56 | + NO_CMAKE_SYSTEM_PATH) |
| 57 | + endif() |
| 58 | + # Mark some CACHE vars as advanced for a cleaner CMake GUI |
| 59 | + mark_as_advanced(FETCHCONTENT_QUIET) |
| 60 | + mark_as_advanced(FETCHCONTENT_BASE_DIR) |
| 61 | + mark_as_advanced(FETCHCONTENT_FULLY_DISCONNECTED) |
| 62 | + mark_as_advanced(FETCHCONTENT_UPDATES_DISCONNECTED) |
| 63 | + mark_as_advanced(FETCHCONTENT_SOURCE_DIR_CCCL) |
| 64 | + mark_as_advanced(FETCHCONTENT_UPDATES_DISCONNECTED_CCCL) |
| 65 | +endif() |
| 66 | + |
| 67 | +# Unset temporary variables |
| 68 | +unset(MIN_REQUIRED_CCCL_VERSION) |
| 69 | +unset(CCCL_DOWNLOAD_TAG) |
| 70 | + |
| 71 | +# Mark some CACHE vars as advanced for a cleaner CMake GUI |
| 72 | +mark_as_advanced(CCCL_DIR) |
| 73 | +mark_as_advanced(CUB_DIR) |
| 74 | +mark_as_advanced(Thrust_DIR) |
| 75 | +mark_as_advanced(libcudacxx_DIR) |
0 commit comments