Skip to content

Commit

Permalink
Add support tools for version management
Browse files Browse the repository at this point in the history
  • Loading branch information
fmauger committed Oct 2, 2017
1 parent 6038509 commit 570abba
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 1 deletion.
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,19 @@ endif()
# CMake/project requirements and configuration
#
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
project(Bayeux VERSION "3.1.0")
project(Bayeux)

# - Load Custom Modules
list(INSERT CMAKE_MODULE_PATH 0 ${PROJECT_SOURCE_DIR}/cmake)

# - Version number management utilities:
include(BxVersionManager)

# - Versioning only giving major and minor. Patch number is
# automatically deduced from an external file.
bx_version_set(Bayeux 3 1)
message(STATUS "[info] Project version = '${PROJECT_VERSION}'")

#-----------------------------------------------------------------------
# Common LPC utilities
#
Expand Down
8 changes: 8 additions & 0 deletions cmake/BxPackageVersions.db
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# List of released versions addressed by their MAJOR.MINOR version number
# and update through a PATCH number:
3.0.0
3.1.0
#3.2.0
#3.3.0
#4.0.0
# end
70 changes: 70 additions & 0 deletions cmake/BxVersionManager.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# CMake tools for version management
# Author: F.Mauger
# Date: 2017-09-26
# Copyright 2017 (c) François Mauger, Université de Caen Normandie

function(bx_version_build_version_number prefix_)
set(${prefix_}_VERSION
"${${prefix_}_VERSION_MAJOR}.${${prefix_}_VERSION_MINOR}.${${prefix_}_VERSION_PATCH}"
PARENT_SCOPE)
endfunction()

function(bx_version_extract_patch_from_db major_ minor_ patch_)
set(_version_patch 0)
if (EXISTS ${PROJECT_SOURCE_DIR}/cmake/BxPackageVersions.db)
file(STRINGS
${PROJECT_SOURCE_DIR}/cmake/BxPackageVersions.db
_bx_package_versions_lines
REGEX "^([0-9]+)\\.([0-9]+)\\.([0-9+])"
)
foreach(line ${_bx_package_versions_lines})
string(REPLACE "." ";" _version_list ${line})
list(GET _version_list 0 _version_major)
list(GET _version_list 1 _version_minor)
list(GET _version_list 2 _version_patch)
if(${_version_major} EQUAL ${major_})
if(${_version_minor} EQUAL ${minor_})
set(${patch_} ${_version_patch} PARENT_SCOPE)
endif()
endif()
endforeach()
else()
set(${patch_} ${_version_patch} PARENT_SCOPE)
endif()
endfunction()

macro(bx_version_set prefix_ major_ minor_)
set(_version_major ${major_})
set(_version_minor ${minor_})
set(_version_patch 0)
set(${prefix_}_VERSION_MAJOR ${_version_major})
set(${prefix_}_VERSION_MINOR ${_version_minor})
set(${prefix_}_VERSION_PATCH ${_version_patch})
bx_version_extract_patch_from_db(
${${prefix_}_VERSION_MAJOR}
${${prefix_}_VERSION_MINOR}
${prefix_}_VERSION_PATCH
)
bx_version_build_version_number(${prefix_})
message(STATUS "[info] bx_version_set: Major = ${${prefix_}_VERSION_MAJOR}")
message(STATUS "[info] bx_version_set: Minor = ${${prefix_}_VERSION_MINOR}")
message(STATUS "[info] bx_version_set: Patch = ${${prefix_}_VERSION_PATCH}")
message(STATUS "[info] bx_version_set: Version = ${${prefix_}_VERSION}")
if (NOT PROJECT_VERSION)
message(STATUS "[info] bx_version_set: Setting project version...")
set(PROJECT_VERSION "${${prefix_}_VERSION}")
endif()
if (NOT PROJECT_VERSION_MAJOR)
message(STATUS "[info] bx_version_set: Setting project version major...")
set(PROJECT_VERSION_MAJOR "${${prefix_}_VERSION_MAJOR}")
endif()
if (NOT PROJECT_VERSION_MINOR)
message(STATUS "[info] bx_version_set: Setting project version minor...")
set(PROJECT_VERSION_MINOR_VERSION "${${prefix_}_VERSION_MINOR}")
endif()
if (NOT PROJECT_VERSION_PATCH)
message(STATUS "[info] bx_version_set: Setting project version patch...")
set(PROJECT_VERSION_PATCH "${${prefix_}_VERSION_MINOR}")
endif()
message(STATUS "[info] bx_version_set: Project version = '${PROJECT_VERSION}'")
endmacro()
1 change: 1 addition & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ include(CMakePackageConfigHelpers)
# - Versioning file is the same for the build and install trees
write_basic_package_version_file(
${BAYEUX_BUILD_CMAKEDIR}/${BAYEUX_TAG}/BayeuxConfigVersion.cmake
VERSION ${Bayeux_VERSION}
COMPATIBILITY SameMajorVersion
)

Expand Down

0 comments on commit 570abba

Please sign in to comment.