[core] consolidate backend network write handlers
[lighttpd.git] / src / CMakeLists.txt
blobf285f836b76acefb9b46386fd7231f0b1f616a8d
1 include(CheckCSourceCompiles)
2 include(CheckIncludeFiles)
3 include(CheckFunctionExists)
4 include(CheckSymbolExists)
5 include(CheckVariableExists)
6 include(CheckTypeSize)
7 include(CheckLibraryExists)
8 include(CMakeDetermineCCompiler)
9 include(FindThreads)
10 include(FindPkgConfig)
12 include(LighttpdMacros)
14 add_definitions(-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGE_FILES)
16 option(WITH_XATTR "with xattr-support for the stat-cache [default: off]")
17 option(WITH_MYSQL "with mysql-support for mod_vhostdb_mysql [default: off]")
18 option(WITH_PGSQL "with postgres-support for mod_vhostdb_pgsql [default: off]")
19 option(WITH_DBI "with dbi-support for mod_vhostdb_dbi [default: off]")
20 option(WITH_OPENSSL "with openssl-support [default: off]")
21 option(WITH_PCRE "with regex support [default: on]" ON)
22 option(WITH_WEBDAV_PROPS "with property-support for mod_webdav [default: off]")
23 option(WITH_WEBDAV_LOCKS "locks in webdav [default: off]")
24 option(WITH_BZIP "with bzip2-support for mod_compress [default: off]")
25 option(WITH_ZLIB "with deflate-support for mod_compress [default: on]" ON)
26 option(WITH_KRB5 "with Kerberos5-support for mod_auth [default: off]")
27 option(WITH_LDAP "with LDAP-support for mod_auth mod_vhostdb_ldap [default: off]")
28 option(WITH_LUA "with lua 5.1 for mod_magnet [default: off]")
29 # option(WITH_VALGRIND "with internal support for valgrind [default: off]")
30 option(WITH_FAM "fam/gamin for reducing number of stat() calls [default: off]")
31 option(WITH_GDBM "gdbm storage for mod_trigger_b4_dl [default: off]")
32 option(WITH_MEMCACHED "memcached storage for mod_trigger_b4_dl [default: off]")
33 option(WITH_LIBEV "libev support for fdevent handlers [default: off]")
34 option(WITH_LIBUNWIND "with libunwind to print backtraces in asserts [default: off]")
35 option(WITH_GEOIP "with GeoIP-support mod_geoip [default: off]")
37 if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang")
38         option(BUILD_EXTRA_WARNINGS "extra warnings")
40         if(BUILD_EXTRA_WARNINGS)
41                 set(WARN_CFLAGS "-g -g2 -Wall -Wmissing-declarations -Wdeclaration-after-statement -Wcast-align -Wsign-compare -Wnested-externs -Wpointer-arith -D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security")
42                 set(WARN_LDFLAGS "-Wl,--as-needed")
43                 # -Werror -Wbad-function-cast -Wmissing-prototypes
44         endif()
45 endif()
47 option(BUILD_STATIC "build a static lighttpd with all modules added")
49 if(BUILD_STATIC)
50         set(LIGHTTPD_STATIC 1)
51 elseif(APPLE)
52         set(CMAKE_SHARED_MODULE_PREFIX "")
53 else()
54         set(CMAKE_SHARED_LIBRARY_PREFIX "")
55 endif()
57 if(WITH_LIBEV)
58         find_package(LibEV REQUIRED)
59         set(HAVE_LIBEV 1)
60 endif()
62 if(WITH_LIBUNWIND)
63         pkg_check_modules(LIBUNWIND REQUIRED libunwind)
64         set(HAVE_LIBUNWIND 1)
65 endif()
67 if(WITH_WEBDAV_PROPS)
68         set(WITH_XML 1)
69         set(WITH_SQLITE3 1)
70 endif()
72 if(WITH_WEBDAV_LOCKS)
73         set(WITH_UUID 1)
74 endif()
76 check_include_files(sys/devpoll.h HAVE_SYS_DEVPOLL_H)
77 check_include_files(sys/epoll.h HAVE_SYS_EPOLL_H)
78 check_include_files(sys/event.h HAVE_SYS_EVENT_H)
79 check_include_files(sys/mman.h HAVE_SYS_MMAN_H)
80 check_include_files(sys/poll.h HAVE_SYS_POLL_H)
81 check_include_files(sys/port.h HAVE_SYS_PORT_H)
82 check_include_files(sys/prctl.h HAVE_SYS_PRCTL_H)
83 check_include_files(sys/resource.h HAVE_SYS_RESOURCE_H)
84 check_include_files(sys/sendfile.h HAVE_SYS_SENDFILE_H)
85 check_include_files(sys/select.h HAVE_SYS_SELECT_H)
86 check_include_files(sys/types.h HAVE_SYS_TYPES_H)
87 check_include_files(sys/uio.h HAVE_SYS_UIO_H)
88 check_include_files(sys/un.h HAVE_SYS_UN_H)
89 check_include_files(sys/wait.h HAVE_SYS_WAIT_H)
90 check_include_files(sys/time.h HAVE_SYS_TIME_H)
91 check_include_files(unistd.h HAVE_UNISTD_H)
92 check_include_files(pthread.h HAVE_PTHREAD_H)
93 check_include_files(getopt.h HAVE_GETOPT_H)
94 check_include_files(inttypes.h HAVE_INTTYPES_H)
95 check_include_files(poll.h HAVE_POLL_H)
96 check_include_files(pwd.h HAVE_PWD_H)
97 check_include_files(stddef.h HAVE_STDDEF_H)
98 check_include_files(stdint.h HAVE_STDINT_H)
99 check_include_files(strings.h HAVE_STRINGS_H)
100 check_include_files(syslog.h HAVE_SYSLOG_H)
102 # check for fastcgi lib, for the tests only
103 check_include_files(fastcgi.h HAVE_FASTCGI_H)
104 check_include_files(fastcgi/fastcgi.h HAVE_FASTCGI_FASTCGI_H)
106 # will be needed for auth
107 check_include_files(crypt.h HAVE_CRYPT_H)
108 # check if we need libcrypt for crypt_r()
109 check_library_exists(crypt crypt_r "" HAVE_LIBCRYPT_CRYPT_R)
110 if(HAVE_LIBCRYPT_CRYPT_R)
111         set(HAVE_CRYPT_R 1)
112         set(HAVE_LIBCRYPT 1)
113 else()
114         check_library_exists(crypt crypt "" HAVE_LIBCRYPT)
115 endif()
116 check_function_exists(crypt_r HAVE_CRYPT_R)
117 check_function_exists(crypt HAVE_CRYPT)
119 check_include_files(sys/inotify.h HAVE_SYS_INOTIFY_H)
120 if(HAVE_SYS_INOTIFY_H)
121         check_function_exists(inotify_init HAVE_INOTIFY_INIT)
122 endif()
124 set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
125 check_type_size(socklen_t HAVE_SOCKLEN_T)
126 set(CMAKE_EXTRA_INCLUDE_FILES)
128 check_include_files(sys/random.h HAVE_SYS_RANDOM_H)
129 set(CMAKE_EXTRA_INCLUDE_FILES sys/random.h)
130 check_function_exists(getentropy HAVE_GETENTROPY)
131 set(CMAKE_EXTRA_INCLUDE_FILES)
133 check_include_files(linux/random.h HAVE_LINUX_RANDOM_H)
134 set(CMAKE_EXTRA_INCLUDE_FILES linux/random.h)
135 check_function_exists(getrandom HAVE_GETRANDOM)
136 set(CMAKE_EXTRA_INCLUDE_FILES)
138 check_type_size(long SIZEOF_LONG)
139 check_type_size(off_t SIZEOF_OFF_T)
141 check_function_exists(arc4random_buf HAVE_ARC4RANDOM_BUF)
142 check_function_exists(chroot HAVE_CHROOT)
143 check_function_exists(epoll_ctl HAVE_EPOLL_CTL)
144 check_function_exists(fork HAVE_FORK)
145 check_function_exists(getloadavg HAVE_GETLOADAVG)
146 check_function_exists(getrlimit HAVE_GETRLIMIT)
147 check_function_exists(getuid HAVE_GETUID)
148 check_function_exists(gmtime_r HAVE_GMTIME_R)
149 check_function_exists(inet_ntop HAVE_INET_NTOP)
150 check_function_exists(jrand48 HAVE_JRAND48)
151 check_function_exists(kqueue HAVE_KQUEUE)
152 check_function_exists(localtime_r HAVE_LOCALTIME_R)
153 check_function_exists(lstat HAVE_LSTAT)
154 check_function_exists(madvise HAVE_MADVISE)
155 check_function_exists(memcpy HAVE_MEMCPY)
156 check_function_exists(memset HAVE_MEMSET)
157 check_function_exists(mmap HAVE_MMAP)
158 check_function_exists(pathconf HAVE_PATHCONF)
159 check_function_exists(pipe2 HAVE_PIPE2)
160 check_function_exists(poll HAVE_POLL)
161 check_function_exists(port_create HAVE_PORT_CREATE)
162 check_function_exists(prctl HAVE_PRCTL)
163 check_function_exists(pread HAVE_PREAD)
164 check_function_exists(posix_fadvise HAVE_POSIX_FADVISE)
165 check_function_exists(select HAVE_SELECT)
166 check_function_exists(sendfile HAVE_SENDFILE)
167 check_function_exists(send_file HAVE_SEND_FILE)
168 check_function_exists(sendfile64 HAVE_SENDFILE64)
169 check_function_exists(sendfilev HAVE_SENDFILEV)
170 check_function_exists(sigaction HAVE_SIGACTION)
171 check_function_exists(signal HAVE_SIGNAL)
172 check_function_exists(sigtimedwait HAVE_SIGTIMEDWAIT)
173 check_function_exists(srandom HAVE_SRANDOM)
174 check_function_exists(strptime HAVE_STRPTIME)
175 check_function_exists(syslog HAVE_SYSLOG)
176 check_function_exists(writev HAVE_WRITEV)
177 check_function_exists(inet_aton HAVE_INET_ATON)
178 check_function_exists(issetugid HAVE_ISSETUGID)
179 check_function_exists(inet_pton HAVE_INET_PTON)
180 check_function_exists(memset_s HAVE_MEMSET_S)
181 check_function_exists(explicit_bzero HAVE_EXPLICIT_BZERO)
182 check_symbol_exists(clock_gettime "time.h" HAVE_CLOCK_GETTIME)
183 if (NOT HAVE_CLOCK_GETTIME)
184         check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME)
185 endif()
186 check_c_source_compiles("
187         #include <sys/types.h>
188         #include <sys/socket.h>
189         #include <netinet/in.h>
191         int main() {
192                 struct sockaddr_in6 s; struct in6_addr t=in6addr_any; int i=AF_INET6; s; t.s6_addr[0] = 0;
193                 return 0;
194         }" HAVE_IPV6)
195 check_c_source_compiles("
196         __attribute__((weak)) void __dummy(void *x) { }
197         int main() {
198                 void *x;
199                 __dummy(x);
200         }
201         " HAVE_WEAK_SYMBOLS)
202 check_c_source_compiles("
203         #include <time.h>
204         int main(void) {
205                 struct tm t;
206                 t.tm_gmtoff = 0;
207                 return 0;
208         }
209         " HAVE_STRUCT_TM_GMTOFF)
211 ## refactor me
212 macro(XCONFIG _package _include_DIR _link_DIR _link_FLAGS _cflags)
213 # reset the variables at the beginning
214         set(${_include_DIR})
215         set(${_link_DIR})
216         set(${_link_FLAGS})
217         set(${_cflags})
219         find_program(${_package}CONFIG_EXECUTABLE NAMES ${_package} PATHS /usr/local/bin )
221         # if pkg-config has been found
222         if(${_package}CONFIG_EXECUTABLE)
223                 set(XCONFIG_EXECUTABLE "${${_package}CONFIG_EXECUTABLE}")
224                 message(STATUS "found ${_package}: ${XCONFIG_EXECUTABLE}")
226                 exec_program(${XCONFIG_EXECUTABLE} ARGS --libs OUTPUT_VARIABLE __link_FLAGS)
227                 string(REPLACE "\n" "" ${_link_FLAGS} ${__link_FLAGS})
228                 exec_program(${XCONFIG_EXECUTABLE} ARGS --cflags OUTPUT_VARIABLE __cflags)
229                 string(REPLACE "\n" "" ${_cflags} ${__cflags})
230         else()
231                 message(STATUS "found ${_package}: no")
232         endif()
233 endmacro(XCONFIG _package _include_DIR _link_DIR _link_FLAGS _cflags)
235 if(WITH_XATTR)
236         check_include_files("sys/types.h;attr/attributes.h" HAVE_ATTR_ATTRIBUTES_H)
237         if(HAVE_ATTR_ATTRIBUTES_H)
238                 check_library_exists(attr attr_get "" HAVE_XATTR)
239         endif()
240 else()
241         unset(HAVE_ATTR_ATTRIBUTES_H)
242         unset(HAVE_XATTR)
243 endif()
245 if(WITH_MYSQL)
246         xconfig(mysql_config MYSQL_INCDIR MYSQL_LIBDIR MYSQL_LDFLAGS MYSQL_CFLAGS)
248         set(CMAKE_REQUIRED_INCLUDES /usr/include/mysql)
249         check_include_files(mysql.h HAVE_MYSQL_H)
250         set(CMAKE_REQUIRED_INCLUDES)
251         if(HAVE_MYSQL_H)
252                 check_library_exists(mysqlclient mysql_real_connect "" HAVE_MYSQL)
253         endif()
254 else()
255         unset(HAVE_MYSQL_H)
256         unset(HAVE_MYSQL)
257 endif()
259 if(WITH_PGSQL)
260         xconfig(pg_config PGSQL_INCDIR PGSQL_LIBDIR PGSQL_LDFLAGS PGSQL_CFLAGS)
262         check_include_files(libpq-fe.h HAVE_PGSQL_H)
263         if(HAVE_PGSQL_H)
264                 check_library_exists(pq PQsetdbLogin "" HAVE_PGSQL)
265         endif()
266 else()
267         unset(HAVE_PGSQL_H)
268         unset(HAVE_PGSQL)
269 endif()
271 if(WITH_DBI)
272         check_include_files(dbi/dbi.h HAVE_DBI_H)
273         if(HAVE_DBI_H)
274                 check_library_exists(dbi dbi_conn_connect "" HAVE_DBI)
275         endif()
276 else()
277         unset(HAVE_DBI_H)
278         unset(HAVE_DBI)
279 endif()
281 if(WITH_OPENSSL)
282         if(APPLE)
283                 set(CMAKE_REQUIRED_INCLUDES /opt/local/include)
284         endif()
285         check_include_files(openssl/ssl.h HAVE_OPENSSL_SSL_H)
286         if(APPLE)
287                 set(CMAKE_REQUIRED_INCLUDES)
288         endif()
289         if(HAVE_OPENSSL_SSL_H)
290                 check_library_exists(crypto BIO_f_base64 "" HAVE_LIBCRYPTO)
291                 if(HAVE_LIBCRYPTO)
292                         check_library_exists(ssl SSL_new "" HAVE_LIBSSL)
293                 endif()
294         endif()
295 else()
296         unset(HAVE_OPENSSL_SSL_H)
297         unset(HAVE_LIBCRYPTO)
298         unset(HAVE_LIBSSL)
299 endif()
301 if(WITH_PCRE)
302         ## if we have pcre-config, use it
303         xconfig(pcre-config PCRE_INCDIR PCRE_LIBDIR PCRE_LDFLAGS PCRE_CFLAGS)
304         if(PCRE_LDFLAGS OR PCRE_CFLAGS)
305                 message(STATUS "found pcre at: LDFLAGS: ${PCRE_LDFLAGS} CFLAGS: ${PCRE_CFLAGS}")
307                 if(NOT PCRE_CFLAGS STREQUAL "\n")
308                         ## if it is empty we'll get newline returned
309                         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PCRE_CFLAGS}")
310                 endif()
312                 set(HAVE_PCRE_H 1)
313                 set(HAVE_LIBPCRE 1)
314         else()
315                 if(NOT WIN32)
316                         check_include_files(pcre.h HAVE_PCRE_H)
317                         check_library_exists(pcre pcre_exec "" HAVE_LIBPCRE)
318                         set(PCRE_LDFLAGS -lpcre)
319                 else()
320                         find_path(PCRE_INCLUDE_DIR pcre.h
321                         /usr/local/include
322                         /usr/include
323                         )
325                         set(PCRE_NAMES pcre)
326                         find_library(PCRE_LIBRARY
327                         NAMES ${PCRE_NAMES}
328                         PATHS /usr/lib /usr/local/lib
329                         )
331                         if(PCRE_INCLUDE_DIR AND PCRE_LIBRARY)
332                                 set(CMAKE_REQUIRED_INCLUDES ${PCRE_INCLUDE_DIR})
333                                 set(CMAKE_REQUIRED_LIBRARIES ${PCRE_LIBRARY})
334                                 check_include_files(pcre.h HAVE_PCRE_H)
335                                 check_library_exists(pcre pcre_exec "" HAVE_LIBPCRE)
336                                 set(CMAKE_REQUIRED_INCLUDES)
337                                 set(CMAKE_REQUIRED_LIBRARIES)
338                                 include_directories(${PCRE_INCLUDE_DIR})
339                         endif()
340                 endif()
341         endif()
343         if(NOT HAVE_PCRE_H)
344                 message(FATAL_ERROR "pcre.h couldn't be found")
345         endif()
346         if(NOT HAVE_LIBPCRE)
347                 message(FATAL_ERROR "libpcre couldn't be found")
348         endif()
349 else()
350         unset(HAVE_PCRE_H)
351         unset(HAVE_LIBPCRE)
352 endif()
355 if(WITH_XML)
356         xconfig(xml2-config XML2_INCDIR XML2_LIBDIR XML2_LDFLAGS XML2_CFLAGS)
357         if(XML2_LDFLAGS OR XML2_CFLAGS)
358                 message(STATUS "found xml2 at: LDFLAGS: ${XML2_LDFLAGS} CFLAGS: ${XML2_CFLAGS}")
360                 ## if it is empty we'll get newline returned
361                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${XML2_CFLAGS}")
363                 check_include_files(libxml/tree.h HAVE_LIBXML_H)
365                 set(CMAKE_REQUIRED_FLAGS ${XML2_LDFLAGS})
366                 check_library_exists(xml2 xmlParseChunk "" HAVE_LIBXML)
367                 set(CMAKE_REQUIRED_FLAGS)
368         else()
369                 check_include_files(libxml.h HAVE_LIBXML_H)
370                 check_library_exists(xml2 xmlParseChunk "" HAVE_LIBXML)
371         endif()
373         if(NOT HAVE_LIBXML_H)
374                 message(FATAL_ERROR "libxml/tree.h couldn't be found")
375         endif()
376         if(NOT HAVE_LIBXML)
377                 message(FATAL_ERROR "libxml2 couldn't be found")
378         endif()
379 else()
380         unset(HAVE_LIBXML_H)
381         unset(HAVE_LIBXML)
382 endif()
384 if(WITH_SQLITE3)
385         check_include_files(sqlite3.h HAVE_SQLITE3_H)
386         check_library_exists(sqlite3 sqlite3_reset "" HAVE_SQLITE3)
387 else()
388         unset(HAVE_SQLITE3_H)
389         unset(HAVE_SQLITE3)
390 endif()
392 if(WITH_UUID)
393         check_include_files(uuid/uuid.h HAVE_UUID_UUID_H)
394         check_library_exists(uuid uuid_generate "" NEED_LIBUUID)
395         if(NOT NEED_LIBUUID)
396                 check_function_exists(uuid_generate HAVE_LIBUUID)
397         else()
398                 set(HAVE_LIBUUID 1)
399         endif()
400 else()
401         unset(HAVE_UUID_UUID_H)
402         unset(NEED_LIBUUID)
403         unset(HAVE_LIBUUID)
404 endif()
406 if(WITH_ZLIB)
407         if(NOT WIN32)
408                 check_include_files(zlib.h HAVE_ZLIB_H)
409                 check_library_exists(z deflate "" HAVE_LIBZ)
410                 set(ZLIB_LIBRARY z)
411         else()
412                 find_path(ZLIB_INCLUDE_DIR zlib.h
413                         /usr/local/include
414                         /usr/include
415                 )
417                 set(ZLIB_NAMES z zlib zdll)
418                         find_library(ZLIB_LIBRARY
419                         NAMES ${ZLIB_NAMES}
420                         PATHS /usr/lib /usr/local/lib
421                 )
423                 if(ZLIB_INCLUDE_DIR AND ZLIB_LIBRARY)
424                         set(CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIR})
425                         set(CMAKE_REQUIRED_LIBRARIES ${ZLIB_LIBRARY})
426                         get_filename_component(ZLIB_NAME ${ZLIB_LIBRARY} NAME)
427                         check_include_files(zlib.h HAVE_ZLIB_H)
428                         check_library_exists(${ZLIB_NAME} deflate "" HAVE_LIBZ)
429                         set(CMAKE_REQUIRED_INCLUDES)
430                         set(CMAKE_REQUIRED_LIBRARIES)
431                         include_directories(${ZLIB_INCLUDE_DIR})
432                 endif()
433         endif()
434 else()
435         unset(HAVE_ZLIB_H)
436         unset(HAVE_LIBZ)
437         unset(ZLIB_INCLUDE_DIR)
438         unset(ZLIB_LIBRARY)
439 endif()
441 if(WITH_BZIP)
442         check_include_files(bzlib.h HAVE_BZLIB_H)
443         check_library_exists(bz2 BZ2_bzCompress "" HAVE_LIBBZ2)
444 else()
445         unset(HAVE_BZLIB_H)
446         unset(HAVE_LIBBZ2)
447 endif()
449 if(WITH_LDAP)
450         check_include_files(ldap.h HAVE_LDAP_H)
451         check_library_exists(ldap ldap_bind "" HAVE_LIBLDAP)
452         check_include_files(lber.h HAVE_LBER_H)
453         check_library_exists(lber ber_printf "" HAVE_LIBLBER)
454         set(LDAP_DEPRECATED 1) # Using deprecated ldap api
455 else()
456         unset(HAVE_LDAP_H)
457         unset(HAVE_LIBLDAP)
458         unset(HAVE_LBER_H)
459         unset(HAVE_LIBLBER)
460 endif()
462 if(WITH_LUA)
463         pkg_search_module(LUA REQUIRED lua5.3 lua-5.3 lua5.2 lua-5.2 lua5.1 lua-5.1 lua)
464         message(STATUS "found lua at: INCDIR: ${LUA_INCLUDE_DIRS} LIBDIR: ${LUA_LIBRARY_DIRS} LDFLAGS: ${LUA_LDFLAGS} CFLAGS: ${LUA_CFLAGS}")
465         set(HAVE_LIBLUA 1 "Have liblua")
466         set(HAVE_LUA_H  1 "Have liblua header")
467 else()
468         unset(HAVE_LIBLUA)
469         unset(HAVE_LUA_H)
470 endif()
472 if(WITH_FAM)
473         check_include_files(fam.h HAVE_FAM_H)
474         check_library_exists(fam FAMOpen2 "" HAVE_LIBFAM)
475         if(HAVE_LIBFAM)
476                 set(CMAKE_REQUIRED_LIBRARIES fam)
477                 check_function_exists(FAMNoExists HAVE_FAMNOEXISTS)
478         endif()
479 else()
480         unset(HAVE_FAM_H)
481         unset(HAVE_LIBFAM)
482         unset(HAVE_FAMNOEXISTS)
483 endif()
485 if(WITH_GDBM)
486         check_include_files(gdbm.h HAVE_GDBM_H)
487         check_library_exists(gdbm gdbm_open "" HAVE_GDBM)
488 else()
489         unset(HAVE_GDBM_H)
490         unset(HAVE_GDBM)
491 endif()
493 if(WITH_MEMCACHED)
494         check_include_files(libmemcached/memcached.h HAVE_LIBMEMCACHED_MEMCACHED_H)
495         check_library_exists(memcached memcached "" HAVE_LIBMEMCACHED)
496         if(HAVE_LIBMEMCACHED_MEMCACHED_H AND HAVE_LIBMEMCACHED)
497                 set(USE_MEMCACHED 1)
498         else()
499                 message(FATAL_ERROR "didn't find libmemcached")
500         endif()
501 endif()
503 if(WITH_GEOIP)
504         check_library_exists(geoip GeoIP_country_name_by_addr "" HAVE_GEOIP)
505 endif()
507 if(NOT BUILD_STATIC)
508         check_include_files(dlfcn.h HAVE_DLFCN_H)
509 else()
510         unset(HAVE_DLFCN_H)
511 endif()
513 if(HAVE_DLFCN_H)
514         check_library_exists(dl dlopen "" HAVE_LIBDL)
515 else()
516         unset(HAVE_LIBDL)
517 endif()
519 set(LIGHTTPD_VERSION_ID 10400)
520 set(PACKAGE_NAME "${CMAKE_PROJECT_NAME}")
521 set(PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}")
523 if(NOT SBINDIR)
524         set(SBINDIR "sbin")
525 endif()
527 if(NOT LIGHTTPD_MODULES_DIR)
528         set(LIGHTTPD_MODULES_DIR "lib${LIB_SUFFIX}/lighttpd")
529 endif()
531 if(NOT WIN32)
532         set(LIGHTTPD_LIBRARY_DIR "${CMAKE_INSTALL_PREFIX}/${LIGHTTPD_MODULES_DIR}")
533 else()
534         ## We use relative path in windows
535         set(LIGHTTPD_LIBRARY_DIR "lib")
536 endif()
538 ## Write out config.h
539 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
541 add_definitions(-DHAVE_CONFIG_H)
543 include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
545 set(COMMON_SRC
546         base64.c buffer.c log.c
547         keyvalue.c chunk.c
548         http_chunk.c stream.c fdevent.c gw_backend.c
549         stat_cache.c plugin.c joblist.c etag.c array.c
550         data_string.c data_array.c
551         data_integer.c algo_sha1.c md5.c
552         vector.c
553         fdevent_select.c fdevent_libev.c
554         fdevent_poll.c fdevent_linux_sysepoll.c
555         fdevent_solaris_devpoll.c fdevent_solaris_port.c
556         fdevent_freebsd_kqueue.c
557         data_config.c
558         crc32.c
559         connections-glue.c
560         configfile-glue.c
561         http-header-glue.c
562         http_auth.c
563         http_vhostdb.c
564         sock_addr.c
565         splaytree.c
566         rand.c
567         status_counter.c safe_memclear.c
570 if(WIN32)
571         message(STATUS "Adding local getopt implementation.")
572         set(COMMON_SRC ${COMMON_SRC} xgetopt.c)
573 endif()
575 add_executable(lemon lemon.c)
577 ## Build parsers by using lemon...
578 lemon_parser(configparser.y)
579 lemon_parser(mod_ssi_exprparser.y)
581 set(L_INSTALL_TARGETS)
583 add_executable(lighttpd-angel lighttpd-angel.c)
584 set(L_INSTALL_TARGETS ${L_INSTALL_TARGETS} lighttpd-angel)
585 add_target_properties(lighttpd-angel COMPILE_FLAGS "-DSBIN_DIR=\\\\\"${CMAKE_INSTALL_PREFIX}/${SBINDIR}\\\\\"")
587 add_executable(lighttpd
588         server.c
589         response.c
590         connections.c
591         inet_ntop_cache.c
592         network.c
593         network_write.c
594         configfile.c
595         configparser.c
596         request.c
597         proc_open.c
598         ${COMMON_SRC}
600 set(L_INSTALL_TARGETS ${L_INSTALL_TARGETS} lighttpd)
602 add_and_install_library(mod_access mod_access.c)
603 add_and_install_library(mod_accesslog mod_accesslog.c)
604 add_and_install_library(mod_alias mod_alias.c)
605 add_and_install_library(mod_auth "mod_auth.c")
606 add_and_install_library(mod_authn_file "mod_authn_file.c")
607 if(NOT WIN32)
608         add_and_install_library(mod_cgi mod_cgi.c)
609 endif()
610 add_and_install_library(mod_compress mod_compress.c)
611 add_and_install_library(mod_deflate mod_deflate.c)
612 add_and_install_library(mod_dirlisting mod_dirlisting.c)
613 add_and_install_library(mod_evasive mod_evasive.c)
614 add_and_install_library(mod_evhost mod_evhost.c)
615 add_and_install_library(mod_expire mod_expire.c)
616 add_and_install_library(mod_extforward mod_extforward.c)
617 add_and_install_library(mod_fastcgi mod_fastcgi.c)
618 add_and_install_library(mod_flv_streaming mod_flv_streaming.c)
619 add_and_install_library(mod_indexfile mod_indexfile.c)
620 add_and_install_library(mod_proxy mod_proxy.c)
621 add_and_install_library(mod_redirect mod_redirect.c)
622 add_and_install_library(mod_rewrite mod_rewrite.c)
623 add_and_install_library(mod_rrdtool mod_rrdtool.c)
624 add_and_install_library(mod_scgi mod_scgi.c)
625 add_and_install_library(mod_secdownload mod_secdownload.c)
626 add_and_install_library(mod_setenv mod_setenv.c)
627 add_and_install_library(mod_simple_vhost mod_simple_vhost.c)
628 add_and_install_library(mod_ssi "mod_ssi_exprparser.c;mod_ssi_expr.c;mod_ssi.c")
629 add_and_install_library(mod_staticfile mod_staticfile.c)
630 add_and_install_library(mod_status mod_status.c)
631 add_and_install_library(mod_uploadprogress mod_uploadprogress.c)
632 add_and_install_library(mod_userdir mod_userdir.c)
633 add_and_install_library(mod_usertrack mod_usertrack.c)
634 add_and_install_library(mod_vhostdb mod_vhostdb.c)
635 add_and_install_library(mod_webdav mod_webdav.c)
636 add_and_install_library(mod_wstunnel mod_wstunnel.c)
638 add_executable(test_buffer
639         test_buffer.c
640         buffer.c
642 add_test(NAME test_buffer COMMAND test_buffer)
644 add_executable(test_base64
645         test_base64.c
646         buffer.c
647         base64.c
649 add_test(NAME test_base64 COMMAND test_base64)
651 add_executable(test_configfile
652         test_configfile.c
653         buffer.c
654         array.c
655         data_string.c
656         keyvalue.c
657         vector.c
658         log.c
660 add_test(NAME test_configfile COMMAND test_configfile)
662 if(HAVE_PCRE_H)
663         target_link_libraries(lighttpd ${PCRE_LDFLAGS})
664         add_target_properties(lighttpd COMPILE_FLAGS ${PCRE_CFLAGS})
665         target_link_libraries(mod_rewrite ${PCRE_LDFLAGS})
666         add_target_properties(mod_rewrite COMPILE_FLAGS ${PCRE_CFLAGS})
667         target_link_libraries(mod_dirlisting ${PCRE_LDFLAGS})
668         add_target_properties(mod_dirlisting COMPILE_FLAGS ${PCRE_CFLAGS})
669         target_link_libraries(mod_redirect ${PCRE_LDFLAGS})
670         add_target_properties(mod_redirect COMPILE_FLAGS ${PCRE_CFLAGS})
671         target_link_libraries(test_configfile ${PCRE_LDFLAGS})
672         add_target_properties(test_configfile COMPILE_FLAGS ${PCRE_CFLAGS})
673 endif()
675 if(WITH_PCRE AND (WITH_MEMCACHED OR WITH_GDBM))
676         add_and_install_library(mod_trigger_b4_dl mod_trigger_b4_dl.c)
677         target_link_libraries(mod_trigger_b4_dl ${PCRE_LDFLAGS})
678         add_target_properties(mod_trigger_b4_dl COMPILE_FLAGS ${PCRE_CFLAGS})
679 endif()
681 if(WITH_LUA)
682         add_and_install_library(mod_magnet "mod_magnet.c;mod_magnet_cache.c")
683         target_link_libraries(mod_magnet ${LUA_LDFLAGS})
684         add_target_properties(mod_magnet COMPILE_FLAGS ${LUA_CFLAGS})
686         add_and_install_library(mod_cml "mod_cml.c;mod_cml_lua.c;mod_cml_funcs.c")
687         target_link_libraries(mod_cml ${LUA_LDFLAGS})
688         add_target_properties(mod_cml COMPILE_FLAGS ${LUA_CFLAGS})
689         if(WITH_MEMCACHED)
690                 target_link_libraries(mod_cml memcached)
691         endif()
692 endif()
694 if(WITH_GEOIP)
695         add_and_install_library(mod_geoip mod_geoip.c)
696         target_link_libraries(mod_geoip GeoIP)
697 endif()
699 if(HAVE_MYSQL_H AND HAVE_MYSQL)
700         add_and_install_library(mod_mysql_vhost "mod_mysql_vhost.c")
701         target_link_libraries(mod_mysql_vhost mysqlclient)
702         add_and_install_library(mod_vhostdb_mysql "mod_vhostdb_mysql.c")
703         target_link_libraries(mod_vhostdb_mysql mysqlclient)
704         include_directories(/usr/include/mysql)
706         add_and_install_library(mod_authn_mysql "mod_authn_mysql.c")
707         set(L_MOD_AUTHN_MYSQL)
708         if(HAVE_LIBCRYPT)
709                 set(L_MOD_AUTHN_MYSQL ${L_MOD_AUTHN_MYSQL} crypt)
710         endif()
711         target_link_libraries(mod_authn_mysql ${L_MOD_AUTHN_MYSQL} mysqlclient)
712 endif()
714 if(HAVE_PGSQL_H AND HAVE_PGSQL)
715         add_and_install_library(mod_vhostdb_pgsql "mod_vhostdb_pgsql.c")
716         target_link_libraries(mod_vhostdb_pgsql pq)
717 endif()
719 if(HAVE_DBI_H AND HAVE_DBI)
720         add_and_install_library(mod_vhostdb_dbi "mod_vhostdb_dbi.c")
721         target_link_libraries(mod_vhostdb_dbi dbi)
722 endif()
724 set(L_MOD_WEBDAV)
725 if(HAVE_SQLITE3_H)
726         set(L_MOD_WEBDAV ${L_MOD_WEBDAV} sqlite3)
727 endif()
728 if(HAVE_LIBXML_H)
729         target_link_libraries(mod_webdav ${XML2_LDFLAGS})
730 endif()
731 if(HAVE_UUID_H)
732         if(NEED_LIBUUID)
733                 set(L_MOD_WEBDAV ${L_MOD_WEBDAV} uuid)
734         endif()
735 endif()
737 target_link_libraries(mod_webdav ${L_MOD_WEBDAV})
739 set(L_MOD_AUTHN_FILE)
740 if(HAVE_LIBCRYPT)
741         set(L_MOD_AUTHN_FILE ${L_MOD_AUTHN_FILE} crypt)
742 endif()
743 target_link_libraries(mod_authn_file ${L_MOD_AUTHN_FILE})
745 if(WITH_KRB5)
746         check_library_exists(krb5 krb5_init_context "" HAVE_KRB5)
747         add_and_install_library(mod_authn_gssapi "mod_authn_gssapi.c")
748         set(L_MOD_AUTHN_GSSAPI ${L_MOD_AUTHN_GSSAPI} krb5 gssapi_krb5)
749         target_link_libraries(mod_authn_gssapi ${L_MOD_AUTHN_GSSAPI})
750 endif()
752 if(WITH_LDAP)
753         set(L_MOD_AUTHN_LDAP ${L_MOD_AUTHN_LDAP} ldap lber)
754         add_and_install_library(mod_authn_ldap "mod_authn_ldap.c")
755         target_link_libraries(mod_authn_ldap ${L_MOD_AUTHN_LDAP})
756         add_and_install_library(mod_vhostdb_ldap "mod_vhostdb_ldap.c")
757         target_link_libraries(mod_vhostdb_ldap ${L_MOD_AUTHN_LDAP})
758 endif()
760 if(HAVE_ZLIB_H)
761         if(HAVE_BZLIB_H)
762                 target_link_libraries(mod_compress ${ZLIB_LIBRARY} bz2)
763                 target_link_libraries(mod_deflate ${ZLIB_LIBRARY} bz2)
764         else()
765                 target_link_libraries(mod_compress ${ZLIB_LIBRARY})
766                 target_link_libraries(mod_deflate ${ZLIB_LIBRARY})
767         endif()
768 endif()
770 if(HAVE_LIBFAM)
771         target_link_libraries(lighttpd fam)
772 endif()
774 if(HAVE_GDBM_H)
775         target_link_libraries(mod_trigger_b4_dl gdbm)
776 endif()
778 if(WITH_MEMCACHED)
779         target_link_libraries(mod_trigger_b4_dl memcached)
780 endif()
782 if(HAVE_XATTR)
783         target_link_libraries(lighttpd attr)
784 endif()
786 if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang")
787         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wall -g -Wshadow -W -pedantic ${WARN_CFLAGS}")
788         set(CMAKE_C_FLAGS_RELEASE        "${CMAKE_C_FLAGS_RELEASE}     -O2")
789         set(CMAKE_C_FLAGS_DEBUG          "${CMAKE_C_FLAGS_DEBUG}       -O0")
790         set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_WITHDEBINFO} -O2")
791         set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${WARN_LDFLAGS}")
792         set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${WARN_LDFLAGS}")
793 endif()
795 if((NOT APPLE) OR CMAKE_C_COMPILER_ID MATCHES "GNU")
796         add_target_properties(lighttpd LINK_FLAGS "-Wl,-export-dynamic")
797 endif()
799 set_target_properties(lighttpd PROPERTIES CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
801 if(WIN32)
802         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNVALGRIND")
803         add_target_properties(lighttpd COMPILE_FLAGS "-DLI_DECLARE_EXPORTS")
804         target_link_libraries(lighttpd ws2_32)
805         target_link_libraries(mod_proxy ws2_32)
806         target_link_libraries(mod_fcgi ws2_32)
807         target_link_libraries(mod_scgi ws2_32)
808         target_link_libraries(mod_ssi ws2_32)
810         if(MINGW)
811                 target_link_libraries(lighttpd msvcr70)
812                 add_target_properties(lighttpd LINK_FLAGS "-Wl,-subsystem,console")
813         endif()
814 endif()
816 if(NOT BUILD_STATIC)
817         if(HAVE_LIBDL)
818                 target_link_libraries(lighttpd dl)
819         endif()
820 endif()
822 if(HAVE_LIBSSL AND HAVE_LIBCRYPTO)
823         target_link_libraries(lighttpd ssl)
824         target_link_libraries(lighttpd crypto)
825         add_and_install_library(mod_openssl "mod_openssl.c")
826         set(L_MOD_OPENSSL ${L_MOD_OPENSSL} ssl crypto)
827         target_link_libraries(mod_openssl ${L_MOD_OPENSSL})
828         set(L_MOD_AUTHN_FILE ${L_MOD_AUTHN_FILE} crypto)
829         target_link_libraries(mod_authn_file ${L_MOD_AUTHN_FILE})
830         target_link_libraries(mod_secdownload crypto)
831         target_link_libraries(mod_wstunnel crypto)
832 endif()
834 if(WITH_LIBEV)
835         target_link_libraries(lighttpd ${LIBEV_LDFLAGS})
836         add_target_properties(lighttpd COMPILE_FLAGS ${LIBEV_CFLAGS})
837 endif()
839 if(WITH_LIBUNWIND)
840         target_link_libraries(lighttpd ${LIBUNWIND_LDFLAGS})
841         add_target_properties(lighttpd COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
843         target_link_libraries(test_buffer ${LIBUNWIND_LDFLAGS})
844         add_target_properties(test_buffer COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
845         target_link_libraries(test_base64 ${LIBUNWIND_LDFLAGS})
846         add_target_properties(test_base64 COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
847         target_link_libraries(test_configfile ${PCRE_LDFLAGS} ${LIBUNWIND_LDFLAGS})
848         add_target_properties(test_configfile COMPILE_FLAGS ${PCRE_CFLAGS} ${LIBUNWIND_CFLAGS})
849 endif()
851 if(NOT WIN32)
852 install(TARGETS ${L_INSTALL_TARGETS}
853         RUNTIME DESTINATION ${SBINDIR}
854         LIBRARY DESTINATION ${LIGHTTPD_MODULES_DIR}
855         ARCHIVE DESTINATION ${LIGHTTPD_MODULES_DIR}/static)
856 else()
857 ## HACK to make win32 to install our libraries in desired directory..
858 install(TARGETS lighttpd
859         RUNTIME DESTINATION ${SBINDIR}
860         ARCHIVE DESTINATION lib/static)
861 list(REMOVE_ITEM L_INSTALL_TARGETS lighttpd)
862 install(TARGETS ${L_INSTALL_TARGETS}
863         RUNTIME DESTINATION ${SBINDIR}/lib
864         LIBRARY DESTINATION lib
865         ARCHIVE DESTINATION lib/static)
866 endif()