From 0d43936a6102ba8dc3c1fcb7e3b5bdc4416aa447 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Wed, 11 Oct 2023 20:49:32 +0200 Subject: [PATCH] feat: add version header --- CMakeLists.txt | 19 +++++++++---------- include/version.h.in | 8 ++++++++ src/main.cpp | 8 ++++++-- 3 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 include/version.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d24d76..d5d4657 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,21 +2,20 @@ cmake_minimum_required(VERSION 3.20) project( hello - VERSION 0.1 + VERSION 0.1.0 LANGUAGES CXX) -set(SOURCES src/main.cpp) - -set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - -set(CMAKE_EXPORT_COMPILE_COMMANDS - ON - CACHE INTERNAL "") +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) if(CMAKE_EXPORT_COMPILE_COMMANDS) set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}) endif() -add_executable(hello ${SOURCES}) +configure_file("${PROJECT_SOURCE_DIR}/include/version.h.in" + "${PROJECT_BINARY_DIR}/include/version.h") + +add_executable(hello src/main.cpp) +target_compile_features(hello PUBLIC cxx_std_20) + +target_include_directories(hello PRIVATE "${PROJECT_BINARY_DIR}/include") diff --git a/include/version.h.in b/include/version.h.in new file mode 100644 index 0000000..b7e9740 --- /dev/null +++ b/include/version.h.in @@ -0,0 +1,8 @@ +#pragma once + +#define VERSION_MAJOR @PROJECT_VERSION_MAJOR@ +#define VERSION_MINOR @PROJECT_VERSION_MINOR@ +#define VERSION_PATCH @PROJECT_VERSION_PATCH@ +#define VERSION_TWEAK @PROJECT_VERSION_TWEAK@ + +#define VERSION "@PROJECT_VERSION@" diff --git a/src/main.cpp b/src/main.cpp index ce56794..36a4aa5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,10 @@ +#include #include +#include "version.h" + int main(int argc, char **argv) { - std::cout << "Hello" << std::endl; - return 0; + std::cout << "Hello, world! Version " << VERSION << std::endl; + + return EXIT_SUCCESS; }