]> the.earth.li Git - onak.git/blob - CMakeLists.txt
eebafdd4ebfb99d1f9494325fe743eaa0b96d38a
[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 list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
14
15 # Configuration options from the user
16 set(DBTYPE "dynamic" CACHE STRING
17         "Configure the default database backend to use" )
18 option(KEYD
19         "Enable the key daemon to handle communication with the key database"
20         ON)
21
22 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
23 TEST_BIG_ENDIAN(WORDS_BIGENDIAN)
24
25 # Pick up a git based version number for development builds
26 find_package(Git)
27 if (GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
28         EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} describe --tags --dirty
29                 OUTPUT_VARIABLE GIT_VERSION
30                 OUTPUT_STRIP_TRAILING_WHITESPACE)
31         string(REPLACE "onak-" "" VERSION ${GIT_VERSION})
32 else()
33         set(VERSION ${PROJECT_VERSION})
34 endif()
35
36 # Core objects
37 add_library(libonak STATIC armor.c charfuncs.c cleankey.c cleanup.c decodekey.c
38         getcgi.c hash.c keyarray.c keyid.c keyindex.c ll.c log.c marshal.c
39         mem.c merge.c onak-conf.c parsekey.c photoid.c rsa.c sigcheck.c sendsync.c
40         sha1x.c wordlist.c)
41 set(LIBONAK_LIBRARIES "")
42
43 # Ideally use Nettle, fall back to our own md5/sha1 routines otherwise
44 pkg_check_modules(NETTLE nettle)
45 if (NETTLE_FOUND)
46         set(HAVE_NETTLE true)
47         target_include_directories(libonak SYSTEM PUBLIC ${NETTLE_INCLUDE_DIRS})
48         LIST(APPEND LIBONAK_LIBRARIES ${NETTLE_LIBRARIES})
49 else()
50         target_sources(libonak PRIVATE md5.c sha1.c)
51 endif()
52
53 # We need libhogweed and libgmp to be able to do more than hash calculations
54 pkg_check_modules(HOGWEED hogweed)
55 if (HOGWEED_FOUND)
56         find_package(GMP)
57 endif()
58 if (GMP_FOUND)
59         set(HAVE_CRYPTO true)
60         target_include_directories(libonak SYSTEM PUBLIC
61                         ${GMP_INCLUDE_DIRS} ${HOGWEED_INCLUDE_DIRS})
62         LIST(APPEND LIBONAK_LIBRARIES ${GMP_LIBRARY} ${HOGWEED_LIBRARIES})
63 endif()
64
65 # Build files that have substitutions in them
66 include_directories(${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR})
67 configure_file("${CMAKE_SOURCE_DIR}/build-config.h.in"
68         "${CMAKE_BINARY_DIR}/build-config.h" @ONLY)
69
70 configure_file("${CMAKE_SOURCE_DIR}/onak.ini.in"
71         "${CMAKE_BINARY_DIR}/onak.ini" @ONLY)
72 install(FILES ${CMAKE_BINARY_DIR}/onak.ini
73         DESTINATION ${CMAKE_INSTALL_SYSCONFDIR})
74
75 configure_file("${CMAKE_SOURCE_DIR}/onak-mail.pl.in"
76         "${CMAKE_BINARY_DIR}/onak-mail.pl" @ONLY)
77 install(PROGRAMS ${CMAKE_BINARY_DIR}/onak-mail.pl
78         DESTINATION ${CMAKE_INSTALL_LIBDIR}/onak/)
79 install(FILES onak-mail.pl.8 DESTINATION ${CMAKE_INSTALL_MANDIR}/man8/)
80
81 # Key database backends
82 add_subdirectory(keydb)
83
84 # Now we have the DB type confirmed we can tidy up the libonak options
85
86 if (DBTYPE STREQUAL "dynamic")
87         LIST(APPEND LIBONAK_LIBRARIES "dl")
88 else()
89         list (FIND BACKENDS ${DBTYPE} _index)
90         if (${_index} LESS 0)
91                 message(FATAL_ERROR "${DBTYPE} is not a supported DB backend.")
92         endif()
93
94         LIST(APPEND LIBONAK_LIBRARIES ${BACKEND_${DBTYPE}_LIBS})
95 endif()
96
97 # For onak-conf.o compilation
98 target_compile_definitions(libonak PRIVATE
99         CONFIGDIR="${CMAKE_INSTALL_FULL_SYSCONFDIR}"
100         DBINIT=keydb_${DBTYPE}_init)
101
102 # DB Backend related options are known, so finish off libonak configuration
103 target_sources(libonak PRIVATE keydb/keydb_${DBTYPE}.c)
104 target_link_libraries(libonak ${LIBONAK_LIBRARIES})
105
106 # CGI directory
107 add_subdirectory(cgi)
108
109 # Executables start here
110
111 # Swiss Army tool
112 add_executable(onak onak.c)
113 target_link_libraries(onak libonak)
114
115 # Tools that operate on the key DB
116 add_executable(maxpath maxpath.c stats.c)
117 target_link_libraries(maxpath libonak)
118 add_executable(sixdegrees sixdegrees.c stats.c)
119 target_link_libraries(sixdegrees libonak)
120 add_executable(wotsap wotsap.c)
121 target_link_libraries(wotsap libonak)
122
123 # Stand alone tools
124 add_executable(splitkeys splitkeys.c)
125 target_link_libraries(splitkeys libonak)
126 add_executable(stripkey stripkey.c)
127 target_link_libraries(stripkey libonak)
128
129 install(TARGETS onak splitkeys RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
130 install(FILES onak.1 splitkeys.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1/)
131
132 # Basic unit tests
133 enable_testing()
134 add_test(NAME syntaxtest COMMAND perl -cw ${CMAKE_BINARY_DIR}/onak-mail.pl)
135 add_test(NAME sanitytests COMMAND ${CMAKE_SOURCE_DIR}/runtests)