xref: /lighttpd1.4/src/CMakeLists.txt (revision 3392e8fb)
1include(CheckCSourceCompiles)
2include(CheckIncludeFiles)
3include(CheckFunctionExists)
4include(CheckSymbolExists)
5include(CheckVariableExists)
6include(CheckTypeSize)
7include(CheckLibraryExists)
8include(CMakeDetermineCCompiler)
9include(FindThreads)
10include(FindPkgConfig)
11
12include(LighttpdMacros)
13
14add_definitions(-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGE_FILES)
15
16# default to ON
17set(CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "Default value for ``POSITION_INDEPENDENT_CODE`` of targets.")
18
19option(WITH_XATTR "with xattr-support for the stat-cache [default: off]")
20option(WITH_MYSQL "with mysql-support for mod_vhostdb_mysql [default: off]")
21option(WITH_PGSQL "with postgres-support for mod_vhostdb_pgsql [default: off]")
22option(WITH_DBI "with dbi-support for mod_vhostdb_dbi [default: off]")
23option(WITH_GNUTLS "with GnuTLS-support [default: off]")
24option(WITH_MBEDTLS "with mbedTLS-support [default: off]")
25option(WITH_NSS "with NSS-crypto-support [default: off]")
26option(WITH_OPENSSL "with openssl-support [default: off]")
27option(WITH_WOLFSSL "with wolfSSL-support [default: off]")
28option(WITH_NETTLE "with Nettle-support [default: off]")
29option(WITH_PCRE "with regex support [default: on]" ON)
30option(WITH_WEBDAV_PROPS "with property-support for mod_webdav [default: off]")
31option(WITH_WEBDAV_LOCKS "locks in webdav [default: off]")
32option(WITH_BROTLI "with brotli-support for mod_deflate [default: off]")
33option(WITH_BZIP "with bzip2-support for mod_deflate [default: off]")
34option(WITH_ZLIB "with deflate-support for mod_deflate [default: on]" ON)
35option(WITH_ZSTD "with zstd-support for mod_deflate [default: off]")
36option(WITH_KRB5 "with Kerberos5-support for mod_auth [default: off]")
37option(WITH_LDAP "with LDAP-support for mod_auth mod_vhostdb_ldap [default: off]")
38option(WITH_PAM "with PAM-support for mod_auth [default: off]")
39option(WITH_LUA "with lua 5.1 for mod_magnet [default: off]")
40# option(WITH_VALGRIND "with internal support for valgrind [default: off]")
41option(WITH_FAM "fam/gamin for reducing number of stat() calls [default: off]")
42option(WITH_GDBM "gdbm storage for mod_trigger_b4_dl [default: off]")
43option(WITH_MEMCACHED "memcached storage for mod_trigger_b4_dl [default: off]")
44option(WITH_LIBEV "libev support for fdevent handlers [default: off]")
45option(WITH_LIBUNWIND "with libunwind to print backtraces in asserts [default: off]")
46option(WITH_GEOIP "with GeoIP-support mod_geoip [default: off]")
47option(WITH_MAXMINDDB "with MaxMind GeoIP2-support mod_maxminddb [default: off]")
48option(WITH_SASL "with SASL-support for mod_authn_sasl [default: off]")
49option(WITH_XXHASH "with system-provided xxhash [default: off]")
50
51if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang")
52	option(BUILD_EXTRA_WARNINGS "extra warnings")
53
54	if(BUILD_EXTRA_WARNINGS)
55		set(WARN_CFLAGS "-g -g2 -Wall -Wmissing-declarations -Wcast-align -Wsign-compare -Wnested-externs -Wpointer-arith -D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security")
56		set(WARN_LDFLAGS "-Wl,--as-needed")
57		# -Werror -Wbad-function-cast -Wmissing-prototypes
58	endif()
59endif()
60
61option(BUILD_STATIC "build a static lighttpd with all modules added")
62
63if(BUILD_STATIC)
64	set(LIGHTTPD_STATIC 1)
65elseif(APPLE)
66	set(CMAKE_SHARED_MODULE_PREFIX "")
67else()
68	set(CMAKE_SHARED_LIBRARY_PREFIX "")
69endif()
70
71if(WITH_LIBEV)
72	find_package(LibEV REQUIRED)
73	set(HAVE_LIBEV 1)
74endif()
75
76if(WITH_LIBUNWIND)
77	pkg_check_modules(LIBUNWIND REQUIRED libunwind)
78	set(HAVE_LIBUNWIND 1)
79endif()
80
81if(WITH_WEBDAV_PROPS)
82	set(WITH_XML 1)
83	set(WITH_SQLITE3 1)
84endif()
85
86if(WITH_WEBDAV_LOCKS)
87	set(WITH_UUID 1)
88endif()
89
90check_include_files(sys/devpoll.h HAVE_SYS_DEVPOLL_H)
91check_include_files(sys/epoll.h HAVE_SYS_EPOLL_H)
92set(CMAKE_REQUIRED_FLAGS "-include sys/types.h")
93check_include_files(sys/event.h HAVE_SYS_EVENT_H)
94set(CMAKE_REQUIRED_FLAGS)
95check_include_files(sys/inotify.h HAVE_SYS_INOTIFY_H)
96check_include_files(sys/mman.h HAVE_SYS_MMAN_H)
97check_include_files(sys/loadavg.h HAVE_SYS_LOADAVG_H)
98check_include_files(sys/poll.h HAVE_SYS_POLL_H)
99check_include_files(sys/port.h HAVE_SYS_PORT_H)
100check_include_files(sys/prctl.h HAVE_SYS_PRCTL_H)
101check_include_files(sys/resource.h HAVE_SYS_RESOURCE_H)
102check_include_files(sys/sendfile.h HAVE_SYS_SENDFILE_H)
103check_include_files(sys/select.h HAVE_SYS_SELECT_H)
104check_include_files(sys/types.h HAVE_SYS_TYPES_H)
105check_include_files(sys/uio.h HAVE_SYS_UIO_H)
106check_include_files(sys/un.h HAVE_SYS_UN_H)
107check_include_files(sys/wait.h HAVE_SYS_WAIT_H)
108check_include_files(sys/time.h HAVE_SYS_TIME_H)
109check_include_files(unistd.h HAVE_UNISTD_H)
110check_include_files(pthread.h HAVE_PTHREAD_H)
111check_include_files(getopt.h HAVE_GETOPT_H)
112check_include_files(inttypes.h HAVE_INTTYPES_H)
113check_include_files(poll.h HAVE_POLL_H)
114check_include_files(pwd.h HAVE_PWD_H)
115check_include_files(stddef.h HAVE_STDDEF_H)
116check_include_files(stdint.h HAVE_STDINT_H)
117check_include_files(strings.h HAVE_STRINGS_H)
118check_include_files(syslog.h HAVE_SYSLOG_H)
119
120# will be needed for auth
121check_include_files(crypt.h HAVE_CRYPT_H)
122# check if we need libcrypt for crypt_r()
123check_library_exists(crypt crypt_r "" HAVE_LIBCRYPT_CRYPT_R)
124if(HAVE_LIBCRYPT_CRYPT_R)
125	set(HAVE_CRYPT_R 1)
126	set(HAVE_LIBCRYPT 1)
127else()
128	check_library_exists(crypt crypt "" HAVE_LIBCRYPT)
129endif()
130check_function_exists(crypt_r HAVE_CRYPT_R)
131check_function_exists(crypt HAVE_CRYPT)
132
133check_include_files(sys/inotify.h HAVE_SYS_INOTIFY_H)
134if(HAVE_SYS_INOTIFY_H)
135	check_function_exists(inotify_init HAVE_INOTIFY_INIT)
136endif()
137
138set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
139check_type_size(socklen_t HAVE_SOCKLEN_T)
140set(CMAKE_EXTRA_INCLUDE_FILES)
141
142check_include_files(sys/random.h HAVE_SYS_RANDOM_H)
143set(CMAKE_EXTRA_INCLUDE_FILES sys/random.h)
144check_function_exists(getentropy HAVE_GETENTROPY)
145set(CMAKE_EXTRA_INCLUDE_FILES)
146
147check_include_files(linux/random.h HAVE_LINUX_RANDOM_H)
148set(CMAKE_EXTRA_INCLUDE_FILES linux/random.h)
149check_function_exists(getrandom HAVE_GETRANDOM)
150set(CMAKE_EXTRA_INCLUDE_FILES)
151
152check_type_size(long SIZEOF_LONG)
153check_type_size(off_t SIZEOF_OFF_T)
154
155check_function_exists(arc4random_buf HAVE_ARC4RANDOM_BUF)
156check_function_exists(chroot HAVE_CHROOT)
157check_function_exists(copy_file_range HAVE_COPY_FILE_RANGE)
158check_function_exists(epoll_ctl HAVE_EPOLL_CTL)
159check_function_exists(fork HAVE_FORK)
160check_function_exists(getloadavg HAVE_GETLOADAVG)
161check_function_exists(getrlimit HAVE_GETRLIMIT)
162check_function_exists(getuid HAVE_GETUID)
163check_function_exists(gmtime_r HAVE_GMTIME_R)
164check_function_exists(inet_aton HAVE_INET_ATON)
165check_function_exists(inet_ntop HAVE_INET_NTOP)
166check_function_exists(jrand48 HAVE_JRAND48)
167check_function_exists(kqueue HAVE_KQUEUE)
168check_function_exists(localtime_r HAVE_LOCALTIME_R)
169check_function_exists(lstat HAVE_LSTAT)
170check_function_exists(madvise HAVE_MADVISE)
171check_function_exists(memcpy HAVE_MEMCPY)
172check_function_exists(mempcpy HAVE_MEMPCPY)
173check_function_exists(memset HAVE_MEMSET)
174check_function_exists(mmap HAVE_MMAP)
175check_function_exists(pathconf HAVE_PATHCONF)
176check_function_exists(pipe2 HAVE_PIPE2)
177check_function_exists(poll HAVE_POLL)
178check_function_exists(port_create HAVE_PORT_CREATE)
179check_function_exists(prctl HAVE_PRCTL)
180check_function_exists(pread HAVE_PREAD)
181check_function_exists(posix_fadvise HAVE_POSIX_FADVISE)
182check_function_exists(select HAVE_SELECT)
183check_function_exists(sendfile HAVE_SENDFILE)
184check_function_exists(send_file HAVE_SEND_FILE)
185check_function_exists(sendfile64 HAVE_SENDFILE64)
186check_function_exists(sendfilev HAVE_SENDFILEV)
187check_function_exists(sigaction HAVE_SIGACTION)
188check_function_exists(signal HAVE_SIGNAL)
189check_function_exists(sigtimedwait HAVE_SIGTIMEDWAIT)
190check_function_exists(srandom HAVE_SRANDOM)
191check_function_exists(strptime HAVE_STRPTIME)
192check_function_exists(syslog HAVE_SYSLOG)
193check_function_exists(timegm HAVE_TIMEGM)
194check_function_exists(writev HAVE_WRITEV)
195check_function_exists(inet_aton HAVE_INET_ATON)
196check_function_exists(issetugid HAVE_ISSETUGID)
197check_function_exists(inet_pton HAVE_INET_PTON)
198check_function_exists(memset_s HAVE_MEMSET_S)
199check_function_exists(explicit_bzero HAVE_EXPLICIT_BZERO)
200check_function_exists(explicit_memset HAVE_EXPLICIT_MEMSET)
201check_symbol_exists(clock_gettime "time.h" HAVE_CLOCK_GETTIME)
202if (NOT HAVE_CLOCK_GETTIME)
203	check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME)
204endif()
205check_library_exists(elftc elftc_copyfile "libelftc.h" HAVE_ELFTC_COPYFILE)
206check_c_source_compiles("
207	#include <sys/types.h>
208	#include <sys/socket.h>
209	#include <netinet/in.h>
210
211	int main() {
212		struct sockaddr_in6 s; struct in6_addr t=in6addr_any; int i=AF_INET6; s; t.s6_addr[0] = 0;
213		return 0;
214	}" HAVE_IPV6)
215check_c_source_compiles("
216	__attribute__((weak)) void __dummy(void *x) { }
217	int main() {
218		void *x;
219		__dummy(x);
220	}
221	" HAVE_WEAK_SYMBOLS)
222check_c_source_compiles("
223	#include <time.h>
224	int main(void) {
225		struct tm t;
226		t.tm_gmtoff = 0;
227		return 0;
228	}
229	" HAVE_STRUCT_TM_GMTOFF)
230
231## refactor me
232macro(XCONFIG _package _include_DIR _link_DIR _link_FLAGS _cflags)
233# reset the variables at the beginning
234	set(${_include_DIR})
235	set(${_link_DIR})
236	set(${_link_FLAGS})
237	set(${_cflags})
238
239	find_program(${_package}CONFIG_EXECUTABLE NAMES ${_package} PATHS /usr/local/bin )
240
241	# if pkg-config has been found
242	if(${_package}CONFIG_EXECUTABLE)
243		set(XCONFIG_EXECUTABLE "${${_package}CONFIG_EXECUTABLE}")
244		message(STATUS "found ${_package}: ${XCONFIG_EXECUTABLE}")
245
246		exec_program(${XCONFIG_EXECUTABLE} ARGS --libs OUTPUT_VARIABLE __link_FLAGS)
247		string(REPLACE "\n" "" ${_link_FLAGS} ${__link_FLAGS})
248		exec_program(${XCONFIG_EXECUTABLE} ARGS --cflags OUTPUT_VARIABLE __cflags)
249		string(REPLACE "\n" "" ${_cflags} ${__cflags})
250	else()
251		message(STATUS "found ${_package}: no")
252	endif()
253endmacro(XCONFIG _package _include_DIR _link_DIR _link_FLAGS _cflags)
254
255if(WITH_XATTR)
256	check_include_files("sys/types.h;sys/xattr.h" HAVE_SYS_XATTR_H)
257	check_function_exists(getxattr HAVE_XATTR)
258	check_include_files("sys/types.h;attr/attributes.h" HAVE_ATTR_ATTRIBUTES_H)
259	if(HAVE_ATTR_ATTRIBUTES_H)
260		check_library_exists(attr attr_get "" HAVE_XATTR)
261	endif()
262else()
263	unset(HAVE_ATTR_ATTRIBUTES_H)
264	unset(HAVE_XATTR)
265endif()
266
267if(WITH_MYSQL)
268	xconfig(mysql_config MYSQL_INCDIR MYSQL_LIBDIR MYSQL_LDFLAGS MYSQL_CFLAGS)
269
270	set(CMAKE_REQUIRED_INCLUDES /usr/include/mysql)
271	check_include_files(mysql.h HAVE_MYSQL_H)
272	set(CMAKE_REQUIRED_INCLUDES)
273	if(HAVE_MYSQL_H)
274		check_library_exists(mysqlclient mysql_real_connect "" HAVE_MYSQL)
275	endif()
276else()
277	unset(HAVE_MYSQL_H)
278	unset(HAVE_MYSQL)
279endif()
280
281if(WITH_PGSQL)
282	xconfig(pg_config PGSQL_INCDIR PGSQL_LIBDIR PGSQL_LDFLAGS PGSQL_CFLAGS)
283
284	check_include_files(libpq-fe.h HAVE_PGSQL_H)
285	if(HAVE_PGSQL_H)
286		check_library_exists(pq PQsetdbLogin "" HAVE_PGSQL)
287	endif()
288else()
289	unset(HAVE_PGSQL_H)
290	unset(HAVE_PGSQL)
291endif()
292
293if(WITH_DBI)
294	check_include_files(dbi/dbi.h HAVE_DBI_H)
295	if(HAVE_DBI_H)
296		check_library_exists(dbi dbi_conn_connect "" HAVE_DBI)
297	endif()
298else()
299	unset(HAVE_DBI_H)
300	unset(HAVE_DBI)
301endif()
302
303set(CRYPTO_LIBRARY "")
304
305if(WITH_OPENSSL)
306	if(APPLE)
307		set(CMAKE_REQUIRED_INCLUDES /opt/local/include)
308	endif()
309	check_include_files(openssl/ssl.h HAVE_OPENSSL_SSL_H)
310	if(APPLE)
311		set(CMAKE_REQUIRED_INCLUDES)
312	endif()
313	if(HAVE_OPENSSL_SSL_H)
314		check_library_exists(crypto BIO_f_base64 "" HAVE_LIBCRYPTO)
315		if(HAVE_LIBCRYPTO)
316			set(CRYPTO_LIBRARY crypto)
317			check_library_exists(ssl SSL_new "" HAVE_LIBSSL)
318			set(HAVE_OPENSSL 1)
319		endif()
320	endif()
321else()
322	unset(HAVE_OPENSSL_SSL_H)
323	unset(HAVE_LIBSSL)
324endif()
325
326if(WITH_WOLFSSL)
327	pkg_check_modules(WOLFSSL QUIET wolfssl)
328	if(NOT ${WITH_WOLFSSL} EQUAL "")
329		find_path(WOLFSSL_INCLUDE_DIR wolfssl/ssl.h ${WITH_WOLFSSL}/include)
330	elseif(WOLFSSL_FOUND)
331		set(WOLFSSL_INCLUDE_DIR ${WOLFSSL_INCLUDE_DIRS})
332	elseif(APPLE)
333		find_path(WOLFSSL_INCLUDE_DIR wolfssl/ssl.h /opt/local/include)
334	else()
335		find_path(WOLFSSL_INCLUDE_DIR wolfssl/ssl.h /usr/local/include)
336	endif()
337
338	if(NOT ${WITH_WOLFSSL} EQUAL "")
339		find_library(WOLFSSL_LIBRARY
340			NAMES wolfssl
341			PATHS ${WITH_WOLFSSL}/lib
342		)
343	elseif(WOLFSSL_FOUND)
344		set(WOLFSSL_LIBRARY ${WOLFSSL_LIBRARY_DIRS})
345	else()
346		find_library(WOLFSSL_LIBRARY
347			NAMES wolfssl
348			PATHS /usr/local/lib /opt/local/lib /usr/lib
349		)
350	endif()
351
352	if(WOLFSSL_INCLUDE_DIR AND WOLFSSL_LIBRARY)
353		set(CMAKE_REQUIRED_INCLUDES ${WOLFSSL_INCLUDE_DIR})
354		check_include_files(wolfssl/ssl.h HAVE_WOLFSSL_SSL_H)
355
356		check_c_source_compiles("
357		#include <wolfssl/options.h>
358		#if !defined(HAVE_LIGHTY) && !defined(OPENSSL_EXTRA)
359		#error HAVE_LIGHTY macro not defined
360		#endif
361		int main() { return 0; }
362		" CHECK_HAVE_LIGHTY)
363		if (NOT CHECK_HAVE_LIGHTY)
364			message(FATAL_ERROR "wolfssl must be built with ./configure --enable-lighty")
365		endif()
366		unset(CHECK_HAVE_LIGHTY)
367
368		set(CMAKE_REQUIRED_LIBRARIES ${WOLFSSL_LIBRARY})
369		check_library_exists(${WOLFSSL_LIBRARY} wolfSSL_Init "" HAVE_LIBWOLFSSL)
370		if(HAVE_LIBWOLFSSL)
371			set(CRYPTO_LIBRARY ${WOLFSSL_LIBRARY})
372			add_definitions(-DHAVE_WOLFSSL_SSL_H)
373			set(HAVE_WOLFSSL 1)
374		endif()
375		set(CMAKE_REQUIRED_INCLUDES)
376		set(CMAKE_REQUIRED_LIBRARIES)
377		include_directories(${WOLFSSL_INCLUDE_DIR} ${WOLFSSL_INCLUDE_DIR}/wolfssl)
378	endif()
379	unset(WOLFSSL_LIBRARY)
380	unset(WOLFSSL_INCLUDE_DIR)
381else()
382	unset(HAVE_WOLFSSL_SSL_H)
383endif()
384
385if(WITH_MBEDTLS)
386	check_include_files(mbedtls/ssl.h HAVE_MBEDTLS_SSL_H)
387	if(HAVE_MBEDTLS_SSL_H)
388		check_library_exists(mbedcrypto mbedtls_base64_encode "" HAVE_LIBMBEDCRYPTO)
389		if(HAVE_LIBMBEDCRYPTO)
390			add_definitions(-DHAVE_LIBMBEDCRYPTO)
391			set(CRYPTO_LIBRARY mbedcrypto)
392			check_library_exists(mbedtls mbedtls_cipher_info_from_type "" HAVE_LIBMBEDTLS)
393			if(HAVE_LIBMBEDTLS)
394			    check_library_exists(mbedx509 mbedtls_x509_get_name "" HAVE_LIBMBEDX509)
395			endif()
396		endif()
397	endif()
398else()
399	unset(HAVE_MBEDTLS_SSL_H)
400	unset(HAVE_LIBMBEDCRYPTO)
401	unset(HAVE_LIBMBEDTLS)
402	unset(HAVE_LIBMEDX509)
403endif()
404
405if(WITH_NSS)
406	check_include_files(nss/nss.h HAVE_NSS_NSS_H)
407	check_include_files(nss3/nss.h HAVE_NSS3_NSS_H)
408	if(HAVE_NSS3_NSS_H OR HAVE_NSS_NSS_H)
409		add_definitions(-DHAVE_NSS_NSS_H)
410		check_library_exists(ssl3 NSSSSL_GetVersion "" HAVE_LIBSSL3)
411		if(HAVE_LIBSSL3)
412		    check_library_exists(smime3 NSSSMIME_GetVersion "" HAVE_LIBSMIME3)
413			if(HAVE_LIBSMIME3)
414			    check_library_exists(nss3 NSS_GetVersion "" HAVE_LIBNSS3)
415			    if(HAVE_LIBNSS3)
416				check_library_exists(nssutil3 NSSUTIL_GetVersion "" HAVE_LIBNSSUTIL3)
417			    endif()
418			endif()
419		endif()
420	endif()
421else()
422	unset(HAVE_NSS_NSS_H)
423	unset(HAVE_NSS3_NSS_H)
424	unset(HAVE_LIBSSL3)
425	unset(HAVE_LIBSMIME3)
426	unset(HAVE_LIBNSS3)
427	unset(HAVE_LIBNSSUTIL3)
428endif()
429
430if(WITH_NETTLE)
431	if(APPLE)
432		set(CMAKE_REQUIRED_INCLUDES /opt/local/include)
433	endif()
434	check_include_files(nettle/nettle-types.h HAVE_NETTLE_NETTLE_TYPES_H)
435	if(APPLE)
436		set(CMAKE_REQUIRED_INCLUDES)
437	endif()
438	if(HAVE_NETTLE_NETTLE_TYPES_H)
439		add_definitions(-DHAVE_NETTLE_NETTLE_TYPES_H)
440		check_library_exists(nettle nettle_md5_init "" HAVE_LIBNETTLE)
441		if(HAVE_LIBNETTLE)
442			set(CRYPTO_LIBRARY nettle)
443		endif()
444	endif()
445else()
446	unset(HAVE_NETTLE_NETTLE_TYPES_H)
447endif()
448
449if(WITH_GNUTLS)
450	pkg_check_modules(LIBGNUTLS REQUIRED gnutls)
451	set(HAVE_LIBGNUTLS 1)
452	add_definitions(-DHAVE_GNUTLS_CRYPTO_H)
453	if(NOT WITH_OPENSSL AND NOT WITH_WOLFSSL AND NOT WITH_MBEDTLS AND NOT WITH_NETTLE)
454		set(CRYPTO_LIBRARY gnutls)
455	endif()
456endif()
457
458if(WITH_PCRE)
459	## if we have pcre-config, use it
460	xconfig(pcre-config PCRE_INCDIR PCRE_LIBDIR PCRE_LDFLAGS PCRE_CFLAGS)
461	if(PCRE_LDFLAGS OR PCRE_CFLAGS)
462		message(STATUS "found pcre at: LDFLAGS: ${PCRE_LDFLAGS} CFLAGS: ${PCRE_CFLAGS}")
463
464		if(NOT PCRE_CFLAGS STREQUAL "\n")
465			## if it is empty we'll get newline returned
466			set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PCRE_CFLAGS}")
467		endif()
468
469		set(HAVE_PCRE_H 1)
470		set(HAVE_LIBPCRE 1)
471	else()
472		if(NOT WIN32)
473			check_include_files(pcre.h HAVE_PCRE_H)
474			check_library_exists(pcre pcre_exec "" HAVE_LIBPCRE)
475			set(PCRE_LDFLAGS -lpcre)
476		else()
477			find_path(PCRE_INCLUDE_DIR pcre.h
478			/usr/local/include
479			/usr/include
480			)
481
482			set(PCRE_NAMES pcre)
483			find_library(PCRE_LIBRARY
484			NAMES ${PCRE_NAMES}
485			PATHS /usr/lib /usr/local/lib
486			)
487
488			if(PCRE_INCLUDE_DIR AND PCRE_LIBRARY)
489				set(CMAKE_REQUIRED_INCLUDES ${PCRE_INCLUDE_DIR})
490				set(CMAKE_REQUIRED_LIBRARIES ${PCRE_LIBRARY})
491				check_include_files(pcre.h HAVE_PCRE_H)
492				check_library_exists(pcre pcre_exec "" HAVE_LIBPCRE)
493				set(CMAKE_REQUIRED_INCLUDES)
494				set(CMAKE_REQUIRED_LIBRARIES)
495				include_directories(${PCRE_INCLUDE_DIR})
496			endif()
497		endif()
498	endif()
499
500	if(NOT HAVE_PCRE_H)
501		message(FATAL_ERROR "pcre.h couldn't be found")
502	endif()
503	if(NOT HAVE_LIBPCRE)
504		message(FATAL_ERROR "libpcre couldn't be found")
505	endif()
506else()
507	unset(HAVE_PCRE_H)
508	unset(HAVE_LIBPCRE)
509endif()
510
511if(WITH_SASL)
512	check_include_files(sasl/sasl.h HAVE_SASL_SASL_H)
513	if(HAVE_SASL_SASL_H)
514		check_library_exists(sasl2 sasl_server_init "" HAVE_SASL)
515	endif()
516else()
517	unset(HAVE_SASL_SASL_H)
518	unset(HAVE_SASL)
519endif()
520
521
522if(WITH_XML)
523	xconfig(xml2-config XML2_INCDIR XML2_LIBDIR XML2_LDFLAGS XML2_CFLAGS)
524	if(XML2_LDFLAGS OR XML2_CFLAGS)
525		message(STATUS "found xml2 at: LDFLAGS: ${XML2_LDFLAGS} CFLAGS: ${XML2_CFLAGS}")
526
527		## if it is empty we'll get newline returned
528		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${XML2_CFLAGS}")
529
530		check_include_files(libxml/tree.h HAVE_LIBXML_H)
531
532		set(CMAKE_REQUIRED_FLAGS ${XML2_LDFLAGS})
533		check_library_exists(xml2 xmlParseChunk "" HAVE_LIBXML)
534		set(CMAKE_REQUIRED_FLAGS)
535	else()
536		check_include_files(libxml.h HAVE_LIBXML_H)
537		check_library_exists(xml2 xmlParseChunk "" HAVE_LIBXML)
538	endif()
539
540	if(NOT HAVE_LIBXML_H)
541		message(FATAL_ERROR "libxml/tree.h couldn't be found")
542	endif()
543	if(NOT HAVE_LIBXML)
544		message(FATAL_ERROR "libxml2 couldn't be found")
545	endif()
546else()
547	unset(HAVE_LIBXML_H)
548	unset(HAVE_LIBXML)
549endif()
550
551if(WITH_SQLITE3)
552	check_include_files(sqlite3.h HAVE_SQLITE3_H)
553	check_library_exists(sqlite3 sqlite3_reset "" HAVE_SQLITE3)
554else()
555	unset(HAVE_SQLITE3_H)
556	unset(HAVE_SQLITE3)
557endif()
558
559if(WITH_UUID)
560	check_include_files(uuid/uuid.h HAVE_UUID_UUID_H)
561	check_library_exists(uuid uuid_generate "" NEED_LIBUUID)
562	if(NOT NEED_LIBUUID)
563		check_function_exists(uuid_generate HAVE_LIBUUID)
564	else()
565		set(HAVE_LIBUUID 1)
566	endif()
567else()
568	unset(HAVE_UUID_UUID_H)
569	unset(NEED_LIBUUID)
570	unset(HAVE_LIBUUID)
571endif()
572
573if(WITH_XXHASH)
574	check_include_files(xxhash.h HAVE_XXHASH_H)
575	check_library_exists(xxhash XXH_versionNumber "" HAVE_XXHASH)
576else()
577	unset(HAVE_XXHASH_H)
578	unset(HAVE_XXHASH)
579endif()
580
581if(WITH_ZLIB)
582	if(NOT WIN32)
583		check_include_files(zlib.h HAVE_ZLIB_H)
584		check_library_exists(z deflate "" HAVE_LIBZ)
585		set(ZLIB_LIBRARY z)
586	else()
587		find_path(ZLIB_INCLUDE_DIR zlib.h
588			/usr/local/include
589			/usr/include
590		)
591
592		set(ZLIB_NAMES z zlib zdll)
593			find_library(ZLIB_LIBRARY
594			NAMES ${ZLIB_NAMES}
595			PATHS /usr/lib /usr/local/lib
596		)
597
598		if(ZLIB_INCLUDE_DIR AND ZLIB_LIBRARY)
599			set(CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIR})
600			set(CMAKE_REQUIRED_LIBRARIES ${ZLIB_LIBRARY})
601			get_filename_component(ZLIB_NAME ${ZLIB_LIBRARY} NAME)
602			check_include_files(zlib.h HAVE_ZLIB_H)
603			check_library_exists(${ZLIB_NAME} deflate "" HAVE_LIBZ)
604			set(CMAKE_REQUIRED_INCLUDES)
605			set(CMAKE_REQUIRED_LIBRARIES)
606			include_directories(${ZLIB_INCLUDE_DIR})
607		endif()
608	endif()
609else()
610	unset(HAVE_ZLIB_H)
611	unset(HAVE_LIBZ)
612	unset(ZLIB_INCLUDE_DIR)
613	unset(ZLIB_LIBRARY)
614endif()
615
616if(WITH_ZSTD)
617	check_include_files(zstd.h HAVE_ZSTD_H)
618	check_library_exists(zstd ZSTD_versionNumber "" HAVE_ZSTD)
619else()
620	unset(HAVE_ZSTD_H)
621	unset(HAVE_ZSTD)
622endif()
623
624if(WITH_BZIP)
625	check_include_files(bzlib.h HAVE_BZLIB_H)
626	check_library_exists(bz2 BZ2_bzCompress "" HAVE_LIBBZ2)
627else()
628	unset(HAVE_BZLIB_H)
629	unset(HAVE_LIBBZ2)
630endif()
631
632if(WITH_BROTLI)
633	pkg_check_modules(LIBBROTLI REQUIRED libbrotlienc)
634	set(HAVE_BROTLI 1)
635	add_definitions(-DHAVE_BROTLI_ENCODE_H -DHAVE_BROTLI)
636else()
637	unset(HAVE_BROTLI)
638endif()
639
640if(WITH_LDAP)
641	check_include_files(ldap.h HAVE_LDAP_H)
642	check_library_exists(ldap ldap_bind "" HAVE_LIBLDAP)
643	check_include_files(lber.h HAVE_LBER_H)
644	check_library_exists(lber ber_printf "" HAVE_LIBLBER)
645else()
646	unset(HAVE_LDAP_H)
647	unset(HAVE_LIBLDAP)
648	unset(HAVE_LBER_H)
649	unset(HAVE_LIBLBER)
650endif()
651
652if(WITH_PAM)
653	check_include_files(security/pam_appl.h HAVE_SECURITY_PAM_APPL_H)
654	check_library_exists(pam pam_start "" HAVE_PAM)
655else()
656	unset(HAVE_SECURITY_PAM_APPL_H)
657	unset(HAVE_PAM)
658endif()
659
660if(WITH_LUA)
661	pkg_search_module(LUA REQUIRED lua5.4 lua-5.4 lua5.3 lua-5.3 lua5.2 lua-5.2 lua5.1 lua-5.1 lua)
662	message(STATUS "found lua at: INCDIR: ${LUA_INCLUDE_DIRS} LIBDIR: ${LUA_LIBRARY_DIRS} LDFLAGS: ${LUA_LDFLAGS} CFLAGS: ${LUA_CFLAGS}")
663	set(HAVE_LIBLUA 1 "Have liblua")
664	set(HAVE_LUA_H  1 "Have liblua header")
665else()
666	unset(HAVE_LIBLUA)
667	unset(HAVE_LUA_H)
668endif()
669
670if(WITH_FAM AND NOT HAVE_SYS_INOTIFY_H)
671	check_include_files(fam.h HAVE_FAM_H)
672	check_library_exists(fam FAMOpen2 "" HAVE_LIBFAM)
673	if(HAVE_LIBFAM)
674		set(CMAKE_REQUIRED_LIBRARIES fam)
675		check_function_exists(FAMNoExists HAVE_FAMNOEXISTS)
676	endif()
677else()
678	unset(HAVE_FAM_H)
679	unset(HAVE_LIBFAM)
680	unset(HAVE_FAMNOEXISTS)
681endif()
682
683if(WITH_GDBM)
684	check_include_files(gdbm.h HAVE_GDBM_H)
685	check_library_exists(gdbm gdbm_open "" HAVE_GDBM)
686else()
687	unset(HAVE_GDBM_H)
688	unset(HAVE_GDBM)
689endif()
690
691if(WITH_MEMCACHED)
692	check_include_files(libmemcached/memcached.h HAVE_LIBMEMCACHED_MEMCACHED_H)
693	check_library_exists(memcached memcached "" HAVE_LIBMEMCACHED)
694	if(HAVE_LIBMEMCACHED_MEMCACHED_H AND HAVE_LIBMEMCACHED)
695		set(USE_MEMCACHED 1)
696	else()
697		message(FATAL_ERROR "didn't find libmemcached")
698	endif()
699endif()
700
701if(WITH_GEOIP)
702	check_library_exists(geoip GeoIP_country_name_by_addr "" HAVE_GEOIP)
703endif()
704
705if(WITH_MAXMINDDB)
706	check_library_exists(maxminddb MMDB_open "" HAVE_MAXMINDDB)
707endif()
708
709if(NOT BUILD_STATIC)
710	check_include_files(dlfcn.h HAVE_DLFCN_H)
711else()
712	unset(HAVE_DLFCN_H)
713endif()
714
715if(HAVE_DLFCN_H)
716	check_library_exists(dl dlopen "" HAVE_LIBDL)
717else()
718	unset(HAVE_LIBDL)
719endif()
720
721set(LIGHTTPD_VERSION_ID 10400)
722set(PACKAGE_NAME "${CMAKE_PROJECT_NAME}")
723set(PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}")
724
725if(NOT SBINDIR)
726	set(SBINDIR "sbin")
727endif()
728
729if(NOT LIGHTTPD_MODULES_DIR)
730	set(LIGHTTPD_MODULES_DIR "lib${LIB_SUFFIX}/lighttpd")
731endif()
732
733if(NOT WIN32)
734	set(LIGHTTPD_LIBRARY_DIR "${CMAKE_INSTALL_PREFIX}/${LIGHTTPD_MODULES_DIR}")
735else()
736	## We use relative path in windows
737	set(LIGHTTPD_LIBRARY_DIR "lib")
738endif()
739
740## Write out config.h
741configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
742
743add_definitions(-DHAVE_CONFIG_H)
744
745include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
746
747set(COMMON_SRC
748	base64.c buffer.c burl.c log.c
749	http_header.c http_kv.c keyvalue.c chunk.c
750	http_chunk.c fdevent.c gw_backend.c
751	stat_cache.c plugin.c http_etag.c array.c
752	data_string.c data_array.c
753	data_integer.c
754	algo_hmac.c algo_md5.c algo_sha1.c algo_splaytree.c
755	fdevent_select.c fdevent_libev.c
756	fdevent_poll.c fdevent_linux_sysepoll.c
757	fdevent_solaris_devpoll.c fdevent_solaris_port.c
758	fdevent_freebsd_kqueue.c
759	connections-glue.c
760	configfile-glue.c
761	http-header-glue.c
762	http_auth.c
763	http_cgi.c
764	http_date.c
765	http_vhostdb.c
766	request.c
767	sock_addr.c
768	rand.c
769	safe_memclear.c
770)
771
772if(WIN32)
773	message(STATUS "Adding local getopt implementation.")
774	set(COMMON_SRC ${COMMON_SRC} xgetopt.c)
775endif()
776
777add_executable(lemon lemon.c)
778
779## Build parsers by using lemon...
780lemon_parser(configparser.y)
781lemon_parser(mod_ssi_exprparser.y)
782
783set(L_INSTALL_TARGETS)
784
785add_executable(lighttpd-angel lighttpd-angel.c)
786set(L_INSTALL_TARGETS ${L_INSTALL_TARGETS} lighttpd-angel)
787add_target_properties(lighttpd-angel COMPILE_FLAGS "-DSBIN_DIR=\\\\\"${CMAKE_INSTALL_PREFIX}/${SBINDIR}\\\\\"")
788
789add_executable(lighttpd
790	server.c
791	response.c
792	connections.c
793	h2.c
794	reqpool.c
795	sock_addr_cache.c
796	ls-hpack/lshpack.c
797	algo_xxhash.c
798	http_range.c
799	network.c
800	network_write.c
801	data_config.c
802	vector.c
803	configfile.c
804	configparser.c
805	${COMMON_SRC}
806)
807set(L_INSTALL_TARGETS ${L_INSTALL_TARGETS} lighttpd)
808
809add_and_install_library(mod_access mod_access.c)
810add_and_install_library(mod_accesslog mod_accesslog.c)
811add_and_install_library(mod_ajp13 mod_ajp13.c)
812add_and_install_library(mod_alias mod_alias.c)
813add_and_install_library(mod_auth "mod_auth.c")
814add_and_install_library(mod_authn_file "mod_authn_file.c")
815if(NOT WIN32)
816	add_and_install_library(mod_cgi mod_cgi.c)
817endif()
818add_and_install_library(mod_deflate mod_deflate.c)
819add_and_install_library(mod_dirlisting mod_dirlisting.c)
820add_and_install_library(mod_evasive mod_evasive.c)
821add_and_install_library(mod_evhost mod_evhost.c)
822add_and_install_library(mod_expire mod_expire.c)
823add_and_install_library(mod_extforward mod_extforward.c)
824add_and_install_library(mod_fastcgi mod_fastcgi.c)
825add_and_install_library(mod_flv_streaming mod_flv_streaming.c)
826add_and_install_library(mod_indexfile mod_indexfile.c)
827add_and_install_library(mod_proxy mod_proxy.c)
828add_and_install_library(mod_redirect mod_redirect.c)
829add_and_install_library(mod_rewrite mod_rewrite.c)
830add_and_install_library(mod_rrdtool mod_rrdtool.c)
831add_and_install_library(mod_scgi mod_scgi.c)
832add_and_install_library(mod_secdownload mod_secdownload.c)
833add_and_install_library(mod_setenv mod_setenv.c)
834add_and_install_library(mod_simple_vhost mod_simple_vhost.c)
835add_and_install_library(mod_sockproxy mod_sockproxy.c)
836add_and_install_library(mod_ssi "mod_ssi_exprparser.c;mod_ssi_expr.c;mod_ssi.c")
837add_and_install_library(mod_staticfile mod_staticfile.c)
838add_and_install_library(mod_status mod_status.c)
839add_and_install_library(mod_uploadprogress mod_uploadprogress.c)
840add_and_install_library(mod_userdir mod_userdir.c)
841add_and_install_library(mod_usertrack mod_usertrack.c)
842add_and_install_library(mod_vhostdb mod_vhostdb.c)
843add_and_install_library(mod_webdav mod_webdav.c)
844add_and_install_library(mod_wstunnel mod_wstunnel.c)
845
846add_executable(test_array
847	t/test_array.c
848	array.c
849	data_array.c
850	data_integer.c
851	data_string.c
852	buffer.c
853)
854add_test(NAME test_array COMMAND test_array)
855
856add_executable(test_buffer
857	t/test_buffer.c
858	buffer.c
859)
860add_test(NAME test_buffer COMMAND test_buffer)
861
862add_executable(test_burl
863	t/test_burl.c
864	burl.c
865	buffer.c
866	base64.c
867)
868add_test(NAME test_burl COMMAND test_burl)
869
870add_executable(test_base64
871	t/test_base64.c
872	buffer.c
873	base64.c
874)
875add_test(NAME test_base64 COMMAND test_base64)
876
877add_executable(test_configfile
878	t/test_configfile.c
879	buffer.c
880	array.c
881	data_config.c
882	data_integer.c
883	data_string.c
884	http_header.c
885	http_kv.c
886	vector.c
887	log.c
888	sock_addr.c
889)
890add_test(NAME test_configfile COMMAND test_configfile)
891
892add_executable(test_keyvalue
893	t/test_keyvalue.c
894	burl.c
895	buffer.c
896	base64.c
897	array.c
898	data_integer.c
899	data_string.c
900	log.c
901)
902add_test(NAME test_keyvalue COMMAND test_keyvalue)
903
904add_executable(test_mod_access
905	t/test_mod_access.c
906	buffer.c
907	array.c
908	data_integer.c
909	data_string.c
910	log.c
911)
912add_test(NAME test_mod_access COMMAND test_mod_access)
913
914add_executable(test_mod_evhost
915	t/test_mod_evhost.c
916	buffer.c
917	array.c
918	data_integer.c
919	data_string.c
920	log.c
921)
922add_test(NAME test_mod_evhost COMMAND test_mod_evhost)
923
924add_executable(test_mod_simple_vhost
925	t/test_mod_simple_vhost.c
926	buffer.c
927	array.c
928	data_integer.c
929	data_string.c
930	log.c
931)
932add_test(NAME test_mod_simple_vhost COMMAND test_mod_simple_vhost)
933
934add_executable(test_mod_userdir
935	t/test_mod_userdir.c
936	buffer.c
937	array.c
938	data_integer.c
939	data_string.c
940	log.c
941)
942add_test(NAME test_mod_userdir COMMAND test_mod_userdir)
943
944add_executable(test_request
945	t/test_request.c
946	base64.c
947	buffer.c
948	burl.c
949	array.c
950	data_integer.c
951	data_string.c
952	http_header.c
953	http_kv.c
954	log.c
955	sock_addr.c
956)
957add_test(NAME test_request COMMAND test_request)
958
959if(HAVE_PCRE_H)
960	target_link_libraries(lighttpd ${PCRE_LDFLAGS})
961	add_target_properties(lighttpd COMPILE_FLAGS ${PCRE_CFLAGS})
962	target_link_libraries(test_configfile ${PCRE_LDFLAGS})
963	add_target_properties(test_configfile COMPILE_FLAGS ${PCRE_CFLAGS})
964	target_link_libraries(test_keyvalue ${PCRE_LDFLAGS})
965	add_target_properties(test_keyvalue COMPILE_FLAGS ${PCRE_CFLAGS})
966endif()
967
968if(WITH_PCRE AND (WITH_MEMCACHED OR WITH_GDBM))
969	add_and_install_library(mod_trigger_b4_dl mod_trigger_b4_dl.c)
970endif()
971
972if(WITH_LUA)
973	add_and_install_library(mod_magnet "mod_magnet.c;mod_magnet_cache.c")
974	target_link_libraries(mod_magnet ${LUA_LDFLAGS})
975	add_target_properties(mod_magnet COMPILE_FLAGS ${LUA_CFLAGS})
976
977	add_and_install_library(mod_cml "mod_cml.c;mod_cml_lua.c;mod_cml_funcs.c")
978	target_link_libraries(mod_cml ${LUA_LDFLAGS} ${CRYPTO_LIBRARY})
979	add_target_properties(mod_cml COMPILE_FLAGS ${LUA_CFLAGS})
980	if(WITH_MEMCACHED)
981		target_link_libraries(mod_cml memcached)
982	endif()
983endif()
984
985if(WITH_GEOIP)
986	add_and_install_library(mod_geoip mod_geoip.c)
987	target_link_libraries(mod_geoip GeoIP)
988endif()
989
990if(WITH_MAXMINDDB)
991	add_and_install_library(mod_maxminddb mod_maxminddb.c)
992	target_link_libraries(mod_maxminddb maxminddb)
993endif()
994
995if(HAVE_MYSQL_H AND HAVE_MYSQL)
996	add_and_install_library(mod_mysql_vhost "mod_mysql_vhost.c")
997	target_link_libraries(mod_mysql_vhost mysqlclient)
998	add_and_install_library(mod_vhostdb_mysql "mod_vhostdb_mysql.c")
999	target_link_libraries(mod_vhostdb_mysql mysqlclient)
1000	include_directories(/usr/include/mysql)
1001
1002	add_and_install_library(mod_authn_mysql "mod_authn_mysql.c")
1003	set(L_MOD_AUTHN_MYSQL ${CRYPTO_LIBRARY})
1004	if(HAVE_LIBCRYPT)
1005		set(L_MOD_AUTHN_MYSQL ${L_MOD_AUTHN_MYSQL} crypt)
1006	endif()
1007	target_link_libraries(mod_authn_mysql ${L_MOD_AUTHN_MYSQL} mysqlclient)
1008endif()
1009
1010if(HAVE_PGSQL_H AND HAVE_PGSQL)
1011	add_and_install_library(mod_vhostdb_pgsql "mod_vhostdb_pgsql.c")
1012	target_link_libraries(mod_vhostdb_pgsql pq)
1013endif()
1014
1015if(HAVE_DBI_H AND HAVE_DBI)
1016	add_and_install_library(mod_vhostdb_dbi "mod_vhostdb_dbi.c")
1017	target_link_libraries(mod_vhostdb_dbi dbi)
1018
1019	add_and_install_library(mod_authn_dbi "mod_authn_dbi.c")
1020	set(L_MOD_AUTHN_DBI ${CRYPTO_LIBRARY})
1021	if(HAVE_LIBCRYPT)
1022		set(L_MOD_AUTHN_DBI ${L_MOD_AUTHN_DBI} crypt)
1023	endif()
1024	target_link_libraries(mod_authn_dbi ${L_MOD_AUTHN_DBI} dbi)
1025endif()
1026
1027set(L_MOD_WEBDAV)
1028if(HAVE_SQLITE3_H)
1029	set(L_MOD_WEBDAV ${L_MOD_WEBDAV} sqlite3)
1030endif()
1031if(HAVE_LIBXML_H)
1032	target_link_libraries(mod_webdav ${XML2_LDFLAGS})
1033endif()
1034if(HAVE_UUID_UUID_H)
1035	if(NEED_LIBUUID)
1036		set(L_MOD_WEBDAV ${L_MOD_WEBDAV} uuid)
1037	endif()
1038endif()
1039
1040target_link_libraries(mod_webdav ${L_MOD_WEBDAV})
1041
1042set(L_MOD_AUTHN_FILE)
1043if(HAVE_LIBCRYPT)
1044	set(L_MOD_AUTHN_FILE ${L_MOD_AUTHN_FILE} crypt)
1045endif()
1046target_link_libraries(mod_authn_file ${L_MOD_AUTHN_FILE})
1047
1048if(WITH_KRB5)
1049	check_library_exists(krb5 krb5_init_context "" HAVE_KRB5)
1050	add_and_install_library(mod_authn_gssapi "mod_authn_gssapi.c")
1051	set(L_MOD_AUTHN_GSSAPI ${L_MOD_AUTHN_GSSAPI} krb5 gssapi_krb5)
1052	target_link_libraries(mod_authn_gssapi ${L_MOD_AUTHN_GSSAPI})
1053endif()
1054
1055if(WITH_LDAP)
1056	set(L_MOD_AUTHN_LDAP ${L_MOD_AUTHN_LDAP} ldap lber)
1057	add_and_install_library(mod_authn_ldap "mod_authn_ldap.c")
1058	target_link_libraries(mod_authn_ldap ${L_MOD_AUTHN_LDAP})
1059	add_and_install_library(mod_vhostdb_ldap "mod_vhostdb_ldap.c")
1060	target_link_libraries(mod_vhostdb_ldap ${L_MOD_AUTHN_LDAP})
1061endif()
1062
1063if(WITH_PAM)
1064	add_and_install_library(mod_authn_pam "mod_authn_pam.c")
1065	set(L_MOD_AUTHN_PAM ${L_MOD_AUTHN_PAM} pam)
1066	target_link_libraries(mod_authn_pam ${L_MOD_AUTHN_PAM})
1067endif()
1068
1069if(WITH_SASL)
1070	add_and_install_library(mod_authn_sasl "mod_authn_sasl.c")
1071	set(L_MOD_AUTHN_SASL ${L_MOD_AUTHN_SASL} sasl2)
1072	target_link_libraries(mod_authn_sasl ${L_MOD_AUTHN_SASL})
1073endif()
1074
1075if(HAVE_ZLIB_H OR HAVE_ZSTD_H OR HAVE_BZLIB_H OR HAVE_BROTLI)
1076	if(HAVE_ZLIB_H)
1077		set(L_MOD_DEFLATE ${L_MOD_DEFLATE} ${ZLIB_LIBRARY})
1078	endif()
1079	if(HAVE_ZSTD_H)
1080		set(L_MOD_DEFLATE ${L_MOD_DEFLATE} zstd)
1081	endif()
1082	if(HAVE_BZLIB_H)
1083		set(L_MOD_DEFLATE ${L_MOD_DEFLATE} bz2)
1084	endif()
1085	if(HAVE_BROTLI)
1086		set(L_MOD_DEFLATE ${L_MOD_DEFLATE} brotlienc)
1087	endif()
1088	target_link_libraries(mod_deflate ${L_MOD_DEFLATE})
1089endif()
1090
1091if(HAVE_LIBFAM)
1092	target_link_libraries(lighttpd fam)
1093endif()
1094
1095if(HAVE_GDBM_H)
1096	target_link_libraries(mod_trigger_b4_dl gdbm)
1097endif()
1098
1099if(WITH_MEMCACHED)
1100	target_link_libraries(mod_trigger_b4_dl memcached)
1101endif()
1102
1103if(HAVE_XATTR)
1104	target_link_libraries(lighttpd attr)
1105endif()
1106
1107if(HAVE_XXHASH)
1108	target_link_libraries(lighttpd xxhash)
1109endif()
1110
1111if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang")
1112	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -pipe -Wall -g -Wshadow -W -pedantic ${WARN_CFLAGS}")
1113	set(CMAKE_C_FLAGS_RELEASE        "${CMAKE_C_FLAGS_RELEASE}     -O2")
1114	set(CMAKE_C_FLAGS_DEBUG          "${CMAKE_C_FLAGS_DEBUG}       -O0")
1115	set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_WITHDEBINFO} -O2")
1116	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${WARN_LDFLAGS}")
1117	set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${WARN_LDFLAGS}")
1118endif()
1119
1120if((NOT APPLE) OR CMAKE_C_COMPILER_ID MATCHES "GNU")
1121	add_target_properties(lighttpd LINK_FLAGS "-Wl,-export-dynamic")
1122endif()
1123
1124set_target_properties(lighttpd PROPERTIES CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
1125
1126if(WIN32)
1127	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNVALGRIND")
1128	add_target_properties(lighttpd COMPILE_FLAGS "-DLI_DECLARE_EXPORTS")
1129	target_link_libraries(lighttpd ws2_32)
1130	target_link_libraries(mod_proxy ws2_32)
1131	target_link_libraries(mod_fcgi ws2_32)
1132	target_link_libraries(mod_scgi ws2_32)
1133	target_link_libraries(mod_ssi ws2_32)
1134
1135	if(MINGW)
1136		target_link_libraries(lighttpd msvcr70)
1137		add_target_properties(lighttpd LINK_FLAGS "-Wl,-subsystem,console")
1138	endif()
1139endif()
1140
1141if(NOT BUILD_STATIC)
1142	if(HAVE_LIBDL)
1143		target_link_libraries(lighttpd dl)
1144	endif()
1145endif()
1146
1147if(NOT ${CRYPTO_LIBRARY} EQUAL "")
1148	target_link_libraries(lighttpd ${CRYPTO_LIBRARY})
1149	target_link_libraries(mod_auth ${CRYPTO_LIBRARY})
1150	set(L_MOD_AUTHN_FILE ${L_MOD_AUTHN_FILE} ${CRYPTO_LIBRARY})
1151	target_link_libraries(mod_authn_file ${L_MOD_AUTHN_FILE})
1152	target_link_libraries(mod_secdownload ${CRYPTO_LIBRARY})
1153	target_link_libraries(mod_usertrack ${CRYPTO_LIBRARY})
1154	target_link_libraries(mod_wstunnel ${CRYPTO_LIBRARY})
1155endif()
1156
1157if(HAVE_OPENSSL)
1158	add_and_install_library(mod_openssl "mod_openssl.c")
1159	set(L_MOD_OPENSSL ${L_MOD_OPENSSL} ssl crypto)
1160	target_link_libraries(mod_openssl ${L_MOD_OPENSSL})
1161endif()
1162
1163if(HAVE_WOLFSSL)
1164	add_and_install_library(mod_wolfssl "mod_wolfssl.c")
1165	target_link_libraries(mod_wolfssl wolfssl)
1166endif()
1167
1168if(HAVE_LIBGNUTLS)
1169	add_and_install_library(mod_gnutls "mod_gnutls.c")
1170	target_link_libraries(mod_gnutls gnutls)
1171endif()
1172
1173if(HAVE_LIBMBEDTLS AND HAVE_LIBMEDCRYPTO AND HAVE_LIBMEDX509)
1174	add_and_install_library(mod_mbedtls "mod_mbedtls.c")
1175	set(L_MOD_MBEDTLS ${L_MOD_MBEDTLS} mbedtls mbedcrypto mbedx509)
1176	target_link_libraries(mod_mbedtls ${L_MOD_MBEDTLS})
1177	# not doing "cross module" linkage yet (e.g. mod_authn, secdownload)
1178endif()
1179
1180if(HAVE_LIBSSL3 AND HAVE_LIBSMIME3 AND HAVE_LIBNSS3 AND HAVE_LIBNSSUTIL3)
1181	add_and_install_library(mod_nss "mod_nss.c")
1182	set(L_MOD_NSS ${L_MOD_NSS} ssl3 smime3 nss3 nssutil3)
1183	target_link_libraries(mod_nss ${L_MOD_NSS})
1184endif()
1185
1186if(WITH_LIBEV)
1187	target_link_libraries(lighttpd ${LIBEV_LDFLAGS})
1188	add_target_properties(lighttpd COMPILE_FLAGS ${LIBEV_CFLAGS})
1189endif()
1190
1191if(WITH_LIBUNWIND)
1192	target_link_libraries(lighttpd ${LIBUNWIND_LDFLAGS})
1193	add_target_properties(lighttpd COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
1194
1195	target_link_libraries(test_array ${LIBUNWIND_LDFLAGS})
1196	add_target_properties(test_array COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
1197	target_link_libraries(test_buffer ${LIBUNWIND_LDFLAGS})
1198	add_target_properties(test_buffer COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
1199	target_link_libraries(test_burl ${LIBUNWIND_LDFLAGS})
1200	add_target_properties(test_burl COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
1201	target_link_libraries(test_base64 ${LIBUNWIND_LDFLAGS})
1202	add_target_properties(test_base64 COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
1203	target_link_libraries(test_configfile ${PCRE_LDFLAGS} ${LIBUNWIND_LDFLAGS})
1204	add_target_properties(test_configfile COMPILE_FLAGS ${PCRE_CFLAGS} ${LIBUNWIND_CFLAGS})
1205	target_link_libraries(test_keyvalue ${PCRE_LDFLAGS} ${LIBUNWIND_LDFLAGS})
1206	add_target_properties(test_keyvalue COMPILE_FLAGS ${PCRE_CFLAGS} ${LIBUNWIND_CFLAGS})
1207	target_link_libraries(test_mod_access ${LIBUNWIND_LDFLAGS})
1208	add_target_properties(test_mod_access COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
1209	target_link_libraries(test_mod_evhost ${LIBUNWIND_LDFLAGS})
1210	add_target_properties(test_mod_evhost COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
1211	target_link_libraries(test_mod_simple_vhost ${LIBUNWIND_LDFLAGS})
1212	add_target_properties(test_mod_simple_vhost COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
1213	target_link_libraries(test_mod_userdir ${LIBUNWIND_LDFLAGS})
1214	add_target_properties(test_mod_userdir COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
1215	target_link_libraries(test_request ${LIBUNWIND_LDFLAGS})
1216	add_target_properties(test_request COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
1217endif()
1218
1219if(NOT WIN32)
1220install(TARGETS ${L_INSTALL_TARGETS}
1221	RUNTIME DESTINATION ${SBINDIR}
1222	LIBRARY DESTINATION ${LIGHTTPD_MODULES_DIR}
1223	ARCHIVE DESTINATION ${LIGHTTPD_MODULES_DIR}/static)
1224else()
1225## HACK to make win32 to install our libraries in desired directory..
1226install(TARGETS lighttpd
1227	RUNTIME DESTINATION ${SBINDIR}
1228	ARCHIVE DESTINATION lib/static)
1229list(REMOVE_ITEM L_INSTALL_TARGETS lighttpd)
1230install(TARGETS ${L_INSTALL_TARGETS}
1231	RUNTIME DESTINATION ${SBINDIR}/lib
1232	LIBRARY DESTINATION lib
1233	ARCHIVE DESTINATION lib/static)
1234endif()
1235