Browse Source

feat: api for version info

master
Dnomd343 2 years ago
parent
commit
819f02429b
  1. 1
      .gitignore
  2. 16
      src/klotski/CMakeLists.txt
  3. 17
      src/klotski/ffi/klotski.h
  4. 14
      src/klotski/ffi/version.cc
  5. 5
      src/klotski/utils/version.h.in
  6. 2
      src/main.c

1
.gitignore

@ -2,3 +2,4 @@
/.idea/
/cmake-build-debug/
/cmake-build-release/
/src/klotski/utils/version.h

16
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 $<TARGET_OBJECTS:klotski-ffi>)
#add_library(klotski STATIC $<TARGET_OBJECTS:klotski-core>)
option(SHARED_LIB "build static library" ON)
if (SHARED_LIB)
add_library(klotski SHARED $<TARGET_OBJECTS:klotski-ffi>)
else()
add_library(klotski STATIC $<TARGET_OBJECTS:klotski-ffi>)
endif()
################################################################

17
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

14
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;
}

5
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@

2
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;
}

Loading…
Cancel
Save