Commit 7c001d47 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[FIX #494] - cleaned up and unified automatic version definition.

parent 359200e0
......@@ -23,6 +23,7 @@ syntax: regexp
# files generated by "make tags"
^src/tags
^src/cscope.out
^src/ncscope.out
# files geneterated by build system
^src/qt4gui/version.h
......
CHECKOUT
......@@ -159,6 +159,13 @@ IF( NOT CMAKE_HOST_SYSTEM MATCHES "Windows" )
OPTION( OW_LINK_SHADERS "If turned on, shaders do not get copied. They get linked. This is a nice option for developers." OFF )
ENDIF()
# ---------------------------------------------------------------------------------------------------------------------------------------------------
# The walnut executable should print the revision/tag
# ---------------------------------------------------------------------------------------------------------------------------------------------------
GET_VERSION_STRING( OW_VERSION "Unknown Tarball Version" )
ADD_DEFINITIONS( -DW_VERSION="${OW_VERSION}" )
# ---------------------------------------------------------------------------------------------------------------------------------------------------
#
# REQUIRED third party libs
......
......@@ -45,27 +45,6 @@ SET( QT_LIBS ${QT_QTCORE_LIBRARY}
${QT_QTOPENGL_LIBRARY}
${QT_QTWEBKIT_LIBRARY} )
# ---------------------------------------------------------------------------------------------------------------------------------------------------
# The walnut executable should print the revision/tag
# ---------------------------------------------------------------------------------------------------------------------------------------------------
# We use mercurial to get current version information. This is stored in version.h, included by OpenWalnut.cpp
IF( NOT CMAKE_GENERATOR MATCHES "Visual Studio" )
add_custom_command( OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/version.h
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/../../.hg/dirstate
COMMAND hg parents --template '\#define W_VERSION \"{node|short} {rev} {branches} {tags}\" //' > ${CMAKE_CURRENT_SOURCE_DIR}/version.h
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Creating version.h"
)
ELSE()
add_custom_command( OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/version.h
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/../../.hg/dirstate
COMMAND hg parents --template "\"#define W_VERSION \"\"{node|short} {rev} {branches} {tags}\"\"\"" > ${CMAKE_CURRENT_SOURCE_DIR}/version.h
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMENT "Creating version.h"
)
ENDIF()
# ---------------------------------------------------------------------------------------------------------------------------------------------------
# Add sources as target
# ---------------------------------------------------------------------------------------------------------------------------------------------------
......@@ -80,7 +59,7 @@ QT4_AUTOMOC( ${TARGET_CPP_FILES} )
INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} )
# Setup the target
ADD_EXECUTABLE( ${BinName} ${TARGET_CPP_FILES} ${TARGET_H_FILES} "version.h" )
ADD_EXECUTABLE( ${BinName} ${TARGET_CPP_FILES} ${TARGET_H_FILES} )
TARGET_LINK_LIBRARIES( ${BinName} ${OWCoreName} ${QT_LIBS} ${Boost_LIBRARIES} )
# Do not forget the install targets
......
......@@ -29,8 +29,6 @@
#include "qt4/WQt4Gui.h"
#include "version.h" // this header gets created by our build system.
/**
* \mainpage OpenWalnut Inline Documentation
* \par
......
......@@ -249,3 +249,47 @@ FUNCTION( SETUP_RESOURCES )
)
ENDFUNCTION( SETUP_RESOURCES )
# This function tries to find a proper version string. It therefore uses the file src/../VERSION and mercurial. If the file exists and is not
# empty, the contents of it get combined with the mercurial results if mercurial is installed. If not, only the file content will be used. If
# both methods fail, a default string is used.
# _version the returned version string
# _default a default string you specify if all version check methods fail
FUNCTION( GET_VERSION_STRING _version _default )
# Undef the OW_VERSION variable
UNSET( OW_VERSION_HG )
UNSET( OW_VERSION_FILE )
# Grab version file.
SET( OW_VERSION_FILENAME ${PROJECT_SOURCE_DIR}/../VERSION )
IF( EXISTS ${OW_VERSION_FILENAME} )
# Read the version file
FILE( READ ${OW_VERSION_FILENAME} OW_VERSION_FILE )
# this wil contain an line-break. Remove it.
STRING( REGEX REPLACE "\n" "" OW_VERSION_FILE "${OW_VERSION_FILE}" )
# this is ugly because, if the version file is empty, the OW_VERSION_FILE content is "". Unfortunately, this is not UNDEFINED as it would be
# by SET( VAR "" ) ... so set it manually
IF( OW_VERSION_FILE STREQUAL "" )
UNSET( OW_VERSION_FILE )
ENDIF()
ENDIF()
# Use hg to query version information.
# -> the nice thing is: if hg is not available, no compilation errors anymore
execute_process( COMMAND hg parents --template "{rev}:{node|short} {branches} {tags}" OUTPUT_VARIABLE OW_VERSION_HG RESULT_VARIABLE hgParentsRetVar )
IF( NOT ${hgParentsRetVar} STREQUAL 0 )
UNSET( OW_VERSION_HG )
ENDIF()
# Use the version strings and set them as #define
IF( DEFINED OW_VERSION_HG AND DEFINED OW_VERSION_FILE )
SET( ${_version} "${OW_VERSION_FILE} - ${OW_VERSION_HG}" PARENT_SCOPE )
ELSEIF( DEFINED OW_VERSION_FILE )
SET( ${_version} "${OW_VERSION_FILE}" PARENT_SCOPE )
ELSEIF( DEFINED OW_VERSION_HG )
SET( ${_version} "${OW_VERSION_HG}" PARENT_SCOPE )
ELSE()
SET( ${_version} ${_default} PARENT_SCOPE )
ENDIF()
ENDFUNCTION( GET_VERSION_STRING )
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment