Browse Source

Add version header to libraries

sendfile
Martchus 2 years ago
parent
commit
fc9e1ff703
  1. 9
      cmake/modules/LibraryTarget.cmake
  2. 57
      cmake/templates/version.h.in
  3. 16
      tests/misctests.cpp

9
cmake/modules/LibraryTarget.cmake

@ -62,6 +62,12 @@ configure_file("${GLOBAL_H_TEMPLATE_FILE}"
)
list(APPEND HEADER_FILES global.h)
# add header to check library version
set(VERSION_HEADER_FILE "${CMAKE_CURRENT_BINARY_DIR}/resources/version.h")
find_template_file("version.h" CPP_UTILITIES VERSION_H_TEMPLATE_FILE)
configure_file("${VERSION_H_TEMPLATE_FILE}" "${VERSION_HEADER_FILE}" NEWLINE_STYLE UNIX)
list(APPEND SOURCE_FILES "${VERSION_HEADER_FILE}")
# determine SOVERSION
if (NOT META_SOVERSION AND NOT META_IS_PLUGIN)
if (META_VERSION_EXACT_SONAME)
@ -419,6 +425,9 @@ if (NOT META_NO_INSTALL_TARGETS AND ENABLE_INSTALL_TARGETS)
DESTINATION "${INCLUDE_SUBDIR}/${META_PROJECT_NAME}/${HEADER_DIR}"
COMPONENT header)
endforeach ()
install(FILES "${VERSION_HEADER_FILE}"
DESTINATION "${INCLUDE_SUBDIR}/${META_PROJECT_NAME}"
COMPONENT header)
if (NOT TARGET install-header)
add_custom_target(install-header
COMMAND "${CMAKE_COMMAND}"

57
cmake/templates/version.h.in

@ -0,0 +1,57 @@
// Created via CMake from template version.h.in
// WARNING! Any changes to this file will be overwritten by the next CMake run!
#ifndef @META_PROJECT_VARNAME_UPPER@_VERSION
#define @META_PROJECT_VARNAME_UPPER@_VERSION_MAJOR @META_VERSION_MAJOR@
#define @META_PROJECT_VARNAME_UPPER@_VERSION_MINOR @META_VERSION_MINOR@
#define @META_PROJECT_VARNAME_UPPER@_VERSION_PATCH @META_VERSION_PATCH@
#define @META_PROJECT_VARNAME_UPPER@_VERSION_VCSRE @META_GIT_REV_COUNT@
#define @META_PROJECT_VARNAME_UPPER@_VERSION_VCSID "@META_GIT_LAST_COMMIT_ID@"
#define @META_PROJECT_VARNAME_UPPER@_VERSION_STR "@META_APP_VERSION@"
#define @META_PROJECT_VARNAME_UPPER@_VERSION_CHECK(major, minor, patch) ((major<<16)|(minor<<8)|(patch))
#define @META_PROJECT_VARNAME_UPPER@_VERSION \
@META_PROJECT_VARNAME_UPPER@_VERSION_CHECK(@META_PROJECT_VARNAME_UPPER@_VERSION_MAJOR, @META_PROJECT_VARNAME_UPPER@_VERSION_MINOR, @META_PROJECT_VARNAME_UPPER@_VERSION_PATCH)
/*!
* \def @META_PROJECT_VARNAME_UPPER@_VERSION_MAJOR
* \brief Mayor version of the @META_PROJECT_NAME@ library.
*/
/*!
* \def @META_PROJECT_VARNAME_UPPER@_VERSION_MINOR
* \brief Minor version of the @META_PROJECT_NAME@ library.
*/
/*!
* \def @META_PROJECT_VARNAME_UPPER@_VERSION_PATCH
* \brief Patch version of the @META_PROJECT_NAME@ library.
*/
/*!
* \def @META_PROJECT_VARNAME_UPPER@_VERSION_VCSRE
* \brief Revision number in the version control system of the @META_PROJECT_NAME@ library.
*/
/*!
* \def @META_PROJECT_VARNAME_UPPER@_VERSION_VCSID
* \brief Revision ID in the version control system of the @META_PROJECT_NAME@ library.
*/
/*!
* \def @META_PROJECT_VARNAME_UPPER@_VERSION_STR
* \brief Version of the @META_PROJECT_NAME@ library as string (for display purposes).
*/
/*!
* \def @META_PROJECT_VARNAME_UPPER@_VERSION_CHECK
* \brief Can be used like "#if (@META_PROJECT_VARNAME_UPPER@_VERSION >= @META_PROJECT_VARNAME_UPPER@_VERSION_CHECK(5, 1, 0))".
*/
/*!
* \def @META_PROJECT_VARNAME_UPPER@_VERSION
* \brief Defined as (major << 16) + (minor << 8) + patch.
*/
#endif // @META_PROJECT_VARNAME_UPPER@_VERSION

16
tests/misctests.cpp

@ -8,6 +8,8 @@
#include "../tests/testutils.h"
#include "resources/version.h"
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
@ -18,6 +20,20 @@ using namespace CppUtilities;
using namespace CppUtilities::Literals;
using namespace CPPUNIT_NS;
// test version check macro
#if CPP_UTILITIES_VERSION_CHECK(5, 2, 1) > CPP_UTILITIES_VERSION_CHECK(6, 0, 0)
#error "Check for major version doesn't work"
#endif
#if CPP_UTILITIES_VERSION_CHECK(5, 2, 2) > CPP_UTILITIES_VERSION_CHECK(5, 3, 0)
#error "Check for minor version doesn't work"
#endif
#if CPP_UTILITIES_VERSION_CHECK(5, 2, 1) > CPP_UTILITIES_VERSION_CHECK(5, 2, 2)
#error "Check for path version doesn't work"
#endif
#if CPP_UTILITIES_VERSION < CPP_UTILITIES_VERSION_CHECK(5, 0, 0)
#error "Library version seems wrongly defined, should be already >= 5.0.0"
#endif
/*!
* \brief The MiscTests class tests misc functions and classes (mainly of files contained by the misc directory).
*/

Loading…
Cancel
Save