From d583a09cb2ea2681a47888130bb46897d5dcc903 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sun, 29 Jan 2023 16:50:48 +0800 Subject: [PATCH] build: xmake metadata template --- src/klotski_core/CMakeLists.txt | 13 +++--- src/klotski_core/utils/metadata.h.in | 12 +++--- src/klotski_core/utils/metadata.h.inx | 15 ------- src/klotski_core/xmake.lua | 59 +++++++++++++++------------ 4 files changed, 45 insertions(+), 54 deletions(-) delete mode 100644 src/klotski_core/utils/metadata.h.inx diff --git a/src/klotski_core/CMakeLists.txt b/src/klotski_core/CMakeLists.txt index f2ee30c..5ead486 100644 --- a/src/klotski_core/CMakeLists.txt +++ b/src/klotski_core/CMakeLists.txt @@ -18,18 +18,19 @@ macro(git_commit_id _hash) endif() endmacro() -set(GIT_COMMIT_ID "") -git_commit_id(GIT_COMMIT_ID) +set(GIT_COMMIT_LONG "") +git_commit_id(GIT_COMMIT_LONG) -string(TIMESTAMP BUILD_TIME "%Y-%m-%d %H:%M:%S") +set(PLAT "${CMAKE_SYSTEM_NAME}") +set(ARCH "${CMAKE_SYSTEM_PROCESSOR}") set(VERSION_MAJOR ${klotski-core_VERSION_MAJOR}) set(VERSION_MINOR ${klotski-core_VERSION_MINOR}) -set(VERSION_PATCH ${klotski-core_VERSION_PATCH}) +set(VERSION_ALTER ${klotski-core_VERSION_PATCH}) -set(SYSTEM_INFO "${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_PROCESSOR}") +string(TIMESTAMP BUILD_TIME "%Y-%m-%d %H:%M:%S") -set(COMPILER_INFO "${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}") +set(COMPILER "${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}") configure_file( ${PROJECT_SOURCE_DIR}/utils/metadata.h.in diff --git a/src/klotski_core/utils/metadata.h.in b/src/klotski_core/utils/metadata.h.in index 936794b..91fa9bd 100644 --- a/src/klotski_core/utils/metadata.h.in +++ b/src/klotski_core/utils/metadata.h.in @@ -1,15 +1,13 @@ #pragma once -/// CMake metadata template - #define VERSION_MAJOR (@VERSION_MAJOR@) #define VERSION_MINOR (@VERSION_MINOR@) -#define VERSION_PATCH (@VERSION_PATCH@) -#define VERSION_STR "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@" +#define VERSION_PATCH (@VERSION_ALTER@) +#define VERSION_STR "v@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_ALTER@" #define AUTHOR "dnomd343" -#define SYSTEM "@SYSTEM_INFO@" -#define COMPILER "@COMPILER_INFO@" +#define SYSTEM "@PLAT@ @ARCH@" +#define COMPILER "@COMPILER@" #define BUILD_TIME "@BUILD_TIME@" #define PROJECT_URL "https://github.com/dnomd343/klotski.git" -#define GIT_COMMIT_ID "@GIT_COMMIT_ID@" +#define GIT_COMMIT_ID "@GIT_COMMIT_LONG@" diff --git a/src/klotski_core/utils/metadata.h.inx b/src/klotski_core/utils/metadata.h.inx deleted file mode 100644 index 4c70fc8..0000000 --- a/src/klotski_core/utils/metadata.h.inx +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -/// XMake metadata template - -#define VERSION_MAJOR (${VERSION_MAJOR}) -#define VERSION_MINOR (${VERSION_MINOR}) -#define VERSION_PATCH (${VERSION_ALTER}) -#define VERSION_STR "${VERSION}" - -#define AUTHOR "dnomd343" -#define SYSTEM "${PLAT} ${ARCH}" -#define COMPILER "${COMPILER_INFO}" -#define BUILD_TIME "${BUILD_TIME}" -#define PROJECT_URL "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 6191362..c7246ba 100644 --- a/src/klotski_core/xmake.lua +++ b/src/klotski_core/xmake.lua @@ -1,11 +1,12 @@ -set_xmakever("2.0.0") +---------------------------------------------------------------- -set_version("0.1.2") +set_xmakever("2.5.3") +set_project("klotski-core") +set_version("0.1.2") set_languages("cxx14") set_optimize("fastest") - set_warnings("everything") ---------------------------------------------------------------- @@ -26,67 +27,73 @@ add_includedirs("benchmark") ---------------------------------------------------------------- target("utils") - set_kind("static") + set_kind("object") add_files("utils/*.cc") target("all_cases") - set_kind("static") + set_kind("object") add_files("all_cases/*.cc") target("raw_code") - set_kind("static") + set_kind("object") add_files("raw_code/*.cc") target("short_code") - set_kind("static") + set_kind("object") add_includedirs("short_code/offset") add_files("short_code/*.cc") target("common_code") - set_kind("static") + set_kind("object") add_files("common_code/*.cc") target("core") - set_kind("static") + set_kind("object") add_files("core/*.cc") target("fast_cal") - set_kind("static") + set_kind("object") add_files("fast_cal/*.cc") target("analyse") - set_kind("static") + set_kind("object") add_files("analyse/*.cc") target("benchmark") - set_kind("static") + set_kind("object") add_files("benchmark/*.cc") ---------------------------------------------------------------- --- TODO: generate version.h +target("klotski-ffi") + set_kind("object") + add_includedirs(".") + add_files("ffi/*.cc") + + set_configvar("COMPILER", "GCC ...") + set_configvar("BUILD_TIME", "...time...") + + set_configdir("$(projectdir)/utils") + add_configfiles("utils/metadata.h.in", { + filename = "metadata.h", pattern = "@(.-)@" + }) + +---------------------------------------------------------------- target("klotski") set_kind("static") - add_includedirs(".") - add_files("ffi/*.cc") + + 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_configdir("$(scriptdir)/utils") - - set_configvar("COMPILER_INFO", "GNU ...") - set_configvar("BUILD_TIME", "...time...") - - add_configfiles("utils/metadata.h.inx", {filename = "config.h"}) - - -- add_configfiles("config.h.in", {pattern = "@(.-)@"}) - set_policy("build.merge_archive", true) --- set_targetdir("../../bin/") + set_targetdir("$(projectdir)/../../bin/") --- os.cp("$(scriptdir)/*.h", "$(scriptdir)/../../bin/") + after_build(function (target) + os.cp("$(projectdir)/klotski.h", "$(projectdir)/../../bin/") + end) ----------------------------------------------------------------