You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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 .
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.The text was updated successfully, but these errors were encountered: