]> the.earth.li Git - onak.git/blob - CMakeLists.txt
Set Rules-Requires-Root to no
[onak.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
2 project(onak VERSION 0.5.0 LANGUAGES C)
3
4 include(FindPkgConfig)
5 include(GNUInstallDirs)
6 include(TestBigEndian)
7 # Fall back for earlier versions of CMake which lack RUNSTATEDIR
8 if ("x${CMAKE_INSTALL_FULL_RUNSTATEDIR}" STREQUAL "x")
9         set(CMAKE_INSTALL_FULL_RUNSTATEDIR
10                 ${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/run)
11 endif()
12
13 # Configuration options from the user
14 set(DBTYPE "dynamic" CACHE STRING
15         "Configure the default database backend to use" )
16 option(KEYD
17         "Enable the key daemon to handle communication with the key database"
18         ON)
19
20 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
21 TEST_BIG_ENDIAN(WORDS_BIGENDIAN)
22
23 # Pick up a git based version number for development builds
24 find_package(Git)
25 if (GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
26         EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} describe --tags --dirty
27                 OUTPUT_VARIABLE GIT_VERSION
28                 OUTPUT_STRIP_TRAILING_WHITESPACE)
29         string(REPLACE "onak-" "" VERSION ${GIT_VERSION})
30 else()
31         set(VERSION ${PROJECT_VERSION})
32 endif()
33
34 # Core objects
35 add_library(libonak STATIC armor.c charfuncs.c cleankey.c cleanup.c decodekey.c
36         getcgi.c hash.c keyarray.c keyid.c keyindex.c ll.c log.c marshal.c
37         mem.c merge.c onak-conf.c parsekey.c photoid.c sigcheck.c sendsync.c
38         sha1x.c wordlist.c)
39 set(LIBONAK_LIBRARIES "")
40
41 # Ideally use Nettle, fall back to our own md5/sha1 routines otherwise
42 pkg_check_modules(NETTLE nettle)
43 if (NETTLE_FOUND)
44         set(HAVE_NETTLE true)
45         target_include_directories(libonak SYSTEM PUBLIC ${NETTLE_INCLUDE_DIRS})
46         LIST(APPEND LIBONAK_LIBRARIES ${NETTLE_LIBRARIES})
47 else()
48         target_sources(libonak PRIVATE md5.c sha1.c)
49 endif()
50
51 # Backends
52
53 # These have no dependencies and can always be compiled
54 set(BACKENDS "file" "fs" "keyring" "stacked")
55
56 # DB4 backend (add check for existence)
57 LIST(APPEND BACKENDS db4)
58 set(BACKEND_db4_LIBS db-5.3)
59
60 # HKP backend - needs libcurl
61 pkg_check_modules(CURL libcurl)
62 if (CURL_FOUND)
63         LIST(APPEND BACKENDS hkp)
64         set(BACKEND_hkp_INC ${CURL_INCLUDE_DIRS})
65         set(BACKEND_hkp_LIBS ${CURL_LIBRARIES})
66 endif()
67
68 # PostgreSQL backend - needs libpq
69 pkg_check_modules(POSTGRESQL libpq)
70 if (POSTGRESQL_FOUND)
71         LIST(APPEND BACKENDS pg)
72         set(BACKEND_pg_INC ${POSTGRESQL_INCLUDE_DIRS})
73         set(BACKEND_pg_LIBS ${POSTGRESQL_LIBRARIES})
74 endif()
75
76 # keyd backend - can be disabled entirely
77 if (KEYD STREQUAL "ON")
78         LIST(APPEND BACKENDS keyd)
79
80         add_executable(keyd keyd.c)
81         target_link_libraries(keyd libonak)
82         add_executable(keydctl keydctl.c onak-conf.c)
83         target_link_libraries(keydctl libonak)
84         target_compile_definitions(keydctl PRIVATE
85                 CONFIGDIR="${CMAKE_INSTALL_FULL_SYSCONFDIR}")
86
87         pkg_check_modules(SYSTEMD libsystemd)
88         if (SYSTEMD_FOUND)
89                 set(HAVE_SYSTEMD true)
90                 target_include_directories(keyd SYSTEM PUBLIC
91                         ${SYSTEMD_INCLUDE_DIRS})
92                 target_link_libraries(keyd ${SYSTEMD_LIBRARIES})
93         endif()
94
95         install(TARGETS keydctl RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
96         install(TARGETS keyd RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR})
97         install(FILES keyd.8 keydctl.8
98                 DESTINATION ${CMAKE_INSTALL_MANDIR}/man8/)
99 endif()
100
101
102 # Now we have the DB type confirmed we can tidy up the libonak options
103
104 if (DBTYPE STREQUAL "dynamic")
105         LIST(APPEND LIBONAK_LIBRARIES "dl")
106         foreach(BACKEND IN LISTS BACKENDS)
107                 add_library(keydb_${BACKEND} SHARED keydb_${BACKEND}.c)
108                 target_include_directories(keydb_${BACKEND} SYSTEM PUBLIC
109                         ${BACKEND_${BACKEND}_INC})
110                 target_link_libraries(keydb_${BACKEND} libonak
111                         ${BACKEND_${BACKEND}_LIBS})
112                 install(TARGETS keydb_${BACKEND} LIBRARY DESTINATION
113                         ${CMAKE_INSTALL_LIBDIR}/onak/backends/)
114         endforeach(BACKEND)
115 else()
116         list (FIND BACKENDS ${DBTYPE} _index)
117         if (${_index} LESS 0)
118                 message(FATAL_ERROR "${DBTYPE} is not a supported DB backend.")
119         endif()
120
121         LIST(APPEND LIBONAK_LIBRARIES ${BACKEND_${DBTYPE}_LIBS})
122 endif()
123
124 # For onak-conf.o compilation
125 target_compile_definitions(libonak PRIVATE
126         CONFIGDIR="${CMAKE_INSTALL_FULL_SYSCONFDIR}"
127         DBINIT=keydb_${DBTYPE}_init)
128
129 # DB Backend related options are known, so finish off libonak configuration
130 target_sources(libonak PRIVATE keydb_${DBTYPE}.c)
131 target_link_libraries(libonak ${LIBONAK_LIBRARIES})
132
133 # Build files that have substitutions in them
134 include_directories(${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR})
135 configure_file("${CMAKE_SOURCE_DIR}/build-config.h.in"
136         "${CMAKE_BINARY_DIR}/build-config.h" @ONLY)
137
138 configure_file("${CMAKE_SOURCE_DIR}/onak.ini.in"
139         "${CMAKE_BINARY_DIR}/onak.ini" @ONLY)
140 install(FILES ${CMAKE_BINARY_DIR}/onak.ini
141         DESTINATION ${CMAKE_INSTALL_SYSCONFDIR})
142
143 configure_file("${CMAKE_SOURCE_DIR}/onak-mail.pl.in"
144         "${CMAKE_BINARY_DIR}/onak-mail.pl" @ONLY)
145 install(PROGRAMS ${CMAKE_BINARY_DIR}/onak-mail.pl
146         DESTINATION ${CMAKE_INSTALL_LIBDIR}/onak/)
147 install(FILES onak-mail.pl.8 DESTINATION ${CMAKE_INSTALL_MANDIR}/man8/)
148
149 # CGI directory
150 add_subdirectory(cgi)
151
152 # Executables start here
153
154 # Swiss Army tool
155 add_executable(onak onak.c)
156 target_link_libraries(onak libonak)
157
158 # Tools that operate on the key DB
159 add_executable(maxpath maxpath.c stats.c)
160 target_link_libraries(maxpath libonak)
161 add_executable(sixdegrees sixdegrees.c stats.c)
162 target_link_libraries(sixdegrees libonak)
163 add_executable(wotsap wotsap.c)
164 target_link_libraries(wotsap libonak)
165
166 # Stand alone tools
167 add_executable(splitkeys splitkeys.c)
168 target_link_libraries(splitkeys libonak)
169 add_executable(stripkey stripkey.c)
170 target_link_libraries(stripkey libonak)
171
172 install(TARGETS onak splitkeys RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
173 install(FILES onak.1 splitkeys.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1/)
174
175 # Basic unit tests
176 enable_testing()
177 add_test(NAME syntaxtest COMMAND perl -cw ${CMAKE_BINARY_DIR}/onak-mail.pl)
178 add_test(NAME sanitytests COMMAND ${CMAKE_SOURCE_DIR}/runtests)