Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single point of truth Version Info #72

Open
sithlord48 opened this issue Oct 2, 2022 · 1 comment
Open

Single point of truth Version Info #72

sithlord48 opened this issue Oct 2, 2022 · 1 comment

Comments

@sithlord48
Copy link
Contributor

The project should use a symantic version tag like v.1.0.0
You can then use CMake to parse gits info and use the most recent symantic tag for your Major.minor.patch. For the tweak value i like to the git default of commits since last tag. This can then be exposed to the application with configure_file and the application can use the same version number. The package can also get this number.

@sithlord48
Copy link
Contributor Author

I do this in another repo (It requires a v#.#.# tag in your repo to this is your base version)

#Replace the Version with the numbers for the most recent symantic tag, then update it when your change the tag. 
Project (FOO VERSION 1.0.0 ...)  
# Get the version from git if it's a git repository
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
  find_package(Git)
  if(GIT_FOUND)
    execute_process(
      COMMAND ${GIT_EXECUTABLE} describe --long --match v* --always
      WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
      OUTPUT_VARIABLE GITREV
      ERROR_QUIET
      OUTPUT_STRIP_TRAILING_WHITESPACE)
      string(FIND ${GITREV} "v" isRev)
      if(NOT ifRev EQUAL -1)
        string(REGEX MATCH [0-9]+ MAJOR ${GITREV})
        string(REGEX MATCH \\.[0-9]+ MINOR ${GITREV})
        string(REPLACE "." "" MINOR "${MINOR}")
        string(REGEX MATCH [0-9]+\- PATCH ${GITREV})
        string(REPLACE "-" "" PATCH "${PATCH}")
        string(REGEX MATCH \-[0-9]+\- TWEAK ${GITREV})
        string(REPLACE "-" "" TWEAK "${TWEAK}")
        set(CMAKE_PROJECT_VERSION_MAJOR ${MAJOR})
        set(CMAKE_PROJECT_VERSION_MINOR ${MINOR})
        set(CMAKE_PROJECT_VERSION_PATCH ${PATCH})
        set(CMAKE_PROJECT_VERSION_TWEAK ${TWEAK})
      elseif(NOT ${GITREV} STREQUAL "")
        set(CMAKE_PROJECT_VERSION_TWEAK ${GITREV})
      endif()
        set(CMAKE_PROJECT_VERSION "${MAJOR}.${MINOR}.${PATCH}.${TWEAK}")
  endif()
endif()


#SET FOO_VERSION Used for user facing strings
set(FOO_VERSION "${CMAKE_PROJECT_VERSION_MAJOR}.${CMAKE_PROJECT_VERSION_MINOR}")
if(NOT CMAKE_PROJECT_VERSION_PATCH EQUAL 0)
    string(APPEND FOO_VERSION ".${CMAKE_PROJECT_VERSION_PATCH}")
endif()
if(NOT CMAKE_PROJECT_VERSION_TWEAK EQUAL 0)
    string(APPEND FOO_VERSION "-${CMAKE_PROJECT_VERSION_TWEAK}")
endif()
message(STATUS "Building FOO: ${FOO_VERSION}")

Later on i use configure file to inject FOO_VERSION in a header. i use that header to then set the version of the qApp this sets it for everything. The other nice part about this is CMake knows so you can also use this for rc files and in your Bundle so the correct version are shown on windows and mac os .

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

No branches or pull requests

2 participants