blob: 4b1bc41f4e8b17dfcd84c47a64a90bdd965dd298 (
plain) (
tree)
|
|
## CMakeLists.txt - Build recipe -----------------------------------*- CMake -*-
##
## This file is part of ck, the config keeper
##
## -----------------------------------------------------------------------------
##
## Copyright (C) 2018 Anastasis Grammenos
## GPLv3 (see LICENCE for the full notice)
##
## -------------------------------------------------------------------------- */
cmake_minimum_required (VERSION 3.5.6)
project(ck C)
# version
set(ck_MAJOR_VERSION 0)
set(ck_MINOR_VERSION 7)
# options
option(CK_ASAN "Build with asan")
option(CK_DEBUG "Build with debug symbols")
option(CK_TESTS "Make the tests")
option(CK_SHARED "Build with shared lib")
if(CK_ASAN)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
endif()
if (CK_DEBUG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g3")
else(CK_DEBUG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
endif()
# Set project directories
set(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(RES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/res)
set(TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test)
set(UNIT_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/unit)
# configure the info header
configure_file(
"${SRC_DIR}/ckinfo.h.in"
"${SRC_DIR}/ckinfo.h"
)
# Set source code locations
set(ckBin_src ${SRC_DIR}/ck.c)
set(ckUnitTest_src ${UNIT_TEST_DIR}/ck-test.c)
set(ckLib_src
${SRC_DIR}/actionparser.c
${SRC_DIR}/actions.c
${SRC_DIR}/actionhelper.c
${SRC_DIR}/confparser.c
${SRC_DIR}/dblayer.c
${SRC_DIR}/dbhelper.c
${SRC_DIR}/ckutil.c
${SRC_DIR}/cklist.c
${SRC_DIR}/ckerrlog.c
)
set(ckLib_hdr
${SRC_DIR}/actionparser.h
${SRC_DIR}/actions.h
${SRC_DIR}/actionhelper.h
${SRC_DIR}/confparser.h
${SRC_DIR}/dblayer.h
${SRC_DIR}/dbhelper.h
${SRC_DIR}/ckutil.h
${SRC_DIR}/cklist.h
${SRC_DIR}/ckinfo.h
${SRC_DIR}/ckerrlog.h
)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${RES_DIR}/cmake)
find_package(SQLite3)
# Include directories
include_directories(${SRC_DIR})
include_directories(${PROJECT_BINARY_DIR})
include_directories(${CMAKE_BINARY_DIR})
include_directories(${SQLITE3_INCLUDE_DIRS})
# Create the library (static by default)
if (CK_SHARED)
add_library (ckLib SHARED
${ckLib_src}
${ckLib_hdr}
)
else(CK_SHARED)
add_library (ckLib STATIC
${ckLib_src}
${ckLib_hdr}
)
endif()
# Link
add_executable(ck ${ckBin_src})
target_link_libraries(ck ckLib)
target_link_libraries(ck ${SQLITE3_LIBRARIES})
install(TARGETS ck DESTINATION bin)
if (CK_TESTS)
## unit test
add_executable(ck-test ${ckUnitTest_src})
target_link_libraries(ck-test ckLib)
target_link_libraries(ck-test ${SQLITE3_LIBRARIES})
# copy test files
set(BIN_TEST_DIR ${CMAKE_BINARY_DIR}/res/test)
set(PROJECT_TESTING_GROUNDS ${CMAKE_BINARY_DIR}/test_files)
configure_file(${TEST_DIR}/00_init ${BIN_TEST_DIR}/00_init @ONLY)
configure_file(${TEST_DIR}/01_add ${BIN_TEST_DIR}/01_add @ONLY)
configure_file(${TEST_DIR}/02_list ${BIN_TEST_DIR}/02_list @ONLY)
configure_file(${TEST_DIR}/03_delete ${BIN_TEST_DIR}/03_delete @ONLY)
configure_file(${TEST_DIR}/03_delete ${BIN_TEST_DIR}/03_delete @ONLY)
configure_file(${TEST_DIR}/04_search ${BIN_TEST_DIR}/04_search @ONLY)
# check_ck
configure_file(${RES_DIR}/test-ck test-ck @ONLY)
endif()
|