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