Generate resources/version.hpp with the project version

main archive_04bf40a5
Duncan Ogilvie 3 years ago
parent 4d14395994
commit 04bf40a5a6

1
CMakeLists.txt generated

@ -93,6 +93,7 @@ list(APPEND cmkr_SOURCES
"include/literals.hpp" "include/literals.hpp"
"include/project_parser.hpp" "include/project_parser.hpp"
"cmake/cmkr.cmake" "cmake/cmkr.cmake"
"cmake/version.hpp.in"
) )
list(APPEND cmkr_SOURCES list(APPEND cmkr_SOURCES

@ -25,6 +25,7 @@ sources = [
"src/*.cpp", "src/*.cpp",
"include/*.hpp", "include/*.hpp",
"cmake/cmkr.cmake", "cmake/cmkr.cmake",
"cmake/version.hpp.in",
] ]
include-directories = [ include-directories = [
"include", "include",

@ -5,15 +5,19 @@ function(generate_resources target)
PROPERTY SOURCES PROPERTY SOURCES
) )
foreach(SOURCE ${TARGET_SOURCES}) foreach(SOURCE ${TARGET_SOURCES})
if(SOURCE MATCHES ".cmake$")
get_filename_component(RESOURCE_NAME "${SOURCE}" NAME_WE) get_filename_component(RESOURCE_NAME "${SOURCE}" NAME_WE)
set(RESOURCE_HEADER "include/resources/${RESOURCE_NAME}.hpp") set(RESOURCE_HEADER "include/resources/${RESOURCE_NAME}.hpp")
if(SOURCE MATCHES ".cmake$")
# Add configure-time dependency on the source file # Add configure-time dependency on the source file
configure_file("${SOURCE}" "${RESOURCE_HEADER}" COPYONLY) configure_file("${SOURCE}" "${RESOURCE_HEADER}" COPYONLY)
# Generate the actual resource into the header # Generate the actual resource into the header
file(READ "${SOURCE}" RESOURCE_CONTENTS) file(READ "${SOURCE}" RESOURCE_CONTENTS)
configure_file("${PROJECT_SOURCE_DIR}/cmake/resource.hpp.in" "${RESOURCE_HEADER}" @ONLY) configure_file("${PROJECT_SOURCE_DIR}/cmake/resource.hpp.in" "${RESOURCE_HEADER}" @ONLY)
message(STATUS "[cmkr] Generated ${RESOURCE_HEADER}") message(STATUS "[cmkr] Generated ${RESOURCE_HEADER}")
elseif(SOURCE MATCHES ".in$")
configure_file("${SOURCE}" "${RESOURCE_HEADER}" @ONLY)
message(STATUS "[cmkr] Generated ${RESOURCE_HEADER}")
endif() endif()
endforeach() endforeach()
target_include_directories(${target} PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/include") target_include_directories(${target} PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/include")

@ -0,0 +1,3 @@
#pragma once
#define CMKR_VERSION "@PROJECT_VERSION@"

@ -1,9 +1,10 @@
#include "help.hpp" #include "help.hpp"
#include <resources/version.hpp>
namespace cmkr { namespace cmkr {
namespace help { 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 { const char *message() noexcept {
return R"lit( return R"lit(

Loading…
Cancel
Save