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