Skip to content

Commit

Permalink
Add C++ access to project version
Browse files Browse the repository at this point in the history
  • Loading branch information
SSoelvsten committed Nov 30, 2023
1 parent d822135 commit 874f629
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,7 @@ INPUT = @CMAKE_SOURCE_DIR@/docs/index.md \
@CMAKE_SOURCE_DIR@/docs/cite.md \
@CMAKE_SOURCE_DIR@/docs/ \
@CMAKE_SOURCE_DIR@/src/adiar/adiar.h \
@CMAKE_BINARY_DIR@/src/adiar/version.h \
@CMAKE_SOURCE_DIR@/src/adiar/exec_policy.h \
@CMAKE_SOURCE_DIR@/src/adiar/functional.h \
@CMAKE_SOURCE_DIR@/src/adiar/bdd.h \
Expand Down
3 changes: 3 additions & 0 deletions src/adiar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ set_property(GLOBAL PROPERTY USE_FOLDERS On)
# ============================================================================ #
# Link up files for the library

configure_file(version.h.in version.h)

set(HEADERS
# adiar
adiar.h
Expand All @@ -15,6 +17,7 @@ set(HEADERS
functional.h
statistics.h
types.h
version.h

# adiar/bdd
bdd.h
Expand Down
3 changes: 3 additions & 0 deletions src/adiar/adiar.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

#include <string>

////////////////////////////////////////////////////////////////////////////////
#include <adiar/version.h>

////////////////////////////////////////////////////////////////////////////////
/// Core types
#include <adiar/exception.h>
Expand Down
52 changes: 52 additions & 0 deletions src/adiar/version.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#ifndef ADIAR_VERSION_H
#define ADIAR_VERSION_H

#include <string_view>

namespace adiar
{
//////////////////////////////////////////////////////////////////////////////
/// \addtogroup module__adiar
///
/// \{

//////////////////////////////////////////////////////////////////////////////
/// \name Version Number
///
/// \{

//////////////////////////////////////////////////////////////////////////////
/// \brief Major version of Adiar.
//////////////////////////////////////////////////////////////////////////////
constexpr unsigned short version_major = @CMAKE_PROJECT_VERSION_MAJOR@;

//////////////////////////////////////////////////////////////////////////////
/// \brief Minor version of Adiar.
//////////////////////////////////////////////////////////////////////////////
constexpr unsigned short version_minor = @CMAKE_PROJECT_VERSION_MINOR@;

//////////////////////////////////////////////////////////////////////////////
/// \brief Patch version of Adiar.
//////////////////////////////////////////////////////////////////////////////
constexpr unsigned short version_patch = @CMAKE_PROJECT_VERSION_PATCH@;

//////////////////////////////////////////////////////////////////////////////
/// \brief Combined version number of Adiar into a single integer with two
/// decimal digits for the *major*, *minor*, and *patch* version.
//////////////////////////////////////////////////////////////////////////////
constexpr unsigned short version =
(version_major * 10'000) + (version_minor*100) + version_patch;

//////////////////////////////////////////////////////////////////////////////
/// \brief A pre-formatted string for version of the Adiar version.
//////////////////////////////////////////////////////////////////////////////
constexpr std::string_view version_str = "@CMAKE_PROJECT_VERSION@";

/// \}
//////////////////////////////////////////////////////////////////////////////

/// \}
//////////////////////////////////////////////////////////////////////////////
}

#endif // ADIAR_VERSION_H
5 changes: 5 additions & 0 deletions src/playground.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
#include <adiar/adiar.h>

int main(int argc, char* argv[]) {
std::cout << "-------------------------------------------------------------------------------\n"
<< " Adiar " << adiar::version_str << " : Playground \n"
<< "-------------------------------------------------------------------------------\n"
<< "\n";

size_t M = 1024;

try {
Expand Down

0 comments on commit 874f629

Please sign in to comment.