|
| 1 | +/* |
| 2 | + * Copyright 2023 Robert Bosch GmbH |
| 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 | + * SPDX-License-Identifier: Apache-2.0 |
| 17 | + */ |
| 18 | +/** |
| 19 | + * \file version.hpp |
| 20 | + * |
| 21 | + * This file just provides version information. |
| 22 | + * |
| 23 | + * We expect the CMakeLists.txt to define a constant CLOE_VERSION_U32, |
| 24 | + * which takes the following format: |
| 25 | + * |
| 26 | + * (EPOCH << 24) | (MAJOR_VERSION << 16) | (MINOR_VERSION << 8) | PATCH_VERSION |
| 27 | + * |
| 28 | + * Each version consists of at most 8 bits, so 256 potential values, including 0. |
| 29 | + * The epoch starts with 0, and is bumped after each version naming scheme. |
| 30 | + * |
| 31 | + * The following macros are defined from CLOE_VERSION_U32: |
| 32 | + * |
| 33 | + * - CLOE_VERSION_EPOCH |
| 34 | + * - CLOE_VERSION_MAJOR |
| 35 | + * - CLOE_VERSION_MINOR |
| 36 | + * - CLOE_VERSION_PATCH |
| 37 | + * |
| 38 | + * It's unlikely that EPOCH will ever be changed, but better safe than sorry. |
| 39 | + * |
| 40 | + * You can check for some Cloe version like so: |
| 41 | + * |
| 42 | + * #if CLOE_VERSION_U32 < VERSION_U32(0, 1, 0, 0) |
| 43 | + */ |
| 44 | + |
| 45 | +#pragma once |
| 46 | + |
| 47 | +/** |
| 48 | + * VERSION_U32 is a helper macro to create 32-bit unsigned |
| 49 | + * Epoch-Major-Minor-Patch version integers. |
| 50 | + * |
| 51 | + * These can be then conveniently used to compare versions with the normal |
| 52 | + * integer comparison operators. |
| 53 | + * |
| 54 | + * For example: |
| 55 | + * |
| 56 | + * #if CLOE_VERSION_U32 >= VERSION_U32(1, 0, 0, 0) |
| 57 | + * #error "cloe epoch > 0 not supported" |
| 58 | + * #else if (CLOE_VERSION_U32 >= VERSION_U32(0, 1, 0, 0)) && (CLOE_VERSION_U32 < VERSION_U32(0, 1, 2, 0)) |
| 59 | + * // Code for cloe versions between 1.0 and 1.1.* |
| 60 | + * #endif |
| 61 | + * |
| 62 | + * Note: This macro is defined with the same name and in the same way as |
| 63 | + * fable/version.hpp and is not redefined here if already defined. |
| 64 | + * As long as these macros exist it is unlikely that they will change |
| 65 | + * in mechanism or form, as this would break all code that depends on |
| 66 | + * version comparison. |
| 67 | + */ |
| 68 | +#ifndef VERSION_U32 |
| 69 | +#define VERSION_U32(epoch, major, minor, patch) \ |
| 70 | + (((epoch) << 24) | ((major) << 16) | ((minor) << 8) | (patch)) |
| 71 | +#endif |
| 72 | + |
| 73 | +#ifndef CLOE_VERSION |
| 74 | +#define CLOE_VERSION "@CLOE_VERSION@" |
| 75 | +#endif |
| 76 | + |
| 77 | +#ifndef CLOE_VERSION_U32 |
| 78 | +#define CLOE_VERSION_U32 @CLOE_VERSION_U32@ |
| 79 | +#endif |
| 80 | + |
| 81 | +#define CLOE_VERSION_EPOCH ((CLOE_VERSION_U32 >> 24) && 0xff) |
| 82 | +#define CLOE_VERSION_MAJOR ((CLOE_VERSION_U32 >> 16) && 0xff) |
| 83 | +#define CLOE_VERSION_MINOR ((CLOE_VERSION_U32 >> 8) && 0xff) |
| 84 | +#define CLOE_VERSION_PATCH ((CLOE_VERSION_U32 >> 0) && 0xff) |
0 commit comments