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