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