From f2f199258ddd7bad42ee65889165d4eeffb7583e Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Thu, 1 Aug 2013 11:26:10 +0200 Subject: [PATCH 1/4] Define API version macros for other code to query Note the distinction between the version (1.0) and the release label (2013.03). The latter is not really usable to check for API compatibility. (See ). --- opm/core/version.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/opm/core/version.h b/opm/core/version.h index b82f13b9..8d9a5326 100644 --- a/opm/core/version.h +++ b/opm/core/version.h @@ -2,3 +2,10 @@ * This symbol is initialized with the built version of the library. */ extern const char* const opm_core_version; + +/** + * Current API level (for use with DUNE_VERSION_xxx): + */ +#define OPM_CORE_MAJOR 1 +#define OPM_CORE_MINOR 0 +#define OPM_CORE_REVISION 0 From 404413a226a788da0105c00a49c0902660836921 Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Thu, 1 Aug 2013 11:27:22 +0200 Subject: [PATCH 2/4] Insert remainder to keep version number is sync. --- dune.module | 1 + 1 file changed, 1 insertion(+) diff --git a/dune.module b/dune.module index 40785c91..3abc9177 100644 --- a/dune.module +++ b/dune.module @@ -1,5 +1,6 @@ Module: opm-core Description: Open Porous Media Initiative Core Library +# if you change this, make sure to also change opm/core/version.h Version: 1.0 Label: 2013.03 Maintainer: atgeirr@sintef.no From 99eca2a247a47ebdf07787527ce1440ff5cd40a2 Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Fri, 2 Aug 2013 09:03:49 +0200 Subject: [PATCH 3/4] Name #defines to be compatible with DUNE macros --- opm/core/version.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/opm/core/version.h b/opm/core/version.h index 8d9a5326..4aaccac9 100644 --- a/opm/core/version.h +++ b/opm/core/version.h @@ -6,6 +6,6 @@ extern const char* const opm_core_version; /** * Current API level (for use with DUNE_VERSION_xxx): */ -#define OPM_CORE_MAJOR 1 -#define OPM_CORE_MINOR 0 -#define OPM_CORE_REVISION 0 +#define OPM_CORE_VERSION_MAJOR 1 +#define OPM_CORE_VERSION_MINOR 0 +#define OPM_CORE_VERSION_REVISION 0 From e3638f770f7da1150d37849ba685123aaaa3f79d Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Fri, 2 Aug 2013 10:24:49 +0200 Subject: [PATCH 4/4] Safe-guard against version mismatch The version declared for the build system (in dune.module) is checked against what is in the source (e.g. opm/core/version.h) and if these don't match, then issue an author warning. This will help us keep the two version numbers in sync., since it becomes very obvious when we don't. The benefit for this is to not have the build system start mucking with the code just to dump some static information in there. --- cmake/Modules/UseVersion.cmake | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/cmake/Modules/UseVersion.cmake b/cmake/Modules/UseVersion.cmake index 541784cc..3f0d9808 100644 --- a/cmake/Modules/UseVersion.cmake +++ b/cmake/Modules/UseVersion.cmake @@ -49,3 +49,42 @@ else () add_dependencies (${${project}_TARGET} update-version) endif () endif () + +# safety precaution: check that we don't have version number mismatch. + +# first get the name of the module (e.g. "core") +set (_module_regexp "([^-]+)-(.*)") +string (REGEX REPLACE "${_module_regexp}" "\\1" _suite_name "${project}") +string (REGEX REPLACE "${_module_regexp}" "\\2" _module_name "${project}") + +# if we have a version number it must be in this file, e.g. opm/core/version.h +set (_rel_ver_h "${${project}_DIR}/${_module_name}/version.h") +set (_version_h "${PROJECT_SOURCE_DIR}/${_rel_ver_h}") + +# not all modules have version files, so only check if they do +if (EXISTS "${_version_h}") + # uppercase versions which is used in the file + string (TOUPPER "${_suite_name}" _suite_upper) + string (TOUPPER "${_module_name}" _module_upper) + + # scan the files for version define for major version + set (_major_regexp "#define[ ]+${_suite_upper}_${_module_upper}_VERSION_MAJOR[ ]+([0-9]*)") + file (STRINGS "${_version_h}" _version_h_major REGEX "${_major_regexp}") + string (REGEX REPLACE "${_major_regexp}" "\\1" _version_h_major "${_version_h_major}") + + # exactly the same, but minor version (making a macro is more lines...) + set (_minor_regexp "#define[ ]+${_suite_upper}_${_module_upper}_VERSION_MINOR[ ]+([0-9]*)") + file (STRINGS "${_version_h}" _version_h_minor REGEX "${_minor_regexp}") + string (REGEX REPLACE "${_minor_regexp}" "\\1" _version_h_minor "${_version_h_minor}") + + # compare what we got from the file with what we have defined here + if (NOT (("${_version_h_major}" EQUAL "${${project}_VERSION_MAJOR}") + AND ("${_version_h_minor}" EQUAL "${${project}_VERSION_MINOR}"))) + set (_proj_ver "${${project}_VERSION_MAJOR}.${${project}_VERSION_MINOR}") + set (_file_ver "${_version_h_major}.${_version_h_minor}") + message (AUTHOR_WARNING + "Version in build system (dune.module) is \"${_proj_ver}\", " + "but version in source (${_rel_ver_h}) is \"${_file_ver}\"" + ) + endif () +endif ()