Move cdb query from examples to tools and always build
Change-Id: Ic55a00cd1d96dc76ec20c07b108cf0402b6108e3
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 54cb211..04dd3bb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -64,10 +64,21 @@
COMMAND install_name_tool -id "/usr/local/lib/libcollocatordb.1.dylib" $<TARGET_FILE:collocatordb>)
endif()
+file(GLOB TOOLS_SOURCES tools/*.c tools/*.cc)
+add_custom_target(tools)
+foreach(TOOL_SOURCE ${TOOLS_SOURCES})
+ get_filename_component(TOOL_NAME ${TOOL_SOURCE} NAME_WE)
+ add_executable(${TOOL_NAME} ${TOOL_SOURCE})
+ target_link_libraries(${TOOL_NAME} ${ROCKSDB} collocatordb)
+ set_target_properties(${TOOL_NAME} PROPERTIES
+ INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib64"
+ BUILD_WITH_INSTALL_RPATH TRUE)
+ add_dependencies(tools ${TOOL_NAME})
+ install(TARGETS ${TOOL_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
+endforeach()
+
file(GLOB EXAMPLES_SOURCES examples/*.c examples/*.cc)
-
add_custom_target(examples)
-
foreach(EXAMPLE_SOURCE ${EXAMPLES_SOURCES})
get_filename_component(EXAMPLE_NAME ${EXAMPLE_SOURCE} NAME_WE)
add_executable(${EXAMPLE_NAME} EXCLUDE_FROM_ALL ${EXAMPLE_SOURCE})
diff --git a/examples/collocatordb_query.c b/tools/collocatordb_query.c
similarity index 66%
rename from examples/collocatordb_query.c
rename to tools/collocatordb_query.c
index f75f0c7..c63ebd8 100644
--- a/examples/collocatordb_query.c
+++ b/tools/collocatordb_query.c
@@ -5,12 +5,12 @@
#include "../src/collocatordb.h"
int main(int argc, char *argv[]) {
- if (argc < 3) {
+ if (argc < 3 || (argv > 0 && strcmp(argv[1], "-h") == 0)) {
fprintf(stderr,
- "Usage: %s <dbpath> <word1> [word2] ... [wordN]\n"
- "Gets the collocators of the given words from a collocatordb and "
- "prints them as json.\n"
- "Example: %s ../tests/data/wpd19_10000 geht auch\n",
+ "Usage: %s <dbpath> <word1> [word2] ... [wordN]\n\n"
+ "Gets the collocates of the given words from a collocatordb and "
+ "prints them as json.\n\n"
+ "EXAMPLE\n../tests/data/wpd19_10000 geht auch\n",
argv[0], argv[0]);
return 1;
}
@@ -40,8 +40,8 @@
continue;
}
- fprintf(stderr, "printing collocators of \"%s\" as json:\n", argv[i]);
- printf("%s%s\n", get_collocators_as_json(cdb, word_id), i < argc - 1 ? "," : "");
+ fprintf(stderr, "printing collocates of \"%s\" as json:\n", argv[i]);
+ printf("%s%s", get_collocators_as_json(cdb, word_id), i < argc - 1 ? "," : "");
}
printf("]\n");
return 0;