From 50566d3ac4cc8ac545da445ef3112643636a782f Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sat, 28 Jan 2023 12:51:16 +0800 Subject: [PATCH] build: more version info in cmake template --- src/klotski/CMakeLists.txt | 38 +++++++++++++++++++++++++++------- src/klotski/utils/version.h.in | 14 ++++++++++--- 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/src/klotski/CMakeLists.txt b/src/klotski/CMakeLists.txt index 41456c6..95bf892 100644 --- a/src/klotski/CMakeLists.txt +++ b/src/klotski/CMakeLists.txt @@ -1,15 +1,37 @@ cmake_minimum_required(VERSION 3.0) +set(CMAKE_CXX_STANDARD 14) + project(klotski-core VERSION 0.0.1 LANGUAGES CXX) +################################################################################ + +macro(git_commit_id _hash) + find_package(Git QUIET) + if (GIT_FOUND) + execute_process( + COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%H + OUTPUT_VARIABLE ${_hash} + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET + ) + endif() +endmacro() + +set(GIT_COMMIT_ID "") +git_commit_id(GIT_COMMIT_ID) + +string(TIMESTAMP BUILD_TIME "%Y-%m-%d %H:%M:%S") + +set(SYSTEM_INFO "${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_PROCESSOR}") + +set(COMPILER_INFO "${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}") + configure_file( utils/version.h.in ${PROJECT_SOURCE_DIR}/utils/version.h ) - -set(CMAKE_CXX_STANDARD 14) - -################################################################ +################################################################################ include_directories(utils) include_directories(all_cases) @@ -24,7 +46,7 @@ include_directories(fast_cal) include_directories(benchmark) -################################################################ +################################################################################ add_subdirectory(utils) add_subdirectory(all_cases) @@ -39,7 +61,7 @@ add_subdirectory(fast_cal) add_subdirectory(benchmark) -################################################################ +################################################################################ set(FFI_SRC codec.cc tmain.cc version.cc) list(TRANSFORM FFI_SRC PREPEND "ffi/") @@ -60,7 +82,7 @@ list(APPEND OBJS $) list(APPEND OBJS $) -################################################################ +################################################################################ option(STATIC_LIB "build static library" ON) if (STATIC_LIB) @@ -69,4 +91,4 @@ else() add_library(klotski SHARED ${OBJS}) endif() -################################################################ +################################################################################ diff --git a/src/klotski/utils/version.h.in b/src/klotski/utils/version.h.in index af544f7..9b45e13 100644 --- a/src/klotski/utils/version.h.in +++ b/src/klotski/utils/version.h.in @@ -1,5 +1,13 @@ #pragma once -#define VERSION_MAJOR @klotski-core_VERSION_MAJOR@ -#define VERSION_MINOR @klotski-core_VERSION_MINOR@ -#define VERSION_PATCH @klotski-core_VERSION_PATCH@ +#define VERSION_MAJOR (@klotski-core_VERSION_MAJOR@) +#define VERSION_MINOR (@klotski-core_VERSION_MINOR@) +#define VERSION_PATCH (@klotski-core_VERSION_PATCH@) +#define VERSION_STR "v@klotski-core_VERSION_MAJOR@.@klotski-core_VERSION_MINOR@.@klotski-core_VERSION_PATCH@" + +#define AUTHOR "dnomd343" +#define SYSTEM "@SYSTEM_INFO@" +#define COMPILER "@COMPILER_INFO@" +#define BUILD_TIME "@BUILD_TIME@" +#define PROJECT_URL "https://github.com/dnomd343/klotski.git" +#define GIT_COMMIT_ID "@GIT_COMMIT_ID@"