diff --git a/.gitignore b/.gitignore index 1b452285..527cd1fb 100644 --- a/.gitignore +++ b/.gitignore @@ -81,3 +81,6 @@ cmake-build-*/ *.tcl *.user *.sln + +# Generated version.h +/include/spdlog/version.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 6861e36e..f42754d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,18 +8,16 @@ else() cmake_policy(VERSION 3.11) endif() -enable_language(C) - # --------------------------------------------------------------------------------------- # Start spdlog project # --------------------------------------------------------------------------------------- +project(spdlog VERSION "1.7.0" LANGUAGES CXX) +message(STATUS "Build spdlog: ${PROJECT_VERSION}") + include(cmake/utils.cmake) include(cmake/ide.cmake) -spdlog_extract_version() - -project(spdlog VERSION ${SPDLOG_VERSION} LANGUAGES CXX) -message(STATUS "Build spdlog: ${SPDLOG_VERSION}") +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.h.in ${SPDLOG_HEADERS_DIR}/spdlog/version.h @ONLY) include(GNUInstallDirs) diff --git a/cmake/utils.cmake b/cmake/utils.cmake index d56fc27a..86f68154 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -1,30 +1,3 @@ -# Get spdlog version from include/spdlog/version.h and put it in SPDLOG_VERSION -function(spdlog_extract_version) - file(READ "${CMAKE_CURRENT_LIST_DIR}/include/spdlog/version.h" file_contents) - string(REGEX MATCH "SPDLOG_VER_MAJOR ([0-9]+)" _ "${file_contents}") - if(NOT CMAKE_MATCH_COUNT EQUAL 1) - message(FATAL_ERROR "Could not extract major version number from spdlog/version.h") - endif() - set(ver_major ${CMAKE_MATCH_1}) - - string(REGEX MATCH "SPDLOG_VER_MINOR ([0-9]+)" _ "${file_contents}") - if(NOT CMAKE_MATCH_COUNT EQUAL 1) - message(FATAL_ERROR "Could not extract minor version number from spdlog/version.h") - endif() - - set(ver_minor ${CMAKE_MATCH_1}) - string(REGEX MATCH "SPDLOG_VER_PATCH ([0-9]+)" _ "${file_contents}") - if(NOT CMAKE_MATCH_COUNT EQUAL 1) - message(FATAL_ERROR "Could not extract patch version number from spdlog/version.h") - endif() - set(ver_patch ${CMAKE_MATCH_1}) - - set(SPDLOG_VERSION_MAJOR ${ver_major} PARENT_SCOPE) - set(SPDLOG_VERSION_MINOR ${ver_minor} PARENT_SCOPE) - set(SPDLOG_VERSION_PATCH ${ver_patch} PARENT_SCOPE) - set(SPDLOG_VERSION "${ver_major}.${ver_minor}.${ver_patch}" PARENT_SCOPE) -endfunction() - # Turn on warnings on the given target function(spdlog_enable_warnings target_name) if(SPDLOG_BUILD_WARNINGS) diff --git a/cmake/version.h.in b/cmake/version.h.in new file mode 100644 index 00000000..f08906d6 --- /dev/null +++ b/cmake/version.h.in @@ -0,0 +1,10 @@ +// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) + +#pragma once + +constexpr int SPDLOG_VER_MAJOR{@PROJECT_VERSION_MAJOR@}; +constexpr int SPDLOG_VER_MINOR{@PROJECT_VERSION_MINOR@}; +constexpr int SPDLOG_VER_PATCH{@PROJECT_VERSION_PATCH@}; + +constexpr int SPDLOG_VERSION{SPDLOG_VER_MAJOR * 10000 + SPDLOG_VER_MINOR * 100 + SPDLOG_VER_PATCH}; diff --git a/include/spdlog/version.h b/include/spdlog/version.h deleted file mode 100644 index c59e5f42..00000000 --- a/include/spdlog/version.h +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#define SPDLOG_VER_MAJOR 1 -#define SPDLOG_VER_MINOR 7 -#define SPDLOG_VER_PATCH 0 - -#define SPDLOG_VERSION (SPDLOG_VER_MAJOR * 10000 + SPDLOG_VER_MINOR * 100 + SPDLOG_VER_PATCH)