Skip to content
This repository has been archived by the owner on May 7, 2018. It is now read-only.

Commit

Permalink
add version
Browse files Browse the repository at this point in the history
  • Loading branch information
carstene1ns committed May 1, 2014
1 parent 88411cc commit c02b002
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
20 changes: 20 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,30 @@ cmake_minimum_required(VERSION 2.8)
# add modules
set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules")

# set version
set(VERSION_MAJOR "0")
set(VERSION_MINOR "3")
set(VERSION_PATCH "2")
set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")

# append git revision if available
include(get-git-revision)
get_git_revision(VERSION_GIT)
if(NOT "${VERSION_GIT}" STREQUAL "")
set(VERSION "${VERSION}-${VERSION_GIT}")
endif()

message(STATUS "Configuring steins-gate version " ${VERSION})

# project name and language
project (steins-gate CXX)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2")

# include version number in header
configure_file(${PROJECT_SOURCE_DIR}/src/version.hpp.in
${PROJECT_SOURCE_DIR}/src/version.hpp)

find_package(Boost REQUIRED COMPONENTS system)
find_package(SFML 2 REQUIRED COMPONENTS system window graphics)
find_package(GStreamer REQUIRED)
Expand Down
37 changes: 37 additions & 0 deletions cmake/Modules/get-git-revision.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

# this function returns the git hash of the current checkout, if the 'git'
# command is available, it is a git checkout and it is not a tagged release.
function(get_git_revision _hashvar)
# got git?
if(NOT GIT_FOUND)
find_package(Git QUIET)
endif()
if(GIT_FOUND)
# TODO: look for source directory (for out-of-source builds)?

# check, if we have a tagged release
execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --exact-match
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
RESULT_VARIABLE EXIT_CODE
OUTPUT_QUIET
ERROR_QUIET
)
# it failed => not a tagged revision
if(NOT ${EXIT_CODE} EQUAL 0)
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short=10 HEAD
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
RESULT_VARIABLE EXIT_CODE
OUTPUT_VARIABLE GIT_REV
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(${EXIT_CODE} EQUAL 0)
# all good, set hash
set(${_hashvar} "${GIT_REV}" PARENT_SCOPE)
return()
endif()
endif()
endif()
# no git available or any other error above, set to empty string
set(${_hashvar} "" PARENT_SCOPE)
endfunction()
10 changes: 10 additions & 0 deletions src/version.hpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef VERSION_HPP
#define VERSION_HPP

#define VERSION "@VERSION@"
#define VERSION_MAJOR "@VERSION_MAJOR@"
#define VERSION_MINOR "@VERSION_MINOR@"
#define VERSION_PATCH "@VERSION_PATCH@"
#define VERSION_GIT "@VERSION_GIT@"

#endif

0 comments on commit c02b002

Please sign in to comment.