From 43b0ed1b219284fd74db7a93dd49bb29681fd7bb Mon Sep 17 00:00:00 2001 From: Jeremy Rifkin <51220084+jeremy-rifkin@users.noreply.github.com> Date: Sat, 21 Dec 2024 15:41:13 -0600 Subject: [PATCH] Add version macros header --- CMakeLists.txt | 5 +++++ README.md | 4 +++- cmake/InstallRules.cmake | 1 + cmake/in/version-hpp.in | 11 +++++++++++ test/demo.cpp | 1 + 5 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 cmake/in/version-hpp.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 601e632..4f41504 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -161,6 +161,11 @@ target_compile_options( ${warning_options} ) +set(CPPTRACE_VERSION_MAJOR ${CMAKE_PROJECT_VERSION_MAJOR}) +set(CPPTRACE_VERSION_MINOR ${CMAKE_PROJECT_VERSION_MINOR}) +set(CPPTRACE_VERSION_PATCH ${CMAKE_PROJECT_VERSION_PATCH}) +configure_file("${PROJECT_SOURCE_DIR}/cmake/in/version-hpp.in" "${PROJECT_BINARY_DIR}/include/cpptrace/version.hpp") + # ---- Generate Build Info Headers ---- if(build_type STREQUAL "STATIC") diff --git a/README.md b/README.md index 941e30c..3c5e7c7 100644 --- a/README.md +++ b/README.md @@ -787,8 +787,10 @@ Cpptrace provides a handful of headers to make inclusion more minimal. | `cpptrace/from_current.hpp` | [Traces From All Exceptions](#traces-from-all-exceptions) | | `cpptrace/io.hpp` | `operator<<` overloads for `std::ostream` and `std::formatter`s | | `cpptrace/utils.hpp` | Utility functions, configuration functions, and terminate utilities ([Utilities](#utilities), [Configuration](#configuration), and [Terminate Handling](#terminate-handling)) | +| `cpptrace/version.hpp` | Library version macros | -The main cpptrace header is `cpptrace/cpptrace.hpp` which includes everything other than `from_current.hpp`. +The main cpptrace header is `cpptrace/cpptrace.hpp` which includes everything other than `from_current.hpp` and +`version.hpp`. # Supported Debug Formats diff --git a/cmake/InstallRules.cmake b/cmake/InstallRules.cmake index 85aa69f..b72d365 100644 --- a/cmake/InstallRules.cmake +++ b/cmake/InstallRules.cmake @@ -5,6 +5,7 @@ include(CMakePackageConfigHelpers) install( DIRECTORY "${PROJECT_SOURCE_DIR}/include/" # our header files + "${PROJECT_BINARY_DIR}/include/" # generated header files DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" COMPONENT ${package_name}-development # PATTERN "**/third_party" EXCLUDE # skip third party directory diff --git a/cmake/in/version-hpp.in b/cmake/in/version-hpp.in new file mode 100644 index 0000000..34e043d --- /dev/null +++ b/cmake/in/version-hpp.in @@ -0,0 +1,11 @@ +#ifndef CPPTRACE_VERSION_HPP +#define CPPTRACE_VERSION_HPP + +#define CPPTRACE_VERSION_MAJOR @CPPTRACE_VERSION_MAJOR@ +#define CPPTRACE_VERSION_MINOR @CPPTRACE_VERSION_MINOR@ +#define CPPTRACE_VERSION_PATCH @CPPTRACE_VERSION_PATCH@ + +#define CPPTRACE_TO_VERSION(MAJOR, MINOR, PATCH) ((MAJOR) * 10000 + (MINOR) * 100 + (PATCH)) +#define CPPTRACE_VERSION CPPTRACE_TO_VERSION(CPPTRACE_VERSION_MAJOR, CPPTRACE_VERSION_MINOR, CPPTRACE_VERSION_PATCH) + +#endif diff --git a/test/demo.cpp b/test/demo.cpp index 46ba38d..f51b523 100644 --- a/test/demo.cpp +++ b/test/demo.cpp @@ -1,4 +1,5 @@ #include +#include #include #include