Commit 8d425b14 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE] - some improvements to the version stuff. This could have been very...

[CHANGE] - some improvements to the version stuff. This could have been very easy if SET_SOURCE_FILES_PROPERIES would work properly in cmake. But it doesn't. So we need (again) an external, generated version header. But this time: it will work if mercurial is not installed.
parent 6b2768df
......@@ -26,7 +26,7 @@ syntax: regexp
^src/ncscope.out
# files geneterated by build system
^src/qt4gui/version.h
^src/WVersion.h
# local vim rc
^lvimrc
......
......@@ -163,8 +163,10 @@ ENDIF()
# The walnut executable should print the revision/tag
# ---------------------------------------------------------------------------------------------------------------------------------------------------
GET_VERSION_STRING( OW_VERSION "Unknown Tarball Version" )
ADD_DEFINITIONS( -DW_VERSION="${OW_VERSION}" )
# Generate needed headers
# NOTE: add a line ADD_DEPENDENCIES( XYZ OW_generate_version_header ) to your target XYZ if you need the header!
SET( OW_VERSION_HEADER ${PROJECT_SOURCE_DIR}/WVersion.h )
SETUP_VERSION_HEADER( ${OW_VERSION_HEADER} )
# ---------------------------------------------------------------------------------------------------------------------------------------------------
#
......
......@@ -47,11 +47,15 @@ ENDIF()
COLLECT_COMPILE_FILES( "${CMAKE_CURRENT_SOURCE_DIR}" TARGET_CPP_FILES TARGET_H_FILES TARGET_TEST_FILES )
# Setup the target
ADD_LIBRARY( ${LibName} SHARED ${TARGET_CPP_FILES} ${TARGET_H_FILES} )
ADD_LIBRARY( ${LibName} SHARED ${TARGET_CPP_FILES} ${TARGET_H_FILES} ${OW_VERSION_HEADER} )
TARGET_LINK_LIBRARIES( ${LibName} ${OWExtBioSigName} ${OWExtEEPName} ${OWExtNiftiName}
${Boost_LIBRARIES} ${CMAKE_DL_LIBS} ${OPENGL_gl_LIBRARY} ${OPENSCENEGRAPH_LIBRARIES}
)
# Tell CMake that someone creates this file for us. See doc of SETUP_VERSION_HEADER in BuildUtils.cmake for details why this is needed.
# NOTE: this needs to be placed AFTER ADD_EXECUTABLE or ADD_LIBRARY
SETUP_USE_VERSION_HEADER( ${LibName} )
# Do not forget the install targets
INSTALL( TARGETS ${LibName}
ARCHIVE # NOTE: this is needed on windows
......
......@@ -54,6 +54,8 @@
#include "WROIManager.h"
#include "WSelectionManager.h"
#include "WVersion.h" // NOTE: this file is auto-generated by CMAKE
/**
* Used for program wide access to the kernel.
*/
......
......@@ -59,9 +59,13 @@ QT4_AUTOMOC( ${TARGET_CPP_FILES} )
INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} )
# Setup the target
ADD_EXECUTABLE( ${BinName} ${TARGET_CPP_FILES} ${TARGET_H_FILES} )
ADD_EXECUTABLE( ${BinName} ${TARGET_CPP_FILES} ${TARGET_H_FILES} ${OW_VERSION_HEADER} )
TARGET_LINK_LIBRARIES( ${BinName} ${OWCoreName} ${QT_LIBS} ${Boost_LIBRARIES} )
# Tell CMake that someone creates this file for us. See doc of SETUP_VERSION_HEADER in BuildUtils.cmake for details why this is needed.
# NOTE: this needs to be placed AFTER ADD_EXECUTABLE or ADD_LIBRARY
SETUP_USE_VERSION_HEADER( ${BinName} )
# Do not forget the install targets
INSTALL( TARGETS ${BinName}
RUNTIME
......
......@@ -27,6 +27,8 @@
#include "core/common/WSegmentationFault.h"
#include "core/common/WLogger.h"
#include "WVersion.h" // NOTE: this file is auto-generated by CMAKE
#include "qt4/WQt4Gui.h"
/**
......
......@@ -276,7 +276,10 @@ FUNCTION( GET_VERSION_STRING _version _default )
# 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 )
# NOTE: it is run insde the project source directory
EXECUTE_PROCESS( COMMAND hg parents --template "{rev}:{node|short} {branches} {tags}" OUTPUT_VARIABLE OW_VERSION_HG RESULT_VARIABLE hgParentsRetVar
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)
IF( NOT ${hgParentsRetVar} STREQUAL 0 )
UNSET( OW_VERSION_HG )
ENDIF()
......@@ -293,3 +296,36 @@ FUNCTION( GET_VERSION_STRING _version _default )
ENDIF()
ENDFUNCTION( GET_VERSION_STRING )
# This functions adds a custom target for generating the specified version header. This is very useful if you want to include build-time version
# information in your code. If your executable or lib is created in the same CMakeLists as this function is called, just add the
# _OW_VERSION_Header filename you specified here to your compile files. If you call this and add target XYZ in a subdirectory, you NEED to add
# the lines:
# ADD_DEPENDENCIES( XYZ OW_generate_version_header )
# SET_SOURCE_FILES_PROPERTIES( ${OW_VERSION_HEADER} PROPERTIES GENERATED ON )
# This is needed since CMake can only use the ADD_CUSTOM_COMMAND output as dependency if the custom command was called inside the SAME directory
# as the target is. If not, an additional target needs to be defined and CMake needs information about generated files.
#
# _OW_VERSION_HEADER the filename where to store the header. Should be absolute.
FUNCTION( SETUP_VERSION_HEADER _OW_VERSION_HEADER )
# The file WVersion.* needs the version definition.
ADD_CUSTOM_COMMAND( OUTPUT ${_OW_VERSION_HEADER}
DEPENDS ${PROJECT_SOURCE_DIR}/../VERSION ${PROJECT_SOURCE_DIR}/../.hg/dirstate
COMMAND ${CMAKE_COMMAND} -D PROJECT_SOURCE_DIR:STRING=${PROJECT_SOURCE_DIR} -D HEADER_FILENAME:STRING=${_OW_VERSION_HEADER} -P BuildVersionHeader.cmake
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../tools/cmake/
COMMENT "Creating Version Header ${_OW_VERSION_HEADER}."
)
# this is needed if the file is also a dependency of an target XYZ in a CMakeLists file in some subdirectory. Then, you should add
# ADD_DEPENDENCIES( XYZ OW_generate_version_header )
ADD_CUSTOM_TARGET( OW_generate_version_header DEPENDS ${_OW_VERSION_HEADER} )
ENDFUNCTION( SETUP_VERSION_HEADER )
# Comvenience function which does what SETUP_VERSION_HEADER requests from you if you need the version header in some CMakeLists different from
# the one which called SETUP_VERSION_HEADER. It uses ${OW_VERSION_HEADER} automatically. So it needs to be set.
#
# _target: the target name which needs the header
FUNCTION( SETUP_USE_VERSION_HEADER _target )
SET_SOURCE_FILES_PROPERTIES( ${OW_VERSION_HEADER} PROPERTIES GENERATED ON )
ADD_DEPENDENCIES( ${_target} OW_generate_version_header )
ENDFUNCTION( SETUP_USE_VERSION_HEADER )
#---------------------------------------------------------------------------
#
# Project: OpenWalnut ( http://www.openwalnut.org )
#
# Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
# For more information see http:#www.openwalnut.org/copying
#
# This file is part of OpenWalnut.
#
# OpenWalnut is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# OpenWalnut is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with OpenWalnut. If not, see <http:#www.gnu.org/licenses/>.
#
#---------------------------------------------------------------------------
# This is a script executed during build time to genertae the WVersion.h headers. This is needed since CMake does not allow us to define the
# commands directly inside an ADD_CUSTOM_COMMAND call. An alternative to this would be SET_SOURCE_FILE_PROPERTIES which should be able to set the
# version as define for some files. But this caused the whole source to rebuild although it was only set for one file (bug? feature? we do not
# know.)
INCLUDE( BuildUtils.cmake )
GET_VERSION_STRING( OW_VERSION "Unknown Tarball Version" )
FILE( WRITE ${HEADER_FILENAME} "// generated by CMake. Do not modify.\n#define W_VERSION \"${OW_VERSION}\"\n" )
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