From 2f66696350e13f7a5a2b29e314e25e3706c73512 Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Fri, 30 Dec 2016 16:09:39 +1000 Subject: [PATCH] * add second sampler: dummy --- CMakeLists.txt | 8 ++++++++ src/CMakeLists.txt | 24 +++++++++++++++--------- src/samplers/dummy.c | 13 +++++++++++++ src/simdb-write.c | 2 +- 4 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 src/samplers/dummy.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 409361a..01c8b1c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ include(GNUInstallDirs) option(WITH_HARDENING "Enable hardening options" ON) option(WITH_TOOLS "Build library management tools" ON) +set(SAMPLER "magick" CACHE STRING "Library for sampling") set(CMAKE_INSTALL_PREFIX "/usr/local") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic -std=c99") @@ -20,6 +21,12 @@ if (WITH_HARDENING) add_definitions("-D_FORTIFY_SOURCE=2") endif () +if (${SAMPLER} STREQUAL "dummy") + set(SAMPLER "dummy") +else () + set(SAMPLER "magick") +endif () + message(STATUS "Project : ${CNAME} v${VERSION}") message(STATUS "Compiler : ${CMAKE_C_COMPILER} (${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION})") message(STATUS "- CFLAGS : ${CMAKE_C_FLAGS}") @@ -31,6 +38,7 @@ message(STATUS "Build type : ${CMAKE_BUILD_TYPE}") message(STATUS "Options:") message(STATUS "- WITH_HARDENING : ${WITH_HARDENING}") message(STATUS "- WITH_TOOLS : ${WITH_TOOLS}") +message(STATUS "- SAMPLER : ${SAMPLER}") add_subdirectory("src") add_subdirectory("tests") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e5a2f66..08a8e8e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,8 +1,14 @@ -set(LIB_SOURCES "database.c" "bitmap.c") -set(SAMPLER "magick") # TODO: GD2 +set(LIB_SOURCES "database.c" "bitmap.c" "samplers/${SAMPLER}.c") add_library("simdb" SHARED ${LIB_SOURCES}) set_property(TARGET "simdb" PROPERTY SONAME ${VERSION}) + +if (${SAMPLER} STREQUAL "magick") + find_package(ImageMagick COMPONENTS MagickCore MagickWand) + target_link_libraries("simdb" ${ImageMagick_MagickCore_LIBRARY}) + target_link_libraries("simdb" ${ImageMagick_MagickWand_LIBRARY}) +endif () + install(TARGETS "simdb" LIBRARY DESTINATION "lib") if (WITH_TOOLS) @@ -13,11 +19,11 @@ if (WITH_TOOLS) target_link_libraries("simdb-query" "simdb") install(TARGETS "simdb-query" RUNTIME DESTINATION "bin") - find_package(ImageMagick COMPONENTS MagickCore MagickWand) - - add_executable("simdb-write" "simdb-write.c" "samplers/${SAMPLER}.c") - target_link_libraries("simdb-write" "simdb") - target_link_libraries("simdb-write" ${ImageMagick_MagickCore_LIBRARY}) - target_link_libraries("simdb-write" ${ImageMagick_MagickWand_LIBRARY}) - install(TARGETS "simdb-write" RUNTIME DESTINATION "bin") + if (${SAMPLER} STREQUAL "dummy") + message(STATUS "Sampler set to 'dummy', not building 'simdb-write' tool") + else () + add_executable("simdb-write" "simdb-write.c") + target_link_libraries("simdb-write" "simdb") + install(TARGETS "simdb-write" RUNTIME DESTINATION "bin") + endif () endif () diff --git a/src/samplers/dummy.c b/src/samplers/dummy.c new file mode 100644 index 0000000..d60af77 --- /dev/null +++ b/src/samplers/dummy.c @@ -0,0 +1,13 @@ +#include "../common.h" +#include "../simdb.h" + +bool +simdb_record_create(simdb_rec_t * const rec, const char * const source) { + assert(rec != NULL); + assert(source != NULL); + + (void)(rec); + (void)(source); + + return false; +} diff --git a/src/simdb-write.c b/src/simdb-write.c index 7c14de9..fd34835 100644 --- a/src/simdb-write.c +++ b/src/simdb-write.c @@ -81,7 +81,7 @@ int main(int argc, char **argv) case add : if (rec.num == 0 || sample == NULL) usage(EXIT_FAILURE); - if (simdb_record_create(&rec, sample) != 0) { + if (!simdb_record_create(&rec, sample)) { fprintf(stderr, "sampler failure\n"); exit(EXIT_FAILURE); }