add get_version function
Change-Id: I7f294d3a0ce1acb961c49a8a9bee0f3e8e2824eb
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6a9ec62..8680d8e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,7 +11,8 @@
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
endif("${isSystemDir}" STREQUAL "-1")
-include_directories(/usr/local/include /opt/homebrew/include)
+configure_file(src/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h @ONLY)
+include_directories(/usr/local/include /opt/homebrew/include build)
link_directories(/usr/local/lib64 /usr/local/lib /usr/lib64 /usr/lib /opt/homebrew/lib)
if (1 AND APPLE)
message("MacOS deteted")
@@ -25,6 +26,12 @@
endif()
find_library(ROCKSDB_STATIC librocksdb.a)
+get_cmake_property(_variableNames VARIABLES)
+list (SORT _variableNames)
+foreach (_variableName ${_variableNames})
+ message(STATUS "${_variableName}=${${_variableName}}")
+endforeach()
+
enable_testing()
add_library(collocatordb SHARED src/collocatordb.cc)
diff --git a/README.md b/README.md
index 360acec..f5f75f4 100644
--- a/README.md
+++ b/README.md
@@ -95,6 +95,7 @@
char *get_collocation_scores_as_json(COLLOCATORDB *db, uint32_t w1, uint32_t w2);
char *get_word(COLLOCATORDB *db, uint32_t w1);
void read_vocab(COLLOCATORDB *db, char *fname);
+char *get_version();
```
## Changes
diff --git a/src/collocatordb.cc b/src/collocatordb.cc
index 28035f6..691f820 100644
--- a/src/collocatordb.cc
+++ b/src/collocatordb.cc
@@ -18,6 +18,7 @@
#include <rocksdb/slice_transform.h>
#include "merge_operators.h"
#include "export.h"
+#include "config.h"
#define WINDOW_SIZE 5
#define FREQUENCY_THRESHOLD 5
@@ -895,6 +896,10 @@
return strdup(db->collocators2json(w1, db->get_collocation_scores(w1, w2)).c_str());
}
+ DLL_EXPORT const char *get_version() {
+ return PROJECT_VERSION;
+ }
+
#ifdef __clang__
#pragma clang diagnostic push
#endif
diff --git a/src/collocatordb.h b/src/collocatordb.h
index 7b9b3f5..af97419 100644
--- a/src/collocatordb.h
+++ b/src/collocatordb.h
@@ -118,4 +118,4 @@
extern char *get_collocation_scores_as_json(COLLOCATORDB *db, uint32_t w1, uint32_t w2);
extern char *get_word(COLLOCATORDB *db, uint32_t w1);
extern void read_vocab(COLLOCATORDB *db, char *fname);
-
+extern char *get_version();
diff --git a/tests/basic_test.c b/tests/basic_test.c
index eb0471d..1eb4559 100644
--- a/tests/basic_test.c
+++ b/tests/basic_test.c
@@ -103,6 +103,11 @@
rmrf(rocksdbfn);
}
+void test_version_function() {
+ char *version = get_version();
+ TEST_CHECK(strcmp(version, "1.3.2") == 0);
+ TEST_MSG("Unexpected version: %s", version);
+}
TEST_LIST = {
{ "open database for reading", test_open_db },
@@ -111,5 +116,6 @@
{ "collocation analysis", test_collocation_analysis },
{ "collocation analysis as json", test_collocation_analysis_as_json },
{ "writing", test_writing },
+ { "version function", test_version_function },
{ NULL, NULL }
};