From c01950ec1c1c395b2795968a4ec97838f49af70e Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Mon, 30 Jan 2023 00:13:24 +0800 Subject: [PATCH] update: more metadata fields --- src/klotski_core/CMakeLists.txt | 33 +++++++++++++++- src/klotski_core/ffi/metadata.cc | 10 ++++- src/klotski_core/klotski.h | 2 + src/klotski_core/utils/metadata.h.in | 7 +++- src/klotski_core/xmake.lua | 56 ++++++++++++++++++++++++---- xmake.lua | 5 +++ 6 files changed, 101 insertions(+), 12 deletions(-) create mode 100644 xmake.lua diff --git a/src/klotski_core/CMakeLists.txt b/src/klotski_core/CMakeLists.txt index 5ead486..628f908 100644 --- a/src/klotski_core/CMakeLists.txt +++ b/src/klotski_core/CMakeLists.txt @@ -6,6 +6,30 @@ project(klotski-core VERSION 0.1.2 LANGUAGES CXX) ################################################################################ +macro(git_tag _tag) + find_package(Git QUIET) + if (GIT_FOUND) + execute_process( + COMMAND ${GIT_EXECUTABLE} describe --tags + OUTPUT_VARIABLE ${_tag} + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET + ) + endif() +endmacro() + +macro(git_branch _branch) + find_package(Git QUIET) + if (GIT_FOUND) + execute_process( + COMMAND ${GIT_EXECUTABLE} symbolic-ref --short -q HEAD + OUTPUT_VARIABLE ${_branch} + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET + ) + endif() +endmacro() + macro(git_commit_id _hash) find_package(Git QUIET) if (GIT_FOUND) @@ -18,7 +42,14 @@ macro(git_commit_id _hash) endif() endmacro() +################################################################################ + +set(GIT_BRANCH "") +set(GIT_TAG_LONG "") set(GIT_COMMIT_LONG "") + +git_tag(GIT_TAG_LONG) +git_branch(GIT_BRANCH) git_commit_id(GIT_COMMIT_LONG) set(PLAT "${CMAKE_SYSTEM_NAME}") @@ -28,7 +59,7 @@ set(VERSION_MAJOR ${klotski-core_VERSION_MAJOR}) set(VERSION_MINOR ${klotski-core_VERSION_MINOR}) set(VERSION_ALTER ${klotski-core_VERSION_PATCH}) -string(TIMESTAMP BUILD_TIME "%Y-%m-%d %H:%M:%S") +string(TIMESTAMP VERSION_BUILD "%Y-%m-%d %H:%M:%S") set(COMPILER "${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}") diff --git a/src/klotski_core/ffi/metadata.cc b/src/klotski_core/ffi/metadata.cc index 4268550..0bf2937 100644 --- a/src/klotski_core/ffi/metadata.cc +++ b/src/klotski_core/ffi/metadata.cc @@ -17,6 +17,10 @@ const char* get_author() { return AUTHOR; } +const char* get_git_tag() { + return GIT_TAG_ID; +} + const char* get_version() { return VERSION_STR; } @@ -29,8 +33,12 @@ const char* get_build_time() { return BUILD_TIME; } +const char* get_git_branch() { + return GIT_BRANCH; +} + const char* get_project_url() { - return PROJECT_URL; + return GIT_PROJECT; } const char* get_system_info() { diff --git a/src/klotski_core/klotski.h b/src/klotski_core/klotski.h index 9d72867..5ba9a8b 100644 --- a/src/klotski_core/klotski.h +++ b/src/klotski_core/klotski.h @@ -28,9 +28,11 @@ extern "C" { extern int get_version_patch(); extern const char* get_author(); + extern const char* get_git_tag(); extern const char* get_version(); extern const char* get_commit_id(); extern const char* get_build_time(); + extern const char* get_git_branch(); extern const char* get_project_url(); extern const char* get_system_info(); extern const char* get_compiler_info(); diff --git a/src/klotski_core/utils/metadata.h.in b/src/klotski_core/utils/metadata.h.in index 91fa9bd..130ee7f 100644 --- a/src/klotski_core/utils/metadata.h.in +++ b/src/klotski_core/utils/metadata.h.in @@ -8,6 +8,9 @@ #define AUTHOR "dnomd343" #define SYSTEM "@PLAT@ @ARCH@" #define COMPILER "@COMPILER@" -#define BUILD_TIME "@BUILD_TIME@" -#define PROJECT_URL "https://github.com/dnomd343/klotski.git" +#define BUILD_TIME "@VERSION_BUILD@" + +#define GIT_BRANCH "@GIT_BRANCH@" +#define GIT_TAG_ID "@GIT_TAG_LONG@" +#define GIT_PROJECT "https://github.com/dnomd343/klotski.git" #define GIT_COMMIT_ID "@GIT_COMMIT_LONG@" diff --git a/src/klotski_core/xmake.lua b/src/klotski_core/xmake.lua index c7246ba..819969f 100644 --- a/src/klotski_core/xmake.lua +++ b/src/klotski_core/xmake.lua @@ -3,10 +3,20 @@ set_xmakever("2.5.3") set_project("klotski-core") -set_version("0.1.2") +set_version("0.1.2", {build = "%Y-%m-%d %H:%M:%S"}) set_languages("cxx14") -set_optimize("fastest") +if is_mode("debug") then + set_symbols("debug") + set_optimize("none") +end + +if is_mode("release") then + set_strip("all") + set_symbols("hidden") + set_optimize("fastest") +end + set_warnings("everything") ---------------------------------------------------------------- @@ -29,39 +39,48 @@ add_includedirs("benchmark") target("utils") set_kind("object") add_files("utils/*.cc") +target_end() target("all_cases") set_kind("object") add_files("all_cases/*.cc") +target_end() target("raw_code") set_kind("object") add_files("raw_code/*.cc") +target_end() target("short_code") set_kind("object") add_includedirs("short_code/offset") add_files("short_code/*.cc") +target_end() target("common_code") set_kind("object") add_files("common_code/*.cc") +target_end() target("core") set_kind("object") add_files("core/*.cc") +target_end() target("fast_cal") set_kind("object") add_files("fast_cal/*.cc") +target_end() target("analyse") set_kind("object") add_files("analyse/*.cc") +target_end() target("benchmark") set_kind("object") add_files("benchmark/*.cc") +target_end() ---------------------------------------------------------------- @@ -70,30 +89,51 @@ target("klotski-ffi") add_includedirs(".") add_files("ffi/*.cc") - set_configvar("COMPILER", "GCC ...") - set_configvar("BUILD_TIME", "...time...") + -- TODO: get compiler name and version + set_configvar("COMPILER", "XMake") set_configdir("$(projectdir)/utils") add_configfiles("utils/metadata.h.in", { filename = "metadata.h", pattern = "@(.-)@" }) +target_end() ---------------------------------------------------------------- target("klotski") set_kind("static") - add_deps("klotski-ffi") add_deps("utils", "all_cases") add_deps("raw_code", "short_code", "common_code") add_deps("core", "fast_cal", "analyse") add_deps("benchmark") - set_policy("build.merge_archive", true) - set_targetdir("$(projectdir)/../../bin/") after_build(function (target) - os.cp("$(projectdir)/klotski.h", "$(projectdir)/../../bin/") + import("core.project.config") + +-- local target_file = target:targetfile() + + os.cp(target:targetfile(), "$(projectdir)/bin/") + os.cp("$(scriptdir)/klotski.h", "$(projectdir)/bin/") + end) +-- before_build(function(target) +-- print("23333 -> $(scriptdir)") +-- os.cp("$(scriptdir)/xxx.h", "$(buildir)/inc") + +-- set_targetdir("$(scriptdir)/../../bin/") + +-- end) + +-- print("23333 -> $(scriptdir)") + +-- set_targetdir("$(scriptdir)/../../bin/") + +-- after_build(function (target) +-- os.cp("$(projectdir)/klotski.h", "$(projectdir)/../../bin/") +-- end) +target_end() + ---------------------------------------------------------------- diff --git a/xmake.lua b/xmake.lua new file mode 100644 index 0000000..8594f20 --- /dev/null +++ b/xmake.lua @@ -0,0 +1,5 @@ +set_xmakever("2.5.3") + +BUILD_DN = "2333" + +add_subdirs("src/klotski_core")