From 82a212844fc66a3cfd934b970ccf770931cc2723 Mon Sep 17 00:00:00 2001 From: Sebastian Eichelbaum Date: Fri, 17 Jun 2011 15:37:36 +0200 Subject: [PATCH] [ADD] - added more nice version file and automatic library versioning with linking in binary dir. This is needed for install target and the packages. It makes release-builds even easier. No manual modifications anymore (besides VERSION file) --- VERSION | 10 +++++++++- src/CMakeLists.txt | 7 +++++++ src/core/CMakeLists.txt | 3 +++ src/ext/biosig/CMakeLists.txt | 3 +++ src/ext/biosigWin/CMakeLists.txt | 3 +++ src/ext/libeep/CMakeLists.txt | 3 +++ src/ext/nifti/CMakeLists.txt | 5 +++++ tools/cmake/BuildModuleUtils.cmake | 4 +++- tools/cmake/BuildUtils.cmake | 18 +++++++++++++----- tools/cmake/BuildVersionHeader.cmake | 2 +- 10 files changed, 50 insertions(+), 8 deletions(-) diff --git a/VERSION b/VERSION index 67d04d0ac..2e59834b3 100644 --- a/VERSION +++ b/VERSION @@ -1 +1,9 @@ -CHECKOUT +# OW Version File. This file specifies the version. The line VERSION=X.Y.Z is +# used and parsed. If you do not want a version, comment it out. +# +# IMPORTANT: If you modify the file, cmake re-creates the version header. But +# it is not able to set all library version. Please re-run cmake if +# you change something here. +# +# NOTE: do not add a space after #. The current CMake script will fail. +#VERSION=1.3.0 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 197fdd01d..8cdf461e6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -168,6 +168,13 @@ ENDIF() SET( OW_VERSION_HEADER ${PROJECT_SOURCE_DIR}/WVersion.h ) SETUP_VERSION_HEADER( ${OW_VERSION_HEADER} ) +# Set the OW version string. This can be used by others for setting target versions during compilation. +GET_VERSION_STRING( dummy OW_VERSION "0.0.0 " ) +IF( NOT DEFINED OW_VERSION ) + # CMake does not like unset variables for target properties. + SET( OW_VERSION "0.0.0" ) +ENDIF() + # --------------------------------------------------------------------------------------------------------------------------------------------------- # # REQUIRED third party libs diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index ad4574c85..75d33077d 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -56,6 +56,9 @@ TARGET_LINK_LIBRARIES( ${LibName} ${OWExtBioSigName} ${OWExtEEPName} ${OWExtNift # NOTE: this needs to be placed AFTER ADD_EXECUTABLE or ADD_LIBRARY SETUP_USE_VERSION_HEADER( ${LibName} ) +# Set the version of the library. +SET_TARGET_PROPERTIES( ${LibName} PROPERTIES VERSION ${OW_VERSION} ) + # Do not forget the install targets INSTALL( TARGETS ${LibName} ARCHIVE # NOTE: this is needed on windows diff --git a/src/ext/biosig/CMakeLists.txt b/src/ext/biosig/CMakeLists.txt index 9b2d6b57d..1550b611f 100644 --- a/src/ext/biosig/CMakeLists.txt +++ b/src/ext/biosig/CMakeLists.txt @@ -18,6 +18,9 @@ IF( CMAKE_HOST_SYSTEM MATCHES Windows ) TARGET_LINK_LIBRARIES( OWext_biosig ws2_32 ) ENDIF() +# Set the version of the library. +SET_TARGET_PROPERTIES( OWext_biosig PROPERTIES VERSION ${OW_VERSION} ) + # install target INSTALL( TARGETS OWext_biosig ARCHIVE # NOTE: this is needed on windows diff --git a/src/ext/biosigWin/CMakeLists.txt b/src/ext/biosigWin/CMakeLists.txt index 22d531f04..149d73a85 100644 --- a/src/ext/biosigWin/CMakeLists.txt +++ b/src/ext/biosigWin/CMakeLists.txt @@ -18,6 +18,9 @@ IF( CMAKE_HOST_SYSTEM MATCHES Windows ) TARGET_LINK_LIBRARIES( OWext_biosig ws2_32 ) ENDIF() +# Set the version of the library. +SET_TARGET_PROPERTIES( OWext_biosig PROPERTIES VERSION ${OW_VERSION} ) + # install target INSTALL( TARGETS OWext_biosig ARCHIVE # NOTE: this is needed on windows diff --git a/src/ext/libeep/CMakeLists.txt b/src/ext/libeep/CMakeLists.txt index f2d862c6c..df94a1984 100644 --- a/src/ext/libeep/CMakeLists.txt +++ b/src/ext/libeep/CMakeLists.txt @@ -21,6 +21,9 @@ IF(MSVC_IDE) SET_TARGET_PROPERTIES( OWext_eep PROPERTIES PREFIX "../") ENDIF(MSVC_IDE) +# Set the version of the library. +SET_TARGET_PROPERTIES( OWext_eep PROPERTIES VERSION ${OW_VERSION} ) + # install target INSTALL( TARGETS OWext_eep ARCHIVE # NOTE: this is needed on windows diff --git a/src/ext/nifti/CMakeLists.txt b/src/ext/nifti/CMakeLists.txt index 2e9134a56..55c4cf2b8 100644 --- a/src/ext/nifti/CMakeLists.txt +++ b/src/ext/nifti/CMakeLists.txt @@ -50,6 +50,11 @@ IF(UNIX) TARGET_LINK_LIBRARIES(${NIFTI_NIFTILIB_NAME} -lm) ENDIF(UNIX) +# Set the version of the library. +SET_TARGET_PROPERTIES( ${NIFTI_ZNZLIB_NAME} PROPERTIES VERSION ${OW_VERSION} ) +# Set the version of the library. +SET_TARGET_PROPERTIES( ${NIFTI_NIFTILIB_NAME} PROPERTIES VERSION ${OW_VERSION} ) + # install target INSTALL( TARGETS ${NIFTI_NIFTILIB_NAME} ${NIFTI_ZNZLIB_NAME} ARCHIVE # NOTE: this is needed on windows diff --git a/tools/cmake/BuildModuleUtils.cmake b/tools/cmake/BuildModuleUtils.cmake index a7f68bf7b..ae79f543a 100644 --- a/tools/cmake/BuildModuleUtils.cmake +++ b/tools/cmake/BuildModuleUtils.cmake @@ -29,7 +29,6 @@ # Optional second Parameter: list of additional dependencies # Optional third Parameter: list of style-excludes as regexp. FUNCTION( ADD_MODULE _MODULE_NAME ) - SET( MODULE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/${_MODULE_NAME} ) # is there a CMakeLists.txt? If yes, use it. @@ -84,6 +83,9 @@ FUNCTION( SETUP_MODULE _MODULE_NAME _MODULE_SOURCE_DIR _MODULE_DEPENDENCIES _MOD ADD_LIBRARY( ${MODULE_NAME} SHARED ${TARGET_CPP_FILES} ${TARGET_H_FILES} ) TARGET_LINK_LIBRARIES( ${MODULE_NAME} ${OWCoreName} ${Boost_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENSCENEGRAPH_LIBRARIES} ${_MODULE_DEPENDENCIES} ) + # Set the version of the library. + SET_TARGET_PROPERTIES( ${MODULE_NAME} PROPERTIES VERSION ${OW_VERSION} ) + # Do not forget the install targets # NOTE: do we really need to set all permissions explicitely? INSTALL( TARGETS ${MODULE_NAME} diff --git a/tools/cmake/BuildUtils.cmake b/tools/cmake/BuildUtils.cmake index c884e4ddc..d7133454c 100644 --- a/tools/cmake/BuildUtils.cmake +++ b/tools/cmake/BuildUtils.cmake @@ -253,8 +253,9 @@ ENDFUNCTION( SETUP_RESOURCES ) # 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 +# _file_version returns only the version loaded from the version file. This is useful to set CMake version info for release compilation # _default a default string you specify if all version check methods fail -FUNCTION( GET_VERSION_STRING _version _default ) +FUNCTION( GET_VERSION_STRING _version _file_version _default ) # Undef the OW_VERSION variable UNSET( OW_VERSION_HG ) UNSET( OW_VERSION_FILE ) @@ -263,15 +264,22 @@ FUNCTION( GET_VERSION_STRING _version _default ) 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}" ) - + FILE( READ ${OW_VERSION_FILENAME} OW_VERSION_FILE_CONTENT ) + # The first regex will mathc + STRING(REGEX REPLACE ".*[^#]VERSION=([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1" OW_VERSION_FILE ${OW_VERSION_FILE_CONTENT} ) + STRING( COMPARE EQUAL ${OW_VERSION_FILE} ${OW_VERSION_FILE_CONTENT} OW_VERSION_FILE_INVALID ) + IF( OW_VERSION_FILE_INVALID ) + UNSET( OW_VERSION_FILE ) + ENDIF() + # 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() + + # set the return parameter too + SET( ${_file_version} ${OW_VERSION_FILE} PARENT_SCOPE ) ENDIF() # Use hg to query version information. diff --git a/tools/cmake/BuildVersionHeader.cmake b/tools/cmake/BuildVersionHeader.cmake index d259a9e75..542d92eff 100644 --- a/tools/cmake/BuildVersionHeader.cmake +++ b/tools/cmake/BuildVersionHeader.cmake @@ -28,5 +28,5 @@ # know.) INCLUDE( BuildUtils.cmake ) -GET_VERSION_STRING( OW_VERSION "Unknown Tarball Version" ) +GET_VERSION_STRING( OW_VERSION OW_FILE_VERSION "0.0.0" ) FILE( WRITE ${HEADER_FILENAME} "// generated by CMake. Do not modify.\n#define W_VERSION \"${OW_VERSION}\"\n" ) -- GitLab