From 819f02429b22dd7d472e93f57f00918c7fd9d2b1 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Fri, 27 Jan 2023 18:53:21 +0800 Subject: [PATCH] feat: api for version info --- .gitignore | 1 + src/klotski/CMakeLists.txt | 16 ++++++++++++---- src/klotski/ffi/klotski.h | 17 +++++++++++++++++ src/klotski/ffi/version.cc | 14 ++++++++++++++ src/klotski/utils/version.h.in | 5 +++++ src/main.c | 2 ++ 6 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 src/klotski/ffi/version.cc create mode 100644 src/klotski/utils/version.h.in diff --git a/.gitignore b/.gitignore index 2b9d3d2..197f167 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /.idea/ /cmake-build-debug/ /cmake-build-release/ +/src/klotski/utils/version.h diff --git a/src/klotski/CMakeLists.txt b/src/klotski/CMakeLists.txt index dfb2779..9b3ba76 100644 --- a/src/klotski/CMakeLists.txt +++ b/src/klotski/CMakeLists.txt @@ -1,6 +1,8 @@ cmake_minimum_required(VERSION 3.0) -project(klotski-core LANGUAGES CXX) +project(klotski-core VERSION 0.0.1 LANGUAGES CXX) + +configure_file(utils/version.h.in ${PROJECT_SOURCE_DIR}/utils/version.h) set(CMAKE_CXX_STANDARD 14) @@ -36,10 +38,16 @@ add_subdirectory(benchmark) ################################################################ -add_library(klotski-ffi OBJECT ffi/codec.cc ffi/tmain.cc) +set(FFI_SRC codec.cc tmain.cc version.cc) +list(TRANSFORM FFI_SRC PREPEND "ffi/") +add_library(klotski-ffi OBJECT ${FFI_SRC}) -add_library(klotski SHARED $) -#add_library(klotski STATIC $) +option(SHARED_LIB "build static library" ON) +if (SHARED_LIB) + add_library(klotski SHARED $) +else() + add_library(klotski STATIC $) +endif() ################################################################ diff --git a/src/klotski/ffi/klotski.h b/src/klotski/ffi/klotski.h index ec2d715..1f2ee51 100644 --- a/src/klotski/ffi/klotski.h +++ b/src/klotski/ffi/klotski.h @@ -17,6 +17,23 @@ extern "C" { } #endif +/// --------------------------------- klotski version info ---------------------------------- + +#ifdef __cplusplus +extern "C" { +#endif +// extern char* get_author(); +// extern char* get_project_url(); +// extern char* get_compile_time(); + + /// version -> major.minor.patch + extern int get_version_major(); + extern int get_version_minor(); + extern int get_version_patch(); +#ifdef __cplusplus +} +#endif + /// -------------------------------- klotski codec interface -------------------------------- #ifdef __cplusplus diff --git a/src/klotski/ffi/version.cc b/src/klotski/ffi/version.cc new file mode 100644 index 0000000..7966d53 --- /dev/null +++ b/src/klotski/ffi/version.cc @@ -0,0 +1,14 @@ +#include "klotski.h" +#include "version.h" + +int get_version_major() { + return VERSION_MAJOR; +} + +int get_version_minor() { + return VERSION_MINOR; +} + +int get_version_patch() { + return VERSION_PATCH; +} diff --git a/src/klotski/utils/version.h.in b/src/klotski/utils/version.h.in new file mode 100644 index 0000000..af544f7 --- /dev/null +++ b/src/klotski/utils/version.h.in @@ -0,0 +1,5 @@ +#pragma once + +#define VERSION_MAJOR @klotski-core_VERSION_MAJOR@ +#define VERSION_MINOR @klotski-core_VERSION_MINOR@ +#define VERSION_PATCH @klotski-core_VERSION_PATCH@ diff --git a/src/main.c b/src/main.c index 43e4d6c..5cb3987 100644 --- a/src/main.c +++ b/src/main.c @@ -57,6 +57,8 @@ int main() { printf("short code -> %d\n", short_code); } + printf("version -> %d.%d.%d\n", get_version_major(), get_version_minor(), get_version_patch()); + // printf("cli exit\n"); return 0; }