Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
flagarde committed May 14, 2024
1 parent 6df9704 commit 5e1288b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
2 changes: 2 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
add_executable(KhaosVersion.example KhaosVersion.cpp)
target_link_libraries(KhaosVersion.example PRIVATE Khaos::Khaos)
add_test(NAME KhaosVersion.example COMMAND KhaosVersion.example)

add_executable(Compiler.example Compiler.cpp)
target_link_libraries(Compiler.example PRIVATE Khaos::Khaos)
add_test(NAME Compiler.example COMMAND Compiler.example)
19 changes: 14 additions & 5 deletions include/Khaos/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
#ifndef KHAOS_VERSION_H_
#define KHAOS_VERSION_H_

#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
#endif

/*!
* \file Version.h
* \brief Define macros to set, get versions.
Expand Down Expand Up @@ -43,7 +48,7 @@
* #define KHAOS_DEFINE_name_VERSION_PRIVATE() SET_VERSION(2,3,4,5)
* \endcode
*/
#define SET_VERSION(major, minor, patch, tweak) ((((major)*1UL % (1 << 16)) << 48) + (((minor)*1UL % (1 << 16)) << 32) + (((patch)*1UL % (1 << 16)) << 16) + ((tweak)*1UL % (1 << 16))) /* //NOSONAR */
#define SET_VERSION(major, minor, patch, tweak) ((((major)*1ULL % (1 << 16)) << 48) + (((minor)*1ULL % (1 << 16)) << 32) + (((patch)*1ULL % (1 << 16)) << 16) + ((tweak)*1ULL % (1 << 16))) /* //NOSONAR */

/*!
* \hideinitializer
Expand All @@ -52,7 +57,7 @@
*
* \note Value can be directly used in both preprocessor and compiler expressions for comparison to other similarly defined values.
*/
#define GET_VERSION_MAJOR(name) ((((KHAOS_DEFINE_##name##_VERSION_PRIVATE()) * 1UL) >> 48) % (1 << 16)) /* //NOSONAR */
#define GET_VERSION_MAJOR(name) ((((KHAOS_DEFINE_##name##_VERSION_PRIVATE()) * 1ULL) >> 48) % (1 << 16)) /* //NOSONAR */

/*!
* \hideinitializer
Expand All @@ -61,7 +66,7 @@
*
* \note Value can be directly used in both preprocessor and compiler expressions for comparison to other similarly defined values.
*/
#define GET_VERSION_MINOR(name) ((((KHAOS_DEFINE_##name##_VERSION_PRIVATE()) * 1UL) >> 32) % (1 << 16)) /* //NOSONAR */
#define GET_VERSION_MINOR(name) ((((KHAOS_DEFINE_##name##_VERSION_PRIVATE()) * 1ULL) >> 32) % (1 << 16)) /* //NOSONAR */

/*!
* \hideinitializer
Expand All @@ -70,7 +75,7 @@
*
* \note Value can be directly used in both preprocessor and compiler expressions for comparison to other similarly defined values.
*/
#define GET_VERSION_PATCH(name) ((((KHAOS_DEFINE_##name##_VERSION_PRIVATE()) * 1UL) >> 16) % (1 << 16)) /* //NOSONAR */
#define GET_VERSION_PATCH(name) ((((KHAOS_DEFINE_##name##_VERSION_PRIVATE()) * 1ULL) >> 16) % (1 << 16)) /* //NOSONAR */

/*!
* \hideinitializer
Expand All @@ -79,6 +84,10 @@
*
* \note Value can be directly used in both preprocessor and compiler expressions for comparison to other similarly defined values.
*/
#define GET_VERSION_TWEAK(name) (((KHAOS_DEFINE_##name##_VERSION_PRIVATE()) * 1UL) % (1 << 16)) /* //NOSONAR */
#define GET_VERSION_TWEAK(name) (((KHAOS_DEFINE_##name##_VERSION_PRIVATE()) * 1ULL) % (1 << 16)) /* //NOSONAR */

#if defined(__clang__)
#pragma clang diagnostic pop
#endif

#endif /* KHAOS_VERSION_H_ */
12 changes: 11 additions & 1 deletion src/KhaosVersion.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@

#ifndef KHAOS_KHAOS_VERSION_H_
#define KHAOS_KHAOS_VERSION_H_

#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
#endif

#include "Khaos/Version.h"

/*!
Expand All @@ -34,7 +40,11 @@
\note Use #GET_VERSION_MAJOR(Khaos), #GET_VERSION_MINOR(Khaos), #GET_VERSION_PATCH(Khaos) to parse it.
*/
/* clang-format off*/
#define KHAOS_DEFINE_Khaos_VERSION_PRIVATE() SET_VERSION(@Khaos_VERSION_MAJOR@UL,@Khaos_VERSION_MINOR@UL,@Khaos_VERSION_PATCH@UL,@Khaos_VERSION_TWEAK@UL)
#define KHAOS_DEFINE_Khaos_VERSION_PRIVATE() SET_VERSION(@Khaos_VERSION_MAJOR@ULL,@Khaos_VERSION_MINOR@ULL,@Khaos_VERSION_PATCH@ULL,@Khaos_VERSION_TWEAK@ULL)
/* clang-format on*/

#if defined(__clang__)
#pragma clang diagnostic pop
#endif

#endif /* KHAOS_KHAOS_VERSION_H_*/

0 comments on commit 5e1288b

Please sign in to comment.