-
Notifications
You must be signed in to change notification settings - Fork 18
/
CMakeLists.txt
444 lines (392 loc) · 16.6 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
############################# INITIAL SECTION #############################################
PROJECT(rmilter C)
SET(RMILTER_VERSION_MAJOR 2)
SET(RMILTER_VERSION_MINOR 0)
SET(RMILTER_VERSION_PATCH 0)
IF(GIT_ID)
SET(RMILTER_VERSION
"${RMILTER_VERSION_MAJOR}.${RMILTER_VERSION_MINOR}.${RMILTER_VERSION_PATCH}-${GIT_ID}")
ELSE()
SET(RMILTER_VERSION
"${RMILTER_VERSION_MAJOR}.${RMILTER_VERSION_MINOR}.${RMILTER_VERSION_PATCH}")
ENDIF()
SET(RMILTER_MASTER_SITE_URL "https://rspamd.com")
IF(NOT RMILTER_USER)
SET(RMILTER_USER "nobody")
SET(RMILTER_GROUP "nobody")
ENDIF()
IF(NOT SYSTEMDDIR)
SET(SYSTEMDDIR ${CMAKE_INSTALL_PREFIX}/lib/systemd/system)
ENDIF(NOT SYSTEMDDIR)
IF(NOT MANDIR)
SET(MANDIR "${CMAKE_INSTALL_PREFIX}/share/man")
ENDIF(NOT MANDIR)
IF(NOT SBINDIR)
SET(SBINDIR "${CMAKE_INSTALL_PREFIX}/sbin")
ENDIF(NOT SBINDIR)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0 FATAL_ERROR)
############################# OPTIONS SECTION #############################################
OPTION(ENABLE_DEBUG "Enable debug output [default: OFF]" OFF)
OPTION(ENABLE_OPTIMIZATION "Enable optimization [default: OFF]" OFF)
OPTION(ENABLE_DKIM "Enable dkim signatures [default: ON]" ON)
OPTION(ENABLE_MEMCACHED "Enable memcached storage [default: OFF]" OFF)
OPTION(WANT_SYSTEMD_UNITS "Install systemd unit files on Linux [default: OFF]" OFF)
############################# INCLUDE SECTION #############################################
INCLUDE(CheckIncludeFiles)
INCLUDE(CheckFunctionExists)
INCLUDE(CheckSymbolExists)
INCLUDE(CheckCSourceCompiles)
INCLUDE(CheckLibraryExists)
INCLUDE(FindPkgConfig)
INCLUDE(CheckCCompilerFlag)
INCLUDE(FindThreads)
FIND_PACKAGE(BISON)
FIND_PACKAGE(FLEX)
SET(RMILTER_DEFAULT_INCLUDE_PATHS "/opt;/usr;/usr/local;/opt/local;/usr/pkg;/opt/csw;/sw")
SET(RMILTER_DEFAULT_LIBRARY_PATHS "/usr/local;/usr/pkg;/usr;/Library/Frameworks;/sw;/opt/local;/opt/csw;/opt")
# Process required package by using FindPackage and calling for INCLUDE_DIRECTORIES and
# setting list of required libraries
# Usage:
# ProcessPackage(VAR [OPTIONAL] [ROOT path] [INCLUDE path]
# [LIBRARY path] [INCLUDE_SUFFIXES path1 path2 ...] [LIB_SUFFIXES path1 path2 ...]
# [MODULES module1 module2 ...])
# params:
# OPTIONAL - do not fail if a package has not been found
# ROOT - defines root directory for a package
# INCLUDE - name of the include file to check
# LIBRARY - name of the library to check
# INCLUDE_SUFFIXES - list of include suffixes (relative to ROOT)
# LIB_SUFFIXES - list of library suffixes
# MODULES - modules to search using pkg_config
MACRO(ProcessPackage PKG_NAME)
CMAKE_PARSE_ARGUMENTS(PKG "OPTIONAL" "ROOT;INCLUDE"
"LIBRARY;INCLUDE_SUFFIXES;LIB_SUFFIXES;MODULES" ${ARGN})
IF(NOT PKG_LIBRARY)
SET(PKG_LIBRARY "${PKG_NAME}")
ENDIF()
IF(NOT PKG_INCLUDE)
SET(PKG_INCLUDE "${PKG_NAME}.h")
ENDIF()
IF(NOT PKG_ROOT AND PKG_MODULES)
PKG_SEARCH_MODULE(${PKG_NAME} ${PKG_MODULES})
ENDIF()
IF(${PKG_NAME}_FOUND)
MESSAGE(STATUS "Found package ${PKG_NAME} in pkg-config modules ${PKG_MODULES}")
SET(WITH_${PKG_NAME} 1 CACHE INTERNAL "")
IF(ENABLE_STATIC MATCHES "ON")
SET(_XPREFIX "${PKG_NAME}_STATIC")
ELSE(ENABLE_STATIC MATCHES "ON")
SET(_XPREFIX "${PKG_NAME}")
ENDIF(ENABLE_STATIC MATCHES "ON")
FOREACH(_arg ${${_XPREFIX}_INCLUDE_DIRS})
INCLUDE_DIRECTORIES("${_arg}")
SET(${PKG_NAME}_INCLUDE "${_arg}")
ENDFOREACH(_arg ${${_XPREFIX}_INCLUDE_DIRS})
FOREACH(_arg ${${_XPREFIX}_LIBRARY_DIRS})
LINK_DIRECTORIES("${_arg}")
SET(${PKG_NAME}_LIBRARY "${_arg}")
ENDFOREACH(_arg ${${_XPREFIX}_LIBRARY_DIRS})
# Handle other CFLAGS and LDFLAGS
FOREACH(_arg ${${_XPREFIX}_CFLAGS_OTHER})
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_arg}")
ENDFOREACH(_arg ${${_XPREFIX}_CFLAGS_OTHER})
FOREACH(_arg ${${_XPREFIX}_LDFLAGS_OTHER})
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${_arg}")
ENDFOREACH(_arg ${${_XPREFIX}_LDFLAGS_OTHER})
LIST(APPEND RMILTER_REQUIRED_LIBRARIES "${${_XPREFIX}_LIBRARIES}")
INCLUDE_DIRECTORIES(${${_XPREFIX}_INCLUDEDIR})
ELSE()
IF(NOT ${PKG_NAME}_GUESSED)
# Try some more heuristic
FIND_LIBRARY(_lib NAMES ${PKG_LIBRARY}
HINTS ${PKG_ROOT} ${RMILTER_SEARCH_PATH}
PATH_SUFFIXES ${PKG_LIB_SUFFIXES} lib64 lib
PATHS ${RMILTER_DEFAULT_LIBRARY_PATHS})
IF(NOT _lib)
IF(PKG_OPTIONAL)
MESSAGE(STATUS "Cannot find library ${PKG_LIBRARY} for package ${PKG_NAME}")
ELSE()
MESSAGE(FATAL_ERROR "Cannot find library ${PKG_LIBRARY} for package ${PKG_NAME}")
ENDIF()
ENDIF(NOT _lib)
FIND_PATH(_incl ${PKG_INCLUDE}
HINTS ${PKG_ROOT} ${RMILTER_SEARCH_PATH}
PATH_SUFFIXES ${PKG_INCLUDE_SUFFIXES} "include"
PATHS ${RMILTER_DEFAULT_INCLUDE_PATHS})
IF(NOT _incl)
IF(PKG_OPTIONAL)
MESSAGE(STATUS "Cannot find header ${PKG_INCLUDE} for package ${PKG_NAME}")
ELSE()
MESSAGE(FATAL_ERROR "Cannot find header ${PKG_INCLUDE} for package ${PKG_NAME}")
ENDIF()
ENDIF(NOT _incl)
IF(_incl AND _lib)
GET_FILENAME_COMPONENT(_lib_path "${_lib}" PATH)
INCLUDE_DIRECTORIES("${_incl}")
LINK_DIRECTORIES("${_lib_path}")
LIST(APPEND RMILTER_REQUIRED_LIBRARIES ${_lib})
SET(${PKG_NAME}_INCLUDE "${_incl}" CACHE INTERNAL "")
SET(${PKG_NAME}_LIBRARY_PATH "${_lib_path}" CACHE INTERNAL "")
SET(${PKG_NAME}_LIBRARY "${_lib}" CACHE INTERNAL "")
SET(${PKG_NAME}_GUESSED 1 CACHE INTERNAL "")
SET(WITH_${PKG_NAME} 1 CACHE INTERNAL "")
MESSAGE(STATUS "Found package ${PKG_NAME} in '${_lib_path}' (${_lib}) and '${_incl}' (${PKG_INCLUDE}).")
ENDIF()
ELSE()
MESSAGE(STATUS "Found package ${PKG_NAME} (cached)")
INCLUDE_DIRECTORIES("${${PKG_NAME}_INCLUDE}")
LINK_DIRECTORIES("${${PKG_NAME}_LIBRARY_PATH}")
LIST(APPEND RMILTER_REQUIRED_LIBRARIES "${${PKG_NAME}_LIBRARY}")
ENDIF()
ENDIF(${PKG_NAME}_FOUND)
UNSET(_lib CACHE)
UNSET(_incl CACHE)
ENDMACRO(ProcessPackage name)
############################# OS SECTION #############################################
SET(TAR "tar")
IF(CMAKE_SYSTEM_NAME MATCHES "^.*BSD$|DragonFly")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_BSD_SOURCE -DFREEBSD")
SET(TAR "gtar")
MESSAGE(STATUS "Configuring for FreeBSD")
ENDIF()
IF(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_BSD_SOURCE -DDARWIN")
SET(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS} -undefined dynamic_lookup")
MESSAGE(STATUS "Configuring for Darwin")
SET(TAR "gnutar")
ENDIF()
IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE -DLINUX")
IF(BUILD_CPU_MODE STREQUAL "32")
SET(CMAKE_C_FLAGS "-D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE ${CMAKE_C_FLAGS}")
ENDIF(BUILD_CPU_MODE STREQUAL "32")
LIST(APPEND RMILTER_REQUIRED_LIBRARIES resolv)
LIST(APPEND RMILTER_DEFAULT_INCLUDE_PATHS "/usr/include/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu/")
LIST(APPEND RMILTER_DEFAULT_LIBRARY_PATHS "/usr/lib/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu/")
ENDIF()
IF(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
IF(NOT BUILD_CPU_MODE)
SET (BUILD_CPU_MODE "32")
ENDIF(NOT BUILD_CPU_MODE)
IF("${CMAKE_C_COMPILER_ID}" MATCHES SunPro)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Xa -xregs=no%frameptr -xstrconst -xc99")
SET(SUN_BUILD32 "-xtarget=generic")
SET(SUN_BUILD64 "-xtarget=generic64")
IF(ENABLE_OPTIMIZATION MATCHES "ON")
SET(CMAKE_C_OPT_FLAGS "-fast -xdepend")
ELSE(ENABLE_OPTIMIZATION MATCHES "ON")
SET(CMAKE_C_OPT_FLAGS "-xO0")
ENDIF(ENABLE_OPTIMIZATION MATCHES "ON")
ELSE("${CMAKE_C_COMPILER_ID}" MATCHES SunPro)
set(SUN_BUILD32 "-m32")
set(SUN_BUILD64 "-m64")
ENDIF("${CMAKE_C_COMPILER_ID}" MATCHES SunPro)
IF (BUILD_CPU_MODE STREQUAL "32")
message (STATUS "Building 32-bit mode on Solaris")
# If we are asked to build 32 bit mode
set(CMAKE_C_FLAGS "${SUN_BUILD32} ${CMAKE_C_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${SUN_BUILD32}")
ELSE (BUILD_CPU_MODE STREQUAL "32")
# solaris 64-bit mode
message (STATUS "Building 64-bit mode on Solaris")
set(CMAKE_C_FLAGS "${SUN_BUILD64} ${CMAKE_C_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${SUN_BUILD64}")
ENDIF (BUILD_CPU_MODE STREQUAL "32")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__EXTENSIONS__ -DSOLARIS -D_POSIX_SOURCE -D_POSIX_C_SOURCE=200112L")
LIST(APPEND RMILTER_REQUIRED_LIBRARIES rt)
LIST(APPEND RMILTER_REQUIRED_LIBRARIES dl)
LIST(APPEND RMILTER_REQUIRED_LIBRARIES resolv)
LIST(APPEND RMILTER_REQUIRED_LIBRARIES nsl)
LIST(APPEND RMILTER_REQUIRED_LIBRARIES socket)
LIST(APPEND RMILTER_REQUIRED_LIBRARIES umem)
SET(CMAKE_VERBOSE_MAKEFILE ON)
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
SET(CMAKE_INSTALL_RPATH "${PREFIX}/lib")
ENDIF()
############################# CONFIGURE SECTION #############################################
INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/src"
"${CMAKE_BINARY_DIR}/src"
"${CMAKE_BINARY_DIR}/"
"${CMAKE_SOURCE_DIR}/compat"
"${CMAKE_SOURCE_DIR}/uthash"
"${CMAKE_SOURCE_DIR}/contrib/libucl"
"${CMAKE_SOURCE_DIR}/contrib/http-parser"
"${CMAKE_SOURCE_DIR}/contrib/xxhash")
BISON_TARGET(CfgParser src/cfg_file.y ${CMAKE_CURRENT_BINARY_DIR}/cfg_yacc.c)
FLEX_TARGET(CfgScanner src/cfg_file.l ${CMAKE_CURRENT_BINARY_DIR}/cfg_lex.c)
ADD_FLEX_BISON_DEPENDENCY(CfgScanner CfgParser)
# Process with warn flags
SET(CMAKE_C_WARN_FLAGS "")
CHECK_C_COMPILER_FLAG(-Wall SUPPORT_WALL)
CHECK_C_COMPILER_FLAG(-W SUPPORT_W)
CHECK_C_COMPILER_FLAG(-Wpointer-arith SUPPORT_WPOINTER)
CHECK_C_COMPILER_FLAG(-Wno-unused-parameter SUPPORT_WPARAM)
CHECK_C_COMPILER_FLAG(-Wno-unused-function SUPPORT_WFUNCTION)
CHECK_C_COMPILER_FLAG(-Wunused-variable SUPPORT_WUNUSED_VAR)
CHECK_C_COMPILER_FLAG(-Wpointer-sign SUPPORT_WPOINTER_SIGN)
CHECK_C_COMPILER_FLAG(-Wsign-compare SUPPORT_WSIGN_COMPARE)
CHECK_C_COMPILER_FLAG(-Wstrict-prototypes SUPPORT_WSTRICT_PROTOTYPES)
IF(NOT "${CMAKE_C_COMPILER_ID}" MATCHES SunPro)
CHECK_C_COMPILER_FLAG("-std=c99" SUPPORT_STD_FLAG)
ENDIF(NOT "${CMAKE_C_COMPILER_ID}" MATCHES SunPro)
IF(SUPPORT_W)
SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -W")
ENDIF(SUPPORT_W)
IF(SUPPORT_WALL)
SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -Wall")
ENDIF(SUPPORT_WALL)
IF(SUPPORT_WPOINTER)
SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -Wpointer-arith")
ENDIF(SUPPORT_WPOINTER)
IF(SUPPORT_WPARAM)
SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -Wno-unused-parameter")
ENDIF(SUPPORT_WPARAM)
IF(SUPPORT_WFUNCTION)
SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -Wno-unused-function")
ENDIF(SUPPORT_WFUNCTION)
IF(SUPPORT_WUNUSED_VAR)
SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -Wno-unused-variable")
ENDIF(SUPPORT_WUNUSED_VAR)
IF(SUPPORT_WPOINTER_SIGN)
SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -Wno-pointer-sign")
ENDIF(SUPPORT_WPOINTER_SIGN)
IF(SUPPORT_WSIGN_COMPARE)
SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -Wno-sign-compare")
ENDIF(SUPPORT_WSIGN_COMPARE)
IF(SUPPORT_WSTRICT_PROTOTYPES)
SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -Wstrict-prototypes")
ENDIF(SUPPORT_WSTRICT_PROTOTYPES)
IF(SUPPORT_STD_FLAG)
SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -std=c99")
ENDIF(SUPPORT_STD_FLAG)
# Optimization flags
IF(NOT CMAKE_C_OPT_FLAGS)
IF(ENABLE_OPTIMIZATION MATCHES "ON")
SET(CMAKE_C_OPT_FLAGS "-O3 -fstrict-aliasing")
ELSE(ENABLE_OPTIMIZATION MATCHES "ON")
SET(CMAKE_C_OPT_FLAGS "-g -O2 -fstrict-aliasing")
ENDIF(ENABLE_OPTIMIZATION MATCHES "ON")
ENDIF(NOT CMAKE_C_OPT_FLAGS)
IF(ENABLE_DEBUG MATCHES "ON")
SET(CMAKE_BUILD_TYPE "Debug")
SET(WITH_DEBUG 1)
ENDIF(ENABLE_DEBUG MATCHES "ON")
SET(CMAKE_C_FLAGS "${CMAKE_C_OPT_FLAGS} ${CMAKE_C_FLAGS} ${CMAKE_C_WARN_FLAGS}")
CHECK_INCLUDE_FILES(sys/types.h HAVE_SYS_TYPES_H)
CHECK_INCLUDE_FILES(sys/time.h HAVE_SYS_TIME_H)
CHECK_INCLUDE_FILES(sys/uio.h HAVE_SYS_UIO_H)
CHECK_INCLUDE_FILES(fcntl.h HAVE_FCNTL_H)
CHECK_INCLUDE_FILES(math.h HAVE_MATH_H)
CHECK_INCLUDE_FILES(stdio.h HAVE_STDIO_H)
CHECK_INCLUDE_FILES(stdlib.h HAVE_STDLIB_H)
CHECK_INCLUDE_FILES(string.h HAVE_STRING_H)
CHECK_INCLUDE_FILES(strings.h HAVE_STRINGS_H)
CHECK_INCLUDE_FILES(time.h HAVE_TIME_H)
CHECK_INCLUDE_FILES(unistd.h HAVE_UNISTD_H)
CHECK_INCLUDE_FILES(sysexits.h HAVE_SYSEXITS_H)
CHECK_INCLUDE_FILES(stdint.h HAVE_STDINT_H)
CHECK_INCLUDE_FILES(stdbool.h HAVE_STBOOL_H)
CHECK_INCLUDE_FILES(inttypes.h HAVE_INTTYPES_H)
CHECK_INCLUDE_FILES(endian.h HAVE_ENDIAN_H)
CHECK_INCLUDE_FILES(sys/endian.h HAVE_SYS_ENDIAN_H)
CHECK_INCLUDE_FILES(machine/endian.h HAVE_MACHINE_ENDIAN_H)
CHECK_INCLUDE_FILES(sys/socket.h HAVE_SYS_SOCKET_H)
CHECK_INCLUDE_FILES(sys/mman.h HAVE_SYS_MMAN_H)
CHECK_INCLUDE_FILES(sys/un.h HAVE_SYS_UN_H)
CHECK_INCLUDE_FILES(sys/stat.h HAVE_SYS_STAT_H)
CHECK_INCLUDE_FILES(sys/wait.h HAVE_SYS_WAIT_H)
CHECK_INCLUDE_FILES(sys/param.h HAVE_SYS_PARAM_H)
CHECK_INCLUDE_FILES(sys/cdefs.h HAVE_SYS_CDEFS_H)
CHECK_INCLUDE_FILES(sys/file.h HAVE_SYS_FILE_H)
CHECK_INCLUDE_FILES(sys/utsname.h HAVE_SYS_UTSNAME_H)
CHECK_INCLUDE_FILES(sys/resource.h HAVE_SYS_RESOURCE_H)
CHECK_INCLUDE_FILES(netinet/in.h HAVE_NETINET_IN_H)
CHECK_INCLUDE_FILES(arpa/inet.h HAVE_ARPA_INET_H)
CHECK_INCLUDE_FILES(netdb.h HAVE_NETDB_H)
CHECK_INCLUDE_FILES(syslog.h HAVE_SYSLOG_H)
CHECK_INCLUDE_FILES(siginfo.h HAVE_SIGINFO_H)
CHECK_INCLUDE_FILES(sys/sendfile.h HAVE_SYS_SENDFILE_H)
CHECK_INCLUDE_FILES(poll.h HAVE_POLL_H)
IF(HAVE_SYS_SENDFILE_H)
CHECK_SYMBOL_EXISTS(sendfile sys/sendfile.h HAVE_SENDFILE)
ELSE()
# BSD version
CHECK_SYMBOL_EXISTS(sendfile "sys/types.h;sys/socket.h;sys/uio.h" HAVE_SENDFILE)
ENDIF()
CHECK_SYMBOL_EXISTS(mkstemp unistd.h HAVE_MKSTEMP)
CHECK_SYMBOL_EXISTS(PATH_MAX limits.h HAVE_PATH_MAX)
CHECK_SYMBOL_EXISTS(MAXPATHLEN sys/param.h HAVE_MAXPATHLEN)
CHECK_SYMBOL_EXISTS(MAP_SHARED sys/mman.h HAVE_MMAP_SHARED)
CHECK_SYMBOL_EXISTS(MAP_ANON sys/mman.h HAVE_MMAP_ANON)
CHECK_SYMBOL_EXISTS(MAP_NOCORE sys/mman.h HAVE_MMAP_NOCORE)
ProcessPackage(OPENSSL LIBRARY crypto INCLUDE err.h INCLUDE_SUFFIXES include/openssl
ROOT ${OPENSSL_ROOT_DIR} MODULES openssl)
ProcessPackage(LIBMILTER LIBRARY milter INCLUDE mfapi.h INCLUDE_SUFFIXES include/libmilter
LIB_SUFFIXES lib/libmilter ROOT ${LIBMILTER_ROOT_DIR} MODULES libmilter)
ProcessPackage(PCRE LIBRARY pcre INCLUDE pcre.h INCLUDE_SUFFIXES include/pcre
ROOT ${PCRE_ROOT_DIR} MODULES pcre libpcre pcre3 libpcre3)
ProcessPackage(GLIB2 LIBRARY glib-2.0 INCLUDE glib.h
INCLUDE_SUFFIXES include/glib
ROOT ${GLIB_ROOT_DIR} MODULES glib-2.0>=2.28)
IF(ENABLE_DKIM MATCHES "ON")
SET(WITH_DKIM 1)
ProcessPackage(OPENDKIM LIBRARY opendkim INCLUDE dkim.h
INCLUDE_SUFFIXES include/opendkim
LIB_SUFFIXES lib/opendkim lib64/opendkim
ROOT ${OPENDKIM_ROOT_DIR} MODULES opendkim)
ENDIF()
IF(ENABLE_MEMCACHED MATCHES "ON")
SET(WITH_MEMCACHED 1)
ProcessPackage(LIBMEMCACHED LIBRARY memcached
INCLUDE memcached.h INCLUDE_SUFFIXES include/libmemcached
LIB_SUFFIXES lib/libmemcached ROOT ${LIBMEMCACHED_ROOT_DIR}
MODULES libmemcached)
ENDIF()
################################ SOURCES SECTION ###########################
ADD_SUBDIRECTORY(hiredis)
INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/hiredis")
INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/contrib/lc-btrie")
INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/")
ADD_SUBDIRECTORY(contrib/libucl)
ADD_SUBDIRECTORY(contrib/http-parser)
ADD_SUBDIRECTORY(contrib/xxhash)
ADD_SUBDIRECTORY(contrib/lc-btrie)
ADD_SUBDIRECTORY(contrib/zstd)
SET(RMILTERSRC
compat/blake2b-ref.c
src/upstream.c
src/util.c
src/radix.c
src/cache.c
${CMAKE_BINARY_DIR}/cfg_lex.c
${CMAKE_BINARY_DIR}/cfg_yacc.c
src/cfg_file.c
src/libclamc.c
src/ratelimit.c
src/main.c
src/libspamd.c
src/greylist.c
src/rmilter.c)
LIST(APPEND RMILTER_REQUIRED_LIBRARIES m)
LIST(APPEND RMILTER_REQUIRED_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
CONFIGURE_FILE(config.h.in config.h)
ADD_EXECUTABLE(rmilter ${RMILTERSRC})
SET_TARGET_PROPERTIES(rmilter PROPERTIES LINKER_LANGUAGE C)
TARGET_LINK_LIBRARIES(rmilter ${RMILTER_REQUIRED_LIBRARIES})
TARGET_LINK_LIBRARIES(rmilter rmilter-hiredis)
TARGET_LINK_LIBRARIES(rmilter ucl)
TARGET_LINK_LIBRARIES(rmilter xxhash)
TARGET_LINK_LIBRARIES(rmilter rmilter-http-parser)
TARGET_LINK_LIBRARIES(rmilter lcbtrie)
TARGET_LINK_LIBRARIES(rmilter rmilter-zstd)
##################### INSTALLATION ##########################################
# Binaries
INSTALL(TARGETS rmilter RUNTIME DESTINATION ${SBINDIR})
ADD_CUSTOM_TARGET(dist ${CMAKE_SOURCE_DIR}/dist.sh
"${CMAKE_BINARY_DIR}/rmilter-${RMILTER_VERSION}.tar.xz" "${TAR}"
COMMENT "Create source distribution"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
# systemd unit
IF(WANT_SYSTEMD_UNITS MATCHES "ON")
INSTALL(FILES "rmilter.service" DESTINATION ${SYSTEMDDIR})
ENDIF()