|
| 1 | +# ============================================================================= |
| 2 | +# cmake-format: off |
| 3 | +# SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION. |
| 4 | +# SPDX-License-Identifier: Apache-2.0 |
| 5 | +# cmake-format: on |
| 6 | +# ============================================================================= |
| 7 | +include_guard(GLOBAL) |
| 8 | + |
| 9 | +#[=======================================================================[.rst: |
| 10 | +determine_cuvs_abi_version |
| 11 | +--------------------------- |
| 12 | +
|
| 13 | +.. versionadded:: v26.02.00 |
| 14 | +
|
| 15 | +Convert a calendar version to a cuVS ABI version |
| 16 | +
|
| 17 | + .. code-block:: cmake |
| 18 | +
|
| 19 | + determine_cuvs_abi_version(cal_ver MAJOR major_output_var MINOR minor_output_var) |
| 20 | +
|
| 21 | +Provides a consistent method to convert calendar-based version strings (YY.MM format) to |
| 22 | +cuVS ABI version components. |
| 23 | +
|
| 24 | +Each |
| 25 | +
|
| 26 | +``cal_ver`` |
| 27 | + A calendar version string in YY.MM format (e.g., "26.02", "27.08"). |
| 28 | +
|
| 29 | +``major_output_var`` |
| 30 | + Contains the name of the variable that will be set in the parent scope to the computed |
| 31 | + ABI major version. |
| 32 | +
|
| 33 | +``minor_output_var`` |
| 34 | + Contains the name of the variable that will be set in the parent scope to the computed |
| 35 | + ABI minor version. |
| 36 | +
|
| 37 | +Example on how to properly use :cmake:command:`determine_cuvs_abi_version`: |
| 38 | +
|
| 39 | + .. code-block:: cmake |
| 40 | +
|
| 41 | + project(Example VERSION 26.02.0) |
| 42 | +
|
| 43 | + determine_cuvs_abi_version(${PROJECT_VERSION} MAJOR abi_major MINOR abi_minor) |
| 44 | + message(STATUS "CalVer ${calver} maps to ABI ${abi_major}.${abi_minor}") |
| 45 | +
|
| 46 | +
|
| 47 | +Result Variables |
| 48 | +^^^^^^^^^^^^^^^^ |
| 49 | + Variables matching the contents of ``major_output_var`` and ``minor_output_var`` will be set in the parent |
| 50 | + scope with the computed ABI version components. |
| 51 | +
|
| 52 | + ``${major_output_var}`` |
| 53 | + Contains the ABI major version component |
| 54 | +
|
| 55 | + ``${minor_output_var}`` |
| 56 | + Contains the ABI minor version component |
| 57 | +
|
| 58 | +#]=======================================================================] |
| 59 | +# cmake-lint: disable=C0112 |
| 60 | +function(determine_cuvs_abi_version cal_ver) |
| 61 | + set(options) |
| 62 | + set(one_value "MAJOR" "MINOR") |
| 63 | + set(multi_value) |
| 64 | + cmake_parse_arguments(_CUVS_RAPIDS "${options}" "${one_value}" "${multi_value}" ${ARGN}) |
| 65 | + |
| 66 | + rapids_cmake_parse_version(MAJOR ${cal_ver} cal_ver_major) |
| 67 | + rapids_cmake_parse_version(MINOR ${cal_ver} cal_ver_minor) |
| 68 | + |
| 69 | + # Encode the last ABI break |
| 70 | + set(current_major_abi_ver "1") # The current ABI major value |
| 71 | + set(abi_base_year "26") # What year the current ABI major occurred in |
| 72 | + set(abi_base_month "04") # What month the current ABI major occurred in |
| 73 | + # compute the abi version |
| 74 | + if(cal_ver_major STREQUAL abi_base_year) |
| 75 | + # If we are in the same year is is pretty easy to compute our abi break |
| 76 | + math(EXPR computed_abi_minor "(${cal_ver_minor}-${abi_base_month})/2") |
| 77 | + else() |
| 78 | + # |
| 79 | + math(EXPR first_year_count "(12-${abi_base_month})/2") |
| 80 | + math(EXPR extra_years "(${cal_ver_major} - ${abi_base_year} - 1) * 6") |
| 81 | + math(EXPR this_year_count "(${cal_ver_minor})/2") |
| 82 | + math(EXPR computed_abi_minor "${first_year_count} + ${extra_years} + ${this_year_count}") |
| 83 | + endif() |
| 84 | + |
| 85 | + set(${_CUVS_RAPIDS_MAJOR} |
| 86 | + ${computed_abi_major} |
| 87 | + PARENT_SCOPE |
| 88 | + ) |
| 89 | + set(${_CUVS_RAPIDS_MINOR} |
| 90 | + ${computed_abi_minor} |
| 91 | + PARENT_SCOPE |
| 92 | + ) |
| 93 | +endfunction() |
0 commit comments