Skip to content
Permalink
Browse files

Re-implement versioning scheme within CMake

Use CMake to generate a "version.h" and set different version variables
according to "git describe", falling back to a default if git isn't
installed or the source directory isn't a git checkout (like a tarball
source checkout)
  • Loading branch information...
PerilousApricot committed Aug 2, 2016
1 parent 51478fa commit abb5dc0755a58199393c27cbb606b8d756b9a5bc
@@ -6,4 +6,5 @@ doc/api-autogen.rst
doc/html
doc/latex
doc/xml
src/lio/lio/version.h
venv/
@@ -1,8 +1,6 @@
# Root CMake file for LStore
cmake_minimum_required(VERSION 2.8)

set(LSTORE_PROJECT_VERSION "0.5.1-unknown_commit" CACHE STRING "Project version <major>.<minor>.<patch>[-<git-hash>[-<other-tags>]]")

# Preliminary configuration. Need to find ccache to set the defaults for the
# corresponding option
find_program(FOUND_CCACHE ccache)
@@ -35,6 +33,8 @@ option(INSTALL_DEB_RELEASE "Install deb lstore-release (may require root)" OFF)
option(INSTALL_META "Install meta-package (may require root)" OFF)
option(INSTALL_TESTS "Install test binaries" OFF)

set(LSTORE_VERSION "" CACHE STRING "Override LStore version")

if(NOT CMAKE_BUILD_TYPE)
# Has to be handled differently :(
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Build type" FORCE)
@@ -100,10 +100,11 @@ endif()
# you do it in the other order, cmake complains and reruns the CMakeLists.txt
# compilation.
project(LStore C)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
include(LStoreVersion)

# Defines
set(USE_SUPERBUILD ON)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -fvisibility=hidden -fno-strict-aliasing -Wall -Wextra -Werror -Wno-unused-parameter -Wno-deprecated-declarations -Wno-error=sign-compare")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,--exclude-libs,ALL")
@@ -0,0 +1 @@
0.5.1
@@ -1,13 +1,7 @@
macro(lstore_project_common LSTORE_PROJECT_NAME)
# Extract version components, version string is expected be in the form:
# <major>.<minor>.<patch>-<git-hash>[-<other-tags>]
string(REPLACE "." ";" VERSION_LIST "${LSTORE_PROJECT_VERSION}")
string(REPLACE "-" ";" VERSION_LIST "${VERSION_LIST}")
list(GET VERSION_LIST 0 LSTORE_PROJECT_VERSION_MAJOR)
list(GET VERSION_LIST 1 LSTORE_PROJECT_VERSION_MINOR)
list(GET VERSION_LIST 2 LSTORE_PROJECT_VERSION_PATCH)



# Make the version file.
include(${CMAKE_SOURCE_DIR}/cmake/Date.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/CompilerVersion.cmake)
@@ -25,9 +19,9 @@ macro(lstore_project_common LSTORE_PROJECT_NAME)
add_library(${LSTORE_PROJECT_NAME} ${LSTORE_PROJECT_OBJS})

# Use the project version as the version for each library (for now at least)
set(LSTORE_LIBRARY_VERSION_MAJOR ${LSTORE_PROJECT_VERSION_MAJOR})
set(LSTORE_LIBRARY_VERSION_MINOR ${LSTORE_PROJECT_VERSION_MINOR})
set(LSTORE_LIBRARY_VERSION_PATCH ${LSTORE_PROJECT_VERSION_PATCH})
set(LSTORE_LIBRARY_VERSION_MAJOR ${LSTORE_VERSION_MAJOR})
set(LSTORE_LIBRARY_VERSION_MINOR ${LSTORE_VERSION_MINOR})
set(LSTORE_LIBRARY_VERSION_PATCH ${LSTORE_VERSION_PATCH})
set(LSTORE_LIBRARY_VERSION_STRING ${LSTORE_LIBRARY_VERSION_MAJOR}.${LSTORE_LIBRARY_VERSION_MINOR}.${LSTORE_LIBRARY_VERSION_PATCH})
# Give our libraries versioning info
set_target_properties(${LSTORE_PROJECT_NAME} PROPERTIES VERSION ${LSTORE_LIBRARY_VERSION_STRING} SOVERSION ${LSTORE_LIBRARY_VERSION_MAJOR})
@@ -8,10 +8,6 @@ endif()

# Global configuration
set(CPACK_PACKAGE_NAME "LStore")
set(CPACK_PACKAGE_VERSION "0.5.1")
set(CPACK_PACKAGE_VERSION_MAJOR "0")
set(CPACK_PACKAGE_VERSION_MINOR "5")
set(CPACK_PACKAGE_VERSION_PATCH "1")
set(CPACK_PACKAGE_RELEASE ${LSTORE_PROJECT_REVISION})
set(CPACK_PACKAGE_CONTACT "Andrew Melo or Alan Tackett")
set(CPACK_PACKAGE_VENDOR "Advanced Computing Center for Research and Education, Vanderbilt University")
@@ -20,6 +16,11 @@ set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSIO
set(CPACK_SOURCE_IGNORE_FILES "^${CMAKE_SOURCE_DIR}/build"
"^${PROJECT_SOURCE_DIR}/scripts"
"^${PROJECT_SOURCE_DIR}/\\\\.git/"
"^${PROJECT_SOURCE_DIR}/venv/"
"^${PROJECT_SOURCE_DIR}/doc/latex/"
"^${PROJECT_SOURCE_DIR}/doc/html/"
"^${PROJECT_SOURCE_DIR}/doc/xml/"
"^${PROJECT_SOURCE_DIR}/doc/_build/"
"apr-util.spec"
"apr.spec"
${CPACK_SOURCE_IGNORE_FILES})
@@ -51,6 +52,7 @@ if(UNIX)
ADD_CUSTOM_TARGET(rpm rpmbuild --verbose
-D "_rpmdir ${CMAKE_BINARY_DIR}/rpm_output"
-D "_srcrpmdir ${CMAKE_BINARY_DIR}/srpm_output"
-D "my_version ${CPACK_PACKAGE_VERSION}"
-ta ${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar.gz)
ADD_DEPENDENCIES(rpm dist)
ADD_CUSTOM_TARGET(deb dpkg-buildpackage -uc -us)
@@ -0,0 +1,67 @@
# Try and best extract the LStore version using git or falling back to a static
# file

# Not sure what the meaning of the revision is
set(CPACK_PACKAGE_RELEASE 1)

find_program(GIT_EXECUTABLE git)
if(NOT GIT_EXECUTABLE)
message(STATUS "Git not found, version can't be extracted")
endif()

# Extract from git
if(NOT LSTORE_VERSION AND GIT_EXECUTABLE)
message(STATUS "Detecting version from git: ${CMAKE_SOURCE_DIR}")
execute_process(COMMAND "${GIT_EXECUTABLE}" describe --abbrev=32 "--dirty=-dev" --candidates=100 --match "v[0-9].[0-9].[0-9]*"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE LSTORE_GITVERSION_RAW
RESULT_VARIABLE GIT_RESULT
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(GIT_RESULT EQUAL 0)
string(REGEX REPLACE "v(.*)" "\\1" LSTORE_VERSION "${LSTORE_GITVERSION_RAW}")
set(LSTORE_GITVERSION 1)
message(STATUS "Detecting version from git - Success")
else()
message(STATUS "Detecting version from git - FAILED")
set(LSTORE_GITVERSION 0)
endif()
else()
set(LSTORE_GITVERSION 0)
endif()

# Otherwise extract from the source tree
set(LSTORE_VERSION_TMPL "${CMAKE_SOURCE_DIR}/src/lio/lio/version.h.in")
set(LSTORE_VERSION_FILE "${CMAKE_SOURCE_DIR}/src/lio/lio/version.h")
set(LSTORE_DISTRIBUTION_VERSION_FILE "${CMAKE_SOURCE_DIR}/VERSION")
file(STRINGS "${LSTORE_DISTRIBUTION_VERSION_FILE}" LSTORE_DISTRIBUTION_VERSION
REGEX "^[^#].*"
LIMIT_COUNT 1
)
if(NOT LSTORE_VERSION AND NOT LSTORE_GITVERSION)
set(LSTORE_VERSION "${LSTORE_DISTRIBUTION_VERSION}")
set(LSTORE_DISTVERSION 1)
else()
set(LSTORE_DISTVERSION 0)
endif()

if(NOT LSTORE_VERSION)
message(FATAL_ERROR "Could not detect the LStore version")
endif()
string(REGEX REPLACE "-" "_" LSTORE_VERSION "${LSTORE_VERSION}")
string(REGEX REPLACE "([0-9]+).([0-9]+).(.*)" "\\1" LSTORE_VERSION_MAJOR "${LSTORE_VERSION}")
string(REGEX REPLACE "([0-9]+).([0-9]+).(.*)" "\\2" LSTORE_VERSION_MINOR "${LSTORE_VERSION}")
string(REGEX REPLACE "([0-9]+).([0-9]+).(.*)" "\\3" LSTORE_VERSION_PATCH "${LSTORE_VERSION}")

# create a dependency on version file
# we never use output of the following command but cmake will rerun automatically if the version file changes

set(CPACK_PACKAGE_VERSION_MAJOR "${LSTORE_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${LSTORE_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${LSTORE_VERSION_PATCH}")
set(CPACK_PACKAGE_VERSION "${LSTORE_VERSION}")

message(STATUS "LStore version: ${LSTORE_VERSION}")

configure_file("${LSTORE_VERSION_TMPL}" "${LSTORE_VERSION_FILE}")
@@ -1,7 +1,10 @@
# -*- rpm-spec -*-
%define _basename lstore
%define _version 0.5.1
%define _release 1
# Allow the version to be overridden from the command line
%define _dist_version 0.5.1
%define _dist_release 1
%define _version %{?my_version}%{?!my_version:%{_dist_version}}
%define _release %{?my_release}%{?!my_release:%{_dist_release}}
%define _prefix /usr

URL: http://www.lstore.org
@@ -21,7 +24,8 @@ LStore - Logistical Storage.

%build
CFLAGS="-I%{_prefix}/include $RPM_OPT_FLAGS"
CMAKE_FLAGS="-DCMAKE_INSTALL_PREFIX=%{_prefix}"
CMAKE_FLAGS="-DLSTORE_VERSION=%{_version}"
CMAKE_FLAGS="$CMAKE_FLAGS -DCMAKE_INSTALL_PREFIX=%{_prefix}"
CMAKE_FLAGS="$CMAKE_FLAGS -DINSTALL_YUM_RELEASE:BOOL=ON"
CMAKE_FLAGS="$CMAKE_FLAGS -DINSTALL_META:BOOL=ON"
CMAKE_FLAGS="$CMAKE_FLAGS -DCMAKE_BUILD_TYPE:BOOL=RelWithDebInfo"
@@ -8,7 +8,7 @@
# Preliminary bootstrapping
#

set -eu
set -eux
ABSOLUTE_PATH=$(cd `dirname "${BASH_SOURCE[0]}"` && pwd)
source $ABSOLUTE_PATH/functions.sh
umask 0000
@@ -85,8 +85,9 @@ PACKAGE_REPO=$REPO_BASE/$TAG_NAME

set -x
mkdir -p $PACKAGE_BASE/build
cp -r ${LSTORE_RELEASE_BASE}/{scripts,src,vendor,doc,debian,test,cmake,CMakeLists.txt,lstore.spec} \
cp -r ${LSTORE_RELEASE_BASE}/{scripts,src,vendor,doc,debian,test,cmake,CMakeLists.txt,lstore.spec,VERSION} \
$PACKAGE_BASE
ln -s ${LSTORE_RELEASE_BASE}/.git $PACKAGE_BASE/.git

if [[ "${TARBALL:-}" -eq 1 ]]; then
cd $PACKAGE_BASE/build
@@ -130,6 +130,7 @@ set(LSTORE_PROJECT_INCLUDES
lio/segment.h
lio/service_manager.h
lio/trace.h
lio/version.h
lio/visibility.h
)

@@ -0,0 +1,23 @@
/*
* DO NOT MODIFY version.h! It is autogenerated by CMake from version.h.in
*/
#ifndef ACCRE_LSTORE_LIO_VERSION_H
#define ACCRE_LSTORE_LIO_VERSION_H

/*
* Version string from the "distributed" version. E.G. from a tarball. This
* version is what is used if CMake can't extract a version from git. It is
* set from VERSION in the source base.
*/
#define LSTORE_DISTRIBUTION_VERSION "@LSTORE_DISTRIBUTION_VERSION@"

/*
* The CMake-computed version string and its subparts
*/
#define LSTORE_VERSION "@LSTORE_VERSION@"
#define LSTORE_VERSION_MAJOR "@LSTORE_VERSION_MAJOR@"
#define LSTORE_VERSION_MINOR "@LSTORE_VERSION_MINOR@"
#define LSTORE_VERSION_PATCH "@LSTORE_VERSION_PATCH@"
#cmakedefine01 LSTORE_GITVERSION

#define ACCRE_LSTORE_LIO_VERSION_H

0 comments on commit abb5dc0

Please sign in to comment.
You can’t perform that action at this time.