Merge pull request #290 from rolk/290_version
Embed version string into the library
This commit is contained in:
commit
3e803a4780
@ -124,6 +124,7 @@ list (APPEND MAIN_SOURCE_FILES
|
|||||||
opm/core/utility/parameters/tinyxml/tinyxmlerror.cpp
|
opm/core/utility/parameters/tinyxml/tinyxmlerror.cpp
|
||||||
opm/core/utility/parameters/tinyxml/tinyxmlparser.cpp
|
opm/core/utility/parameters/tinyxml/tinyxmlparser.cpp
|
||||||
opm/core/utility/parameters/tinyxml/xmltest.cpp
|
opm/core/utility/parameters/tinyxml/xmltest.cpp
|
||||||
|
opm/core/version.c
|
||||||
opm/core/wells/InjectionSpecification.cpp
|
opm/core/wells/InjectionSpecification.cpp
|
||||||
opm/core/wells/ProductionSpecification.cpp
|
opm/core/wells/ProductionSpecification.cpp
|
||||||
opm/core/wells/WellCollection.cpp
|
opm/core/wells/WellCollection.cpp
|
||||||
@ -214,6 +215,7 @@ list (APPEND PUBLIC_HEADER_FILES
|
|||||||
opm/core/linalg/blas_lapack.h
|
opm/core/linalg/blas_lapack.h
|
||||||
opm/core/linalg/call_umfpack.h
|
opm/core/linalg/call_umfpack.h
|
||||||
opm/core/linalg/sparse_sys.h
|
opm/core/linalg/sparse_sys.h
|
||||||
|
opm/core/version.h
|
||||||
opm/core/wells.h
|
opm/core/wells.h
|
||||||
opm/core/pressure/CompressibleTpfa.hpp
|
opm/core/pressure/CompressibleTpfa.hpp
|
||||||
opm/core/pressure/FlowBCManager.hpp
|
opm/core/pressure/FlowBCManager.hpp
|
||||||
|
@ -89,11 +89,11 @@ function (configure_vars obj syntax filename verb)
|
|||||||
# integer variables (specifically 0 and 1) are written as they are,
|
# integer variables (specifically 0 and 1) are written as they are,
|
||||||
# whereas everything else (including version numbers, which could
|
# whereas everything else (including version numbers, which could
|
||||||
# be interpreted as floats) are quoted as strings
|
# be interpreted as floats) are quoted as strings
|
||||||
if (${_var} MATCHES "[0-9]+")
|
if (${_var} MATCHES "^[0-9]+$")
|
||||||
set (_quoted "${${_var}}")
|
set (_quoted "${${_var}}")
|
||||||
else (${_var} MATCHES "[0-9]+")
|
else (${_var} MATCHES "^[0-9]+$")
|
||||||
set (_quoted "\"${${_var}}\"")
|
set (_quoted "\"${${_var}}\"")
|
||||||
endif (${_var} MATCHES "[0-9]+")
|
endif (${_var} MATCHES "^[0-9]+$")
|
||||||
|
|
||||||
# write to file using the correct syntax
|
# write to file using the correct syntax
|
||||||
if ("${syntax}" STREQUAL "CMAKE")
|
if ("${syntax}" STREQUAL "CMAKE")
|
||||||
|
@ -30,6 +30,7 @@ function (OpmInitProjVars)
|
|||||||
OpmGetDuneModuleDirective ("Module" project "${DUNE_MODULE}")
|
OpmGetDuneModuleDirective ("Module" project "${DUNE_MODULE}")
|
||||||
OpmGetDuneModuleDirective ("Description" description "${DUNE_MODULE}")
|
OpmGetDuneModuleDirective ("Description" description "${DUNE_MODULE}")
|
||||||
OpmGetDuneModuleDirective ("Version" version "${DUNE_MODULE}")
|
OpmGetDuneModuleDirective ("Version" version "${DUNE_MODULE}")
|
||||||
|
OpmGetDuneModuleDirective ("Label" label "${DUNE_MODULE}")
|
||||||
|
|
||||||
# parse the version number
|
# parse the version number
|
||||||
set (verno_regex "^([0-9]*)\\.([0-9]*).*\$")
|
set (verno_regex "^([0-9]*)\\.([0-9]*).*\$")
|
||||||
@ -42,6 +43,7 @@ function (OpmInitProjVars)
|
|||||||
set (${project}_DESCRIPTION "${description}" PARENT_SCOPE)
|
set (${project}_DESCRIPTION "${description}" PARENT_SCOPE)
|
||||||
set (${project}_VERSION_MAJOR "${major}" PARENT_SCOPE)
|
set (${project}_VERSION_MAJOR "${major}" PARENT_SCOPE)
|
||||||
set (${project}_VERSION_MINOR "${minor}" PARENT_SCOPE)
|
set (${project}_VERSION_MINOR "${minor}" PARENT_SCOPE)
|
||||||
|
set (${project}_LABEL "${label}" PARENT_SCOPE)
|
||||||
endfunction ()
|
endfunction ()
|
||||||
|
|
||||||
macro (OpmInitDirVars)
|
macro (OpmInitDirVars)
|
||||||
|
@ -223,3 +223,13 @@ opm_dist_clean (${project})
|
|||||||
|
|
||||||
### emulate the with-xxx feature of autotools;
|
### emulate the with-xxx feature of autotools;
|
||||||
include (OpmKnown)
|
include (OpmKnown)
|
||||||
|
|
||||||
|
# make sure we rebuild if dune.module changes
|
||||||
|
configure_file (
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/dune.module"
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/dunemod.tmp"
|
||||||
|
COPYONLY
|
||||||
|
)
|
||||||
|
|
||||||
|
# make sure updated version information is available in the source code
|
||||||
|
include (UseVersion)
|
||||||
|
41
cmake/Modules/UseVersion.cmake
Normal file
41
cmake/Modules/UseVersion.cmake
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
# - Write version information into the source code
|
||||||
|
#
|
||||||
|
# Add an unconditional target to the Makefile which checks the current
|
||||||
|
# SHA of the source directory and write to a header file if and *only*
|
||||||
|
# if this has changed (thus we avoid unnecessary rebuilds). By having
|
||||||
|
# this in the Makefile, we get updated version information even though
|
||||||
|
# we haven't done any reconfiguring.
|
||||||
|
#
|
||||||
|
# The time it takes to probe the VCS for this information and write it
|
||||||
|
# to the miniature file in negligable.
|
||||||
|
#
|
||||||
|
# If the build type is Debug, then we only write a static version
|
||||||
|
# information as it gets tiresome to rebuild the project everytime one
|
||||||
|
# makes changes to any of the unit tests.
|
||||||
|
|
||||||
|
string (TOUPPER "${CMAKE_BUILD_TYPE}" cmake_build_type_upper_)
|
||||||
|
if (cmake_build_type_upper_ MATCHES DEBUG)
|
||||||
|
file (WRITE "${PROJECT_BINARY_DIR}/project-version.h"
|
||||||
|
"#define PROJECT_VERSION \"${${project}_LABEL} (debug)\"\n"
|
||||||
|
)
|
||||||
|
else ()
|
||||||
|
if (NOT GIT_FOUND)
|
||||||
|
find_package (Git)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
add_custom_target (update-version ALL
|
||||||
|
COMMAND ${CMAKE_COMMAND}
|
||||||
|
-DCMAKE_HOME_DIRECTORY=${CMAKE_HOME_DIRECTORY}
|
||||||
|
-DGIT_EXECUTABLE=${GIT_EXECUTABLE}
|
||||||
|
-DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}
|
||||||
|
-DPROJECT_BINARY_DIR=${PROJECT_BINARY_DIR}
|
||||||
|
-DPROJECT_LABEL=${${project}_LABEL}
|
||||||
|
-P ${PROJECT_SOURCE_DIR}/cmake/Scripts/WriteVerSHA.cmake
|
||||||
|
COMMENT "Updating version information"
|
||||||
|
)
|
||||||
|
|
||||||
|
# the target above gets built every time thanks to the "ALL" modifier,
|
||||||
|
# but it must also be done before the main library so it can pick up
|
||||||
|
# any changes it does.
|
||||||
|
add_dependencies (${${project}_TARGET} update-version)
|
||||||
|
endif ()
|
63
cmake/Scripts/WriteVerSHA.cmake
Normal file
63
cmake/Scripts/WriteVerSHA.cmake
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
# - This script must be passed the following information
|
||||||
|
#
|
||||||
|
# GIT_EXECUTABLE Path to the Git executable
|
||||||
|
# PROJECT_SOURCE_DIR Path to the source directory
|
||||||
|
# PROJECT_BINARY_DIR Path to the build directory
|
||||||
|
# PROJECT_LABEL String that identifies the minor
|
||||||
|
# version of the project, e.g. "2013.03"
|
||||||
|
#
|
||||||
|
|
||||||
|
# get hash code
|
||||||
|
exec_program (
|
||||||
|
${GIT_EXECUTABLE} ${PROJECT_SOURCE_DIR}
|
||||||
|
ARGS rev-parse --short --verify HEAD
|
||||||
|
OUTPUT_VARIABLE sha1
|
||||||
|
RETURN_VALUE has_sha
|
||||||
|
)
|
||||||
|
|
||||||
|
# exec_program unfortunately mashes together both output
|
||||||
|
# and error streams, so we must use the return code to make
|
||||||
|
# sure that we only get the output
|
||||||
|
if (NOT ${has_sha} EQUAL 0)
|
||||||
|
set (sha1 "")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
# check for local changes
|
||||||
|
if (sha1)
|
||||||
|
# unstaged
|
||||||
|
exec_program (
|
||||||
|
${GIT_EXECUTABLE} ${PROJECT_SOURCE_DIR}
|
||||||
|
ARGS diff --no-ext-diff --quiet --exit-code
|
||||||
|
RETURN_VALUE dirty
|
||||||
|
OUTPUT_VARIABLE _dummy
|
||||||
|
)
|
||||||
|
|
||||||
|
# staged
|
||||||
|
exec_program (
|
||||||
|
${GIT_EXECUTABLE} ${PROJECT_SOURCE_DIR}
|
||||||
|
ARGS diff-index --no-ext-diff --cached --quiet --exit-code HEAD --
|
||||||
|
RETURN_VALUE staged
|
||||||
|
OUTPUT_VARIABLE _dummy
|
||||||
|
)
|
||||||
|
|
||||||
|
# if we found any changes, then append an asterisk to
|
||||||
|
# the SHA1 so we know that it cannot be trusted
|
||||||
|
if (dirty OR staged)
|
||||||
|
set (sha1 "${sha1}*")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
# make a formatted version that can be appended to the label
|
||||||
|
set (sha1 " (${sha1})")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
# write the content to a temporary file in a C compatible format
|
||||||
|
file (WRITE "${PROJECT_BINARY_DIR}/project-version.tmp"
|
||||||
|
"#define PROJECT_VERSION \"${PROJECT_LABEL}${sha1}\"\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
# only commit this to source code if it actually changed. here
|
||||||
|
# we use execute_process instead of exec_program to avoid having
|
||||||
|
# it printed on the console every time
|
||||||
|
execute_process (COMMAND
|
||||||
|
${CMAKE_COMMAND} -E copy_if_different "${PROJECT_BINARY_DIR}/project-version.tmp" "${PROJECT_BINARY_DIR}/project-version.h"
|
||||||
|
)
|
@ -1,5 +1,6 @@
|
|||||||
Module: opm-core
|
Module: opm-core
|
||||||
Description: Open Porous Media Initiative Core Library
|
Description: Open Porous Media Initiative Core Library
|
||||||
Version: 1.0
|
Version: 1.0
|
||||||
|
Label: 2013.03
|
||||||
Maintainer: atgeirr@sintef.no
|
Maintainer: atgeirr@sintef.no
|
||||||
Depends: dune-common (>= 2.2) dune-istl (>= 2.2)
|
Depends: dune-common (>= 2.2) dune-istl (>= 2.2)
|
||||||
|
8
opm/core/version.c
Normal file
8
opm/core/version.c
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/* this file is written by the build system; don't include it anywhere else */
|
||||||
|
#include <project-version.h>
|
||||||
|
|
||||||
|
/* declaration of the externally visible symbol */
|
||||||
|
#include <opm/core/version.h>
|
||||||
|
|
||||||
|
/* initialization */
|
||||||
|
const char* const opm_core_version = PROJECT_VERSION;
|
4
opm/core/version.h
Normal file
4
opm/core/version.h
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
/**
|
||||||
|
* This symbol is initialized with the built version of the library.
|
||||||
|
*/
|
||||||
|
extern const char* const opm_core_version;
|
Loading…
Reference in New Issue
Block a user