From 04bf40a5a6077a2a717d020a06c5259fbe81bb9e Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Thu, 23 Dec 2021 03:53:07 +0100 Subject: [PATCH] Generate resources/version.hpp with the project version --- CMakeLists.txt | 1 + cmake.toml | 1 + cmake/generate_resources.cmake | 8 ++++++-- cmake/version.hpp.in | 3 +++ src/help.cpp | 3 ++- 5 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 cmake/version.hpp.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 814201d..5040760 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,6 +93,7 @@ list(APPEND cmkr_SOURCES "include/literals.hpp" "include/project_parser.hpp" "cmake/cmkr.cmake" + "cmake/version.hpp.in" ) list(APPEND cmkr_SOURCES diff --git a/cmake.toml b/cmake.toml index f7520fa..88abb69 100644 --- a/cmake.toml +++ b/cmake.toml @@ -25,6 +25,7 @@ sources = [ "src/*.cpp", "include/*.hpp", "cmake/cmkr.cmake", + "cmake/version.hpp.in", ] include-directories = [ "include", diff --git a/cmake/generate_resources.cmake b/cmake/generate_resources.cmake index 57533c3..20c7d98 100644 --- a/cmake/generate_resources.cmake +++ b/cmake/generate_resources.cmake @@ -5,15 +5,19 @@ function(generate_resources target) PROPERTY SOURCES ) foreach(SOURCE ${TARGET_SOURCES}) + get_filename_component(RESOURCE_NAME "${SOURCE}" NAME_WE) + set(RESOURCE_HEADER "include/resources/${RESOURCE_NAME}.hpp") + if(SOURCE MATCHES ".cmake$") - get_filename_component(RESOURCE_NAME "${SOURCE}" NAME_WE) - set(RESOURCE_HEADER "include/resources/${RESOURCE_NAME}.hpp") # Add configure-time dependency on the source file configure_file("${SOURCE}" "${RESOURCE_HEADER}" COPYONLY) # Generate the actual resource into the header file(READ "${SOURCE}" RESOURCE_CONTENTS) configure_file("${PROJECT_SOURCE_DIR}/cmake/resource.hpp.in" "${RESOURCE_HEADER}" @ONLY) message(STATUS "[cmkr] Generated ${RESOURCE_HEADER}") + elseif(SOURCE MATCHES ".in$") + configure_file("${SOURCE}" "${RESOURCE_HEADER}" @ONLY) + message(STATUS "[cmkr] Generated ${RESOURCE_HEADER}") endif() endforeach() target_include_directories(${target} PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/include") diff --git a/cmake/version.hpp.in b/cmake/version.hpp.in new file mode 100644 index 0000000..87a5f7b --- /dev/null +++ b/cmake/version.hpp.in @@ -0,0 +1,3 @@ +#pragma once + +#define CMKR_VERSION "@PROJECT_VERSION@" \ No newline at end of file diff --git a/src/help.cpp b/src/help.cpp index 5d93f57..84b4af6 100644 --- a/src/help.cpp +++ b/src/help.cpp @@ -1,9 +1,10 @@ #include "help.hpp" +#include namespace cmkr { namespace help { -const char *version() noexcept { return "cmkr version 0.1.3"; } +const char *version() noexcept { return "cmkr version " CMKR_VERSION; } const char *message() noexcept { return R"lit(