-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
172 lines (145 loc) · 5.41 KB
/
CMakeLists.txt
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
project(onak VERSION 0.6.3 LANGUAGES C)
include(CheckSymbolExists)
include(FindPkgConfig)
include(GNUInstallDirs)
include(TestBigEndian)
# Fall back for earlier versions of CMake which lack RUNSTATEDIR
if ("x${CMAKE_INSTALL_FULL_RUNSTATEDIR}" STREQUAL "x")
set(CMAKE_INSTALL_FULL_RUNSTATEDIR
${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/run)
endif()
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
# Configuration options from the user
set(DBTYPE "dynamic" CACHE STRING
"Configure the default database backend to use" )
option(KEYD
"Enable the key daemon to handle communication with the key database"
ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
TEST_BIG_ENDIAN(WORDS_BIGENDIAN)
include(CheckCSourceCompiles)
check_c_source_compiles(
"
#include <stdlib.h>
static void f(__attribute__((unused))) {}
int main(void) { f(); return 0;}
"
HAVE___ATTRIBUTE__UNUSED
)
if (HAVE___ATTRIBUTE__UNUSED)
set(UNUSED_ATTRIB "__attribute__((unused))")
else()
set(UNUSED_ATTRIB "")
endif()
# Pick up a git based version number for development builds
find_package(Git)
if (GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
if (EXISTS "${CMAKE_SOURCE_DIR}/.git/refs/tags/onak-0.6.2")
EXECUTE_PROCESS(
COMMAND ${GIT_EXECUTABLE} describe --tags --dirty
OUTPUT_VARIABLE GIT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE "onak-" "" VERSION ${GIT_VERSION})
else()
EXECUTE_PROCESS(
COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
OUTPUT_VARIABLE VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
else()
set(VERSION ${PROJECT_VERSION})
endif()
# Core objects
add_library(libonak STATIC armor.c charfuncs.c cleankey.c cleanup.c decodekey.c
hash.c hash-helper.c key-store.c keyarray.c keyid.c keyindex.c
ll.c log.c marshal.c mem.c merge.c onak-conf.c parsekey.c photoid.c
rsa.c sigcheck.c sendsync.c sha1x.c wordlist.c)
set(LIBONAK_LIBRARIES "")
# Ideally use Nettle, fall back to our own md5/sha1 routines otherwise
pkg_check_modules(NETTLE nettle)
if (NETTLE_FOUND)
set(HAVE_NETTLE true)
target_include_directories(libonak SYSTEM PUBLIC ${NETTLE_INCLUDE_DIRS})
LIST(APPEND LIBONAK_LIBRARIES ${NETTLE_LIBRARIES})
else()
target_sources(libonak PRIVATE md5.c sha1.c)
endif()
# We need libhogweed and libgmp to be able to do more than hash calculations
pkg_check_modules(HOGWEED hogweed)
if (HOGWEED_FOUND)
find_package(GMP)
endif()
if (GMP_FOUND)
set(HAVE_CRYPTO true)
target_include_directories(libonak SYSTEM PUBLIC
${GMP_INCLUDE_DIRS} ${HOGWEED_INCLUDE_DIRS})
LIST(APPEND LIBONAK_LIBRARIES ${GMP_LIBRARY} ${HOGWEED_LIBRARIES})
set(CMAKE_REQUIRED_INCLUDES ${NETTLE_INCLUDE_DIRS})
set(CMAKE_REQUIRED_LIBRARIES ${NETTLE_LIBRARIES} ${HOGWEED_LIBRARIES})
# API change in later version of Nettle
CHECK_SYMBOL_EXISTS(nettle_get_secp_256r1 "nettle/ecc-curve.h" HAVE_NETTLE_GET_SECP_256R1)
CHECK_SYMBOL_EXISTS(nettle_get_secp_384r1 "nettle/ecc-curve.h" HAVE_NETTLE_GET_SECP_384R1)
CHECK_SYMBOL_EXISTS(nettle_get_secp_521r1 "nettle/ecc-curve.h" HAVE_NETTLE_GET_SECP_521R1)
endif()
# keyd will use this for socket activation, if it's available
pkg_check_modules(SYSTEMD libsystemd)
if (SYSTEMD_FOUND)
set(HAVE_SYSTEMD true)
endif()
# Build files that have substitutions in them
include_directories(${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR})
configure_file("${CMAKE_SOURCE_DIR}/build-config.h.in"
"${CMAKE_BINARY_DIR}/build-config.h" @ONLY)
configure_file("${CMAKE_SOURCE_DIR}/onak.ini.in"
"${CMAKE_BINARY_DIR}/onak.ini" @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/onak.ini
DESTINATION ${CMAKE_INSTALL_SYSCONFDIR})
configure_file("${CMAKE_SOURCE_DIR}/onak-mail.pl.in"
"${CMAKE_BINARY_DIR}/onak-mail.pl" @ONLY)
install(PROGRAMS ${CMAKE_BINARY_DIR}/onak-mail.pl
DESTINATION ${CMAKE_INSTALL_LIBDIR}/onak/)
install(FILES onak-mail.pl.8 DESTINATION ${CMAKE_INSTALL_MANDIR}/man8/)
# Key database backends
add_subdirectory(keydb)
# Now we have the DB type confirmed we can tidy up the libonak options
if (DBTYPE STREQUAL "dynamic")
LIST(APPEND LIBONAK_LIBRARIES "dl")
else()
list (FIND BACKENDS ${DBTYPE} _index)
if (${_index} LESS 0)
message(FATAL_ERROR "${DBTYPE} is not a supported DB backend.")
endif()
LIST(APPEND LIBONAK_LIBRARIES ${BACKEND_${DBTYPE}_LIBS})
endif()
# For onak-conf.o compilation
target_compile_definitions(libonak PRIVATE
CONFIGDIR="${CMAKE_INSTALL_FULL_SYSCONFDIR}"
DBINIT=keydb_${DBTYPE}_init)
# DB Backend related options are known, so finish off libonak configuration
target_sources(libonak PRIVATE keydb/keydb_${DBTYPE}.c)
target_link_libraries(libonak ${LIBONAK_LIBRARIES})
# CGI directory
add_subdirectory(cgi)
# Executables start here
# Swiss Army tool
add_executable(onak onak.c)
target_link_libraries(onak libonak)
# Tools that operate on the key DB
add_executable(maxpath maxpath.c stats.c)
target_link_libraries(maxpath libonak)
add_executable(sixdegrees sixdegrees.c stats.c)
target_link_libraries(sixdegrees libonak)
add_executable(wotsap wotsap.c)
target_link_libraries(wotsap libonak)
# Stand alone tools
add_executable(splitkeys splitkeys.c)
target_link_libraries(splitkeys libonak)
add_executable(stripkey stripkey.c)
target_link_libraries(stripkey libonak)
install(TARGETS onak splitkeys RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES onak.1 splitkeys.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1/)
# Basic unit tests
enable_testing()
add_test(NAME syntaxtest COMMAND perl -cw ${CMAKE_BINARY_DIR}/onak-mail.pl)
add_test(NAME sanitytests COMMAND ${CMAKE_SOURCE_DIR}/runtests)