|
| 1 | +# ============================================================================= |
| 2 | +# Copyright (c) 2021-2025, NVIDIA CORPORATION. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
| 5 | +# in compliance with the License. You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software distributed under the License |
| 10 | +# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 11 | +# or implied. See the License for the specific language governing permissions and limitations under |
| 12 | +# the License. |
| 13 | +# ============================================================================= |
| 14 | +# |
| 15 | +# This is the preferred entry point for projects using rapids-cmake |
| 16 | +# |
| 17 | +# Enforce the minimum required CMake version for all users |
| 18 | +cmake_minimum_required(VERSION 3.30.4 FATAL_ERROR) |
| 19 | + |
| 20 | +# Allow users to control which version is used |
| 21 | +if(NOT rapids-cmake-version OR NOT rapids-cmake-version MATCHES [[^([0-9][0-9])\.([0-9][0-9])$]]) |
| 22 | + message( |
| 23 | + FATAL_ERROR "The CMake variable rapids-cmake-version must be defined in the format MAJOR.MINOR." |
| 24 | + ) |
| 25 | +endif() |
| 26 | + |
| 27 | +# Allow users to control which GitHub repo is fetched |
| 28 | +if(NOT rapids-cmake-repo) |
| 29 | + # Define a default repo if the user doesn't set one |
| 30 | + set(rapids-cmake-repo rapidsai/rapids-cmake) |
| 31 | +endif() |
| 32 | + |
| 33 | +# Allow users to control which branch is fetched |
| 34 | +if(NOT rapids-cmake-branch) |
| 35 | + # Define a default branch if the user doesn't set one |
| 36 | + set(rapids-cmake-branch "branch-${rapids-cmake-version}") |
| 37 | +endif() |
| 38 | + |
| 39 | +# Allow users to control the exact URL passed to FetchContent |
| 40 | +if(NOT rapids-cmake-url) |
| 41 | + # Construct a default URL if the user doesn't set one |
| 42 | + set(rapids-cmake-url "https://github.com/${rapids-cmake-repo}/") |
| 43 | + |
| 44 | + # In order of specificity |
| 45 | + if(rapids-cmake-fetch-via-git) |
| 46 | + if(rapids-cmake-sha) |
| 47 | + # An exact git SHA takes precedence over anything |
| 48 | + set(rapids-cmake-value-to-clone "${rapids-cmake-sha}") |
| 49 | + elseif(rapids-cmake-tag) |
| 50 | + # Followed by a git tag name |
| 51 | + set(rapids-cmake-value-to-clone "${rapids-cmake-tag}") |
| 52 | + else() |
| 53 | + # Or if neither of the above two were defined, use a branch |
| 54 | + set(rapids-cmake-value-to-clone "${rapids-cmake-branch}") |
| 55 | + endif() |
| 56 | + else() |
| 57 | + if(rapids-cmake-sha) |
| 58 | + # An exact git SHA takes precedence over anything |
| 59 | + set(rapids-cmake-value-to-clone "archive/${rapids-cmake-sha}.zip") |
| 60 | + elseif(rapids-cmake-tag) |
| 61 | + # Followed by a git tag name |
| 62 | + set(rapids-cmake-value-to-clone "archive/refs/tags/${rapids-cmake-tag}.zip") |
| 63 | + else() |
| 64 | + # Or if neither of the above two were defined, use a branch |
| 65 | + set(rapids-cmake-value-to-clone "archive/refs/heads/${rapids-cmake-branch}.zip") |
| 66 | + endif() |
| 67 | + endif() |
| 68 | +endif() |
| 69 | + |
| 70 | +include(FetchContent) |
| 71 | +if(rapids-cmake-fetch-via-git) |
| 72 | + FetchContent_Declare( |
| 73 | + rapids-cmake |
| 74 | + GIT_REPOSITORY "${rapids-cmake-url}" |
| 75 | + GIT_TAG "${rapids-cmake-value-to-clone}") |
| 76 | +else() |
| 77 | + string(APPEND rapids-cmake-url "${rapids-cmake-value-to-clone}") |
| 78 | + FetchContent_Declare(rapids-cmake URL "${rapids-cmake-url}") |
| 79 | +endif() |
| 80 | +FetchContent_GetProperties(rapids-cmake) |
| 81 | +if(rapids-cmake_POPULATED) |
| 82 | + # Something else has already populated rapids-cmake, only thing we need to do is setup the |
| 83 | + # CMAKE_MODULE_PATH |
| 84 | + if(NOT "${rapids-cmake-dir}" IN_LIST CMAKE_MODULE_PATH) |
| 85 | + list(APPEND CMAKE_MODULE_PATH "${rapids-cmake-dir}") |
| 86 | + endif() |
| 87 | +else() |
| 88 | + FetchContent_MakeAvailable(rapids-cmake) |
| 89 | +endif() |
0 commit comments