From f5b1c16e2c1a8139885176cbd53a6d37bf9d006c Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Mon, 7 Nov 2016 18:52:08 -0800 Subject: [PATCH] Add version macro FMT_VERSION (#411) --- CMakeLists.txt | 30 ++++++++++++++++++++++-------- fmt/format.h | 3 +++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 353940f8..b08f9cbe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,12 +9,22 @@ if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) set(MASTER_PROJECT ON) endif () +# Joins arguments and places the results in ${result_var}. +function(join result_var) + set(result ) + foreach (arg ${ARGN}) + set(result "${result}${arg}") + endforeach () + set(${result_var} "${result}" PARENT_SCOPE) +endfunction() + # Set the default CMAKE_BUILD_TYPE to Release. # This should be done before the project command since the latter can set # CMAKE_BUILD_TYPE itself (it does so for nmake). if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Release CACHE STRING - "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.") + join(doc "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or " + "CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.") + set(CMAKE_BUILD_TYPE Release CACHE STRING ${doc}) endif () option(FMT_PEDANTIC "Enable extra warnings and expensive tests." OFF) @@ -28,13 +38,17 @@ option(FMT_USE_CPP11 "Enable the addition of C++11 compiler flags." ON) project(FMT) # Starting with cmake 3.0 VERSION is part of the project command. -set(FMT_VERSION 3.1.0) -if (NOT FMT_VERSION MATCHES "^([0-9]+).([0-9]+).([0-9]+)$") - message(FATAL_ERROR "Invalid version format ${FMT_VERSION}.") +file(READ fmt/format.h format_h) +if (NOT format_h MATCHES "FMT_VERSION ([0-9]+)([0-9][0-9])([0-9][0-9])") + message(FATAL_ERROR "Cannot get FMT_VERSION from format.h.") endif () -set(CPACK_PACKAGE_VERSION_MAJOR ${CMAKE_MATCH_1}) -set(CPACK_PACKAGE_VERSION_MINOR ${CMAKE_MATCH_2}) -set(CPACK_PACKAGE_VERSION_PATCH ${CMAKE_MATCH_3}) +# Use math to skip leading zeros if any. +math(EXPR CPACK_PACKAGE_VERSION_MAJOR ${CMAKE_MATCH_1}) +math(EXPR CPACK_PACKAGE_VERSION_MINOR ${CMAKE_MATCH_2}) +math(EXPR CPACK_PACKAGE_VERSION_PATCH ${CMAKE_MATCH_3}) +join(FMT_VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}. + ${CPACK_PACKAGE_VERSION_PATCH}) +message(STATUS "Version: ${FMT_VERSION}") message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") diff --git a/fmt/format.h b/fmt/format.h index 182d496a..9f0995ab 100644 --- a/fmt/format.h +++ b/fmt/format.h @@ -40,6 +40,9 @@ #include #include +// The fmt library version in the form major * 10000 + minor * 100 + patch. +#define FMT_VERSION 30002 + #ifdef _SECURE_SCL # define FMT_SECURE_SCL _SECURE_SCL #else