Skip to content

Commit 5f49b0f

Browse files
committed
add version comparision macro & test for it
1 parent 5408d4c commit 5f49b0f

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

rerun_cpp/src/rerun/c/sdk_info.h

+14
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,17 @@
1212

1313
/// Patch version of the Rerun C SDK.
1414
#define RERUN_SDK_HEADER_VERSION_PATCH 0
15+
16+
/// Is the Rerun library version greater or equal to this?
17+
///
18+
/// Example usage:
19+
/// ```
20+
/// #if RERUN_VERSION_GE(0, 18, 0)
21+
/// // Use features from Rerun 0.18
22+
/// #endif
23+
/// ```
24+
#define RERUN_VERSION_GE(major, minor, patch) \
25+
((major) == RERUN_SDK_HEADER_VERSION_MAJOR \
26+
? ((minor) == RERUN_SDK_HEADER_VERSION_MINOR ? (patch) <= RERUN_SDK_HEADER_VERSION_PATCH \
27+
: (minor) <= RERUN_SDK_HEADER_VERSION_MINOR) \
28+
: (major) <= RERUN_SDK_HEADER_VERSION_MAJOR)

rerun_cpp/tests/sdk_info.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <rerun.hpp>
2+
3+
static_assert(RERUN_VERSION_GE(0, 18, 0), "Rerun version was expected to be at least 0.18.0");
4+
static_assert(
5+
RERUN_VERSION_GE(
6+
RERUN_SDK_HEADER_VERSION_MAJOR, RERUN_SDK_HEADER_VERSION_MINOR,
7+
RERUN_SDK_HEADER_VERSION_PATCH
8+
),
9+
"Rerun version is equal to this version."
10+
);
11+
static_assert(
12+
!RERUN_VERSION_GE(
13+
RERUN_SDK_HEADER_VERSION_MAJOR, RERUN_SDK_HEADER_VERSION_MINOR,
14+
RERUN_SDK_HEADER_VERSION_PATCH + 1
15+
),
16+
"Rerun version is not greater than this version."
17+
);
18+
static_assert(
19+
!RERUN_VERSION_GE(
20+
RERUN_SDK_HEADER_VERSION_MAJOR, RERUN_SDK_HEADER_VERSION_MINOR + 1,
21+
RERUN_SDK_HEADER_VERSION_PATCH
22+
),
23+
"Rerun version is not greater than this version."
24+
);
25+
static_assert(
26+
!RERUN_VERSION_GE(
27+
RERUN_SDK_HEADER_VERSION_MAJOR + 1, RERUN_SDK_HEADER_VERSION_MINOR,
28+
RERUN_SDK_HEADER_VERSION_PATCH
29+
),
30+
"Rerun version is not greater than this version."
31+
);
32+
33+
#if RERUN_VERSION_GE(0, 18, 0)
34+
static_assert(true, "Rerun can be used in a macro.");
35+
#else
36+
static_assert(false, "Rerun can be used in a macro, but we shouldn't be able to get here.");
37+
#endif

0 commit comments

Comments
 (0)