Skip to content
Snippets Groups Projects
Commit 00962b0a authored by Corné Lukken's avatar Corné Lukken
Browse files

CWG-45: Finish cleaning up c++ versioning

parent 00fce5db
No related branches found
No related tags found
1 merge request!9CWG-45: Implement git tag based version extraction
Pipeline #63808 waiting for manual action
Pipeline: C++ project

#63809

    ......@@ -7,12 +7,9 @@ include(GitVersion)
    get_version_info({{cookiecutter.project_slug}} "${CMAKE_CURRENT_SOURCE_DIR}")
    set(project_slug {{cookiecutter.project_slug}})
    set(${project_slug}_VERSION "${${project_slug}_VERSION_MAJOR}.${${project_slug}_VERSION_MINOR}.${${project_slug}_VERSION_PATCH}")
    project({{cookiecutter.project_slug}} VERSION ${${project_slug}_VERSION})
    message("VERSION: ${${project_slug}_VERSION}")
    set(CMAKE_CXX_STANDARD 17)
    set(CMAKE_CXX_STANDARD_REQUIRED YES)
    set(CMAKE_CXX_EXTENSIONS OFF)
    ......
    ......@@ -36,6 +36,15 @@ For instance:
    - Install the project globally: ``ninja -C ./build/ install``
    - Clean caches: `ninja -C ./build/ clean`
    ## Versioning
    This project uses git tags or branch names to determine the current version of the
    software. The version information is automatically made available in CMake and can be
    made available in C/C++ by dynamically adding a generated header.
    See for details:
    - https://github.com/jahnf/CMake-GitVersion/blob/develop/cmake/GitVersion.cmake
    ## Contributing
    To contribute, please create a feature branch and a "Draft" merge request. Upon
    ......
    # Auto generated archive version information
    # Included in created source archives
    set(@PREFIX@_VERSION "@VERSION@")
    set(@PREFIX@_VERSION_MAJOR "@VERSION_MAJOR@")
    set(@PREFIX@_VERSION_MINOR "@VERSION_MINOR@")
    set(@PREFIX@_VERSION_PATCH "@VERSION_PATCH@")
    ......
    #include "@PREFIX@-GitVersion.h"
    namespace @PREFIX@ {
    const char* version() { return "@VERSION@"; }
    const char* version_string() { return "@VERSION_STRING@"; }
    unsigned int version_major() { return @VERSION_MAJOR@; }
    unsigned int version_minor() { return @VERSION_MINOR@; }
    ......
    ......@@ -45,6 +45,7 @@ set(_GitVersion_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}")
    # Helper method - usually never called directly:
    # Get the version information for a directory, sets the following variables
    # ${prefix}_VERSION_SUCCESS // 0 on error (e.g. git not found), 1 on success
    # ${prefix}_VERSION
    # ${prefix}_VERSION_MAJOR
    # ${prefix}_VERSION_MINOR
    # ${prefix}_VERSION_PATCH
    ......@@ -67,6 +68,7 @@ set(_GitVersion_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}")
    # The environment variable FALLBACK_BRANCH will be used if the branch cannot be determined
    function(get_version_info prefix directory)
    set(${prefix}_VERSION_SUCCESS 0 PARENT_SCOPE)
    set(${prefix}_VERSION "0.0.0")
    set(${prefix}_VERSION_MAJOR 0)
    set(${prefix}_VERSION_MINOR 0)
    set(${prefix}_VERSION_PATCH 0)
    ......@@ -303,6 +305,10 @@ function(get_version_info prefix directory)
    set(${prefix}_VERSION_PATCH ${${prefix}_VERSION_PATCH} PARENT_SCOPE)
    set(${prefix}_VERSION_DISTANCE ${${prefix}_VERSION_DISTANCE} PARENT_SCOPE)
    # build version
    set(VERSION "${${prefix}_VERSION_MAJOR}.${${prefix}_VERSION_MINOR}.${${prefix}_VERSION_PATCH}")
    set(${prefix}_VERSION "${VERSION}" PARENT_SCOPE)
    # Build version string...
    set(VERSION_STRING "${${prefix}_VERSION_MAJOR}.${${prefix}_VERSION_MINOR}")
    if(NOT ${${prefix}_VERSION_PATCH} EQUAL 0)
    ......@@ -365,6 +371,7 @@ function(add_version_info)
    endif()
    # Set default values, in case sth goes wrong
    set(VERSION "0.0.0")
    set(VERSION_MAJOR 0)
    set(VERSION_MINOR 0)
    set(VERSION_PATCH 0)
    ......@@ -473,6 +480,7 @@ function(add_version_info)
    message(STATUS "Version-Info: Failure during version retrieval. Possible incomplete version information!")
    endif()
    # Test if we are building from an archive that has generated version information
    set(VERSION ${${VI_PREFIX}_VERSION})
    set(VERSION_MAJOR ${${VI_PREFIX}_VERSION_MAJOR})
    set(VERSION_MINOR ${${VI_PREFIX}_VERSION_MINOR})
    set(VERSION_PATCH ${${VI_PREFIX}_VERSION_PATCH})
    ......@@ -484,6 +492,7 @@ function(add_version_info)
    set(VERSION_ISDIRTY ${${VI_PREFIX}_VERSION_ISDIRTY})
    set(VERSION_BRANCH ${${VI_PREFIX}_VERSION_BRANCH})
    set_target_properties(${VI_TARGET} PROPERTIES
    VERSION "${VERSION}"
    VERSION_MAJOR "${VERSION_MAJOR}"
    VERSION_MINOR "${VERSION_MINOR}"
    VERSION_PATCH "${VERSION_PATCH}"
    ......
    ......@@ -2,6 +2,7 @@
    #define @PREFIX@_GITVERSION_H
    namespace @PREFIX@ {
    const char* version();
    const char* version_string();
    unsigned int version_major();
    unsigned int version_minor();
    ......
    ......@@ -10,6 +10,7 @@ int main(int, const char **) {
    lib::Hello();
    std::cout << "CMake-GitVersion example"<< std::endl;
    std::cout << "- version: " << cpp::version() << std::endl;
    std::cout << "- version_string: " << cpp::version_string() << std::endl;
    std::cout << "- version_branch: " << cpp::version_branch() << std::endl;
    std::cout << "- version_fullhash: " << cpp::version_fullhash() << std::endl;
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment