aboutsummaryrefslogtreecommitdiffstats
path: root/CMakeLists.txt
blob: 8dcf30a9b4bff9f33386c7ae9e1abb6992bfd99d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
## 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 9)
set(ck_PATCH_VERSION 5)

# Feature test macros
set(FEATURE_TEST_MACROS "-D_DEFAULT_SOURCE")
# Default C flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FEATURE_TEST_MACROS} -std=c99 -pedantic")
# Warnings for debug builds
set(C_WARNINGS "-Wall -Wextra -Wwrite-strings -Wconversion -Wfloat-equal -Wpointer-arith")

# options
option(CK_DEBUG "Build with debug symbols, asan and warnings")
option(CK_TESTS "Make the tests")
option(CK_SHARED "Build with shared lib")

if (CK_DEBUG)
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_WARNINGS} -g3 -fsanitize=address")
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"
  )

# configure the manpage
configure_file(
  "ck.1"
  "${CMAKE_BINARY_DIR}/ck.1"
  )

# 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}/clparser.c
  ${SRC_DIR}/confparser.c
  ${SRC_DIR}/dblayer.c
  ${SRC_DIR}/queries.c
  ${SRC_DIR}/ckutil.c
  ${SRC_DIR}/cklist.c
  ${SRC_DIR}/ckerrlog.c
  ${SRC_DIR}/init.c
  ${SRC_DIR}/add.c
  ${SRC_DIR}/delete.c
  ${SRC_DIR}/edit.c
  ${SRC_DIR}/list.c
  ${SRC_DIR}/restore.c
  ${SRC_DIR}/search.c
  ${SRC_DIR}/help.c
  ${SRC_DIR}/export.c
  )

set(ckLib_hdr
  ${SRC_DIR}/clparser.h
  ${SRC_DIR}/actions.h
  ${SRC_DIR}/confparser.h
  ${SRC_DIR}/dblayer.h
  ${SRC_DIR}/queries.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)
install(FILES ${CMAKE_BINARY_DIR}/ck.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/man/man1)

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)  # used in the tests
  file(GLOB files "${TEST_DIR}/*")
  foreach(file ${files})
    get_filename_component(BASENAME ${file} NAME)
    configure_file(${file} ${BIN_TEST_DIR}/${BASENAME} @ONLY)
  endforeach()
  # test-ck
  configure_file(${RES_DIR}/test-ck test-ck @ONLY)
endif()