-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### Briefly, what does this PR introduce? This adds a version header to the installation of EDM4eic. This allows us to make downstream code behave differently based on the version. Note: with `.gitattributes` (in particular `export-subst`) we could automate the filling of this version information with the most recent tag and such. Maybe something to look into. --------- Co-authored-by: Dmitry Kalinkin <[email protected]>
- Loading branch information
Showing
2 changed files
with
106 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Ref: https://github.com/key4hep/EDM4hep/blob/e0762272e0f718df2811fc1bf4590af976bac70d/EDM4hepVersion.h.in | ||
|
||
#ifndef EDM4EIC_VERSION_H | ||
#define EDM4EIC_VERSION_H | ||
|
||
#include <cstdint> | ||
#include <tuple> | ||
#include <ostream> | ||
#if __cplusplus >= 202002L | ||
#include <compare> | ||
#endif | ||
|
||
// Some preprocessor constants and macros for the use cases where they might be | ||
// necessary | ||
|
||
/// Define a version to be used in edm4eic. | ||
#define EDM4EIC_VERSION(major, minor, patch) ((UINT64_C(major) << 32) | (UINT64_C(minor) << 16) | (UINT64_C(patch))) | ||
/// Get the major version from a preprocessor defined version | ||
#define EDM4EIC_MAJOR_VERSION(v) (((v) & (-1UL >> 16)) >> 32) | ||
/// Get the minor version from a preprocessor defined version | ||
#define EDM4EIC_MINOR_VERSION(v) (((v) & (-1UL >> 32)) >> 16) | ||
/// Get the patch version from a preprocessor defined version | ||
#define EDM4EIC_PATCH_VERSION(v) ((v) & (-1UL >> 48)) | ||
|
||
// Some helper constants that are populated by the cmake configure step | ||
#define EDM4EIC_VERSION_MAJOR @EDM4EIC_VERSION_MAJOR@ | ||
#define EDM4EIC_VERSION_MINOR @EDM4EIC_VERSION_MINOR@ | ||
#define EDM4EIC_VERSION_PATCH @EDM4EIC_VERSION_PATCH@ | ||
#define edm4hep_VERSION EDM4EIC_VERSION(EDM4EIC_VERSION_MAJOR, EDM4EIC_VERSION_MINOR, EDM4EIC_VERSION_PATCH) | ||
|
||
/// The encoded version with which EDM4EIC has been built | ||
#define EDM4EIC_BUILD_VERSION EDM4EIC_VERSION(EDM4EIC_VERSION_MAJOR, EDM4EIC_VERSION_MINOR, EDM4EIC_VERSION_PATCH) | ||
|
||
namespace edm4eic::version { | ||
|
||
/** | ||
* Version class consisting of 3 16 bit unsigned integers to hold the major, | ||
* minor and patch version. Provides constexpr comparison operators that allow | ||
* to use this class in constexpr-if clauses. | ||
*/ | ||
struct Version { | ||
uint16_t major{0}; | ||
uint16_t minor{0}; | ||
uint16_t patch{0}; | ||
|
||
#if __cplusplus >= 202002L | ||
auto operator<=>(const Version&) const = default; | ||
#else | ||
// No spaceship yet in c++17 | ||
#define DEFINE_COMP_OPERATOR(OP) \ | ||
constexpr bool operator OP(const Version& o) const noexcept { \ | ||
return std::tie(major, minor, patch) OP std::tie(o.major, o.minor, o.patch); \ | ||
} | ||
|
||
DEFINE_COMP_OPERATOR(<) | ||
DEFINE_COMP_OPERATOR(<=) | ||
DEFINE_COMP_OPERATOR(>) | ||
DEFINE_COMP_OPERATOR(>=) | ||
DEFINE_COMP_OPERATOR(==) | ||
DEFINE_COMP_OPERATOR(!=) | ||
|
||
#undef DEFINE_COMP_OPERATOR | ||
#endif | ||
|
||
friend std::ostream& operator<<(std::ostream&, const Version& v); | ||
}; | ||
|
||
inline std::ostream& operator<<(std::ostream& os, const Version& v) { | ||
return os << v.major << "." << v.minor << "." << v.patch; | ||
} | ||
|
||
/** | ||
* The current build version | ||
*/ | ||
static constexpr Version build_version{EDM4EIC_VERSION_MAJOR, EDM4EIC_VERSION_MINOR, EDM4EIC_VERSION_PATCH}; | ||
|
||
/** | ||
* Decode a version from a 64 bit unsigned | ||
*/ | ||
static constexpr Version decode_version(uint64_t version) noexcept { | ||
return Version{ | ||
(uint16_t) EDM4EIC_MAJOR_VERSION(version), | ||
(uint16_t) EDM4EIC_MINOR_VERSION(version), | ||
(uint16_t) EDM4EIC_PATCH_VERSION(version) | ||
}; | ||
} | ||
} | ||
|
||
|
||
#endif |