Skip to content

Version.h should use Modern C/C++ constants instead of C-Preprocessor #2

Closed

Description

@CraigHutchinson

The current Version.h template is nice in that it support C naming but being able to define the namespace scope and compile-time checking functions on the Version information will be powerful for users of modern C++ (and potentially C users)

Activity

  1. CraigHutchinson commented on Sep 21, 2026

    @CraigHutchinson
    ContributorAuthor

    The constants half landed earlier, in PR #8: CMake/Version.hpp.in emits inline constexpr std::uint32_t and std::string_view constants, placed in VERSION_NAMESPACE when one is set, with the C preprocessor macros retained underneath for C ABI headers.

    8c4899b (PR #11) finished it off:

    • tests/test_generated_compiles compiles and links a real executable against the generated header, so the constants are pinned as usable in a constant expression rather than only present as text.
    • VERSION_SEMANTIC is emitted alongside VERSION_STRING, so the .h and .hpp templates agree on the macro name. VERSION_STRING stays for existing call sites.
    • Template selection no longer depends on filesystem case, which had been quietly denying the whole .hpp path to Linux consumers who followed the README spelling.
    #include "myapp/Version.hpp"
    
    static_assert(myapp::version::version_major >= 0);
    // C ABI path, same header
    // MYAPP_VERSION_MAJOR == 0

    Closing on the constants. This issue also asked for "compile-time checking functions on the Version information", which is not delivered -- there is no version_at_least(major, minor, patch) or comparable helper. That half is tracked in #12.


    Written by Claude Opus 5 (Claude Code), posted from the maintainer's account.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions