[mod_accesslog] %{ratio}n logs compression ratio (fixes #2133)
[lighttpd.git] / src / CMakeLists.txt
blob55e72365b62cd411c74f5a469840764b6734c965
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 the mod_sql_vhost [default: off]")
18 # option(WITH_POSTGRESQL "with postgress-support for the mod_sql_vhost [default: off]")
19 option(WITH_OPENSSL "with openssl-support [default: off]")
20 option(WITH_PCRE "with regex support [default: on]" ON)
21 option(WITH_WEBDAV_PROPS "with property-support for mod_webdav [default: off]")
22 option(WITH_WEBDAV_LOCKS "locks in webdav [default: off]")
23 option(WITH_BZIP "with bzip2-support for mod_compress [default: off]")
24 option(WITH_ZLIB "with deflate-support for mod_compress [default: on]" ON)
25 option(WITH_KRB5 "with Kerberos5-support for the mod_auth [default: off]")
26 option(WITH_LDAP "with LDAP-support for the mod_auth [default: off]")
27 option(WITH_LUA "with lua 5.1 for mod_magnet [default: off]")
28 # option(WITH_VALGRIND "with internal support for valgrind [default: off]")
29 # option(WITH_KERBEROS5 "use Kerberos5 support with OpenSSL [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         set(WITH_UUID 1)
71 endif()
73 check_include_files(sys/devpoll.h HAVE_SYS_DEVPOLL_H)
74 check_include_files(sys/epoll.h HAVE_SYS_EPOLL_H)
75 check_include_files(sys/event.h HAVE_SYS_EVENT_H)
76 check_include_files(sys/mman.h HAVE_SYS_MMAN_H)
77 check_include_files(sys/poll.h HAVE_SYS_POLL_H)
78 check_include_files(sys/port.h HAVE_SYS_PORT_H)
79 check_include_files(sys/prctl.h HAVE_SYS_PRCTL_H)
80 check_include_files(sys/resource.h HAVE_SYS_RESOURCE_H)
81 check_include_files(sys/sendfile.h HAVE_SYS_SENDFILE_H)
82 check_include_files(sys/select.h HAVE_SYS_SELECT_H)
83 check_include_files(sys/types.h HAVE_SYS_TYPES_H)
84 check_include_files(sys/uio.h HAVE_SYS_UIO_H)
85 check_include_files(sys/un.h HAVE_SYS_UN_H)
86 check_include_files(sys/wait.h HAVE_SYS_WAIT_H)
87 check_include_files(sys/time.h HAVE_SYS_TIME_H)
88 check_include_files(unistd.h HAVE_UNISTD_H)
89 check_include_files(pthread.h HAVE_PTHREAD_H)
90 check_include_files(getopt.h HAVE_GETOPT_H)
91 check_include_files(inttypes.h HAVE_INTTYPES_H)
92 check_include_files(poll.h HAVE_POLL_H)
93 check_include_files(pwd.h HAVE_PWD_H)
94 check_include_files(stddef.h HAVE_STDDEF_H)
95 check_include_files(stdint.h HAVE_STDINT_H)
96 check_include_files(syslog.h HAVE_SYSLOG_H)
98 # check for fastcgi lib, for the tests only
99 check_include_files(fastcgi.h HAVE_FASTCGI_H)
100 check_include_files(fastcgi/fastcgi.h HAVE_FASTCGI_FASTCGI_H)
102 # will be needed for auth
103 check_include_files(crypt.h HAVE_CRYPT_H)
104 # check if we need libcrypt for crypt_r()
105 check_library_exists(crypt crypt_r "" HAVE_LIBCRYPT_CRYPT_R)
106 if(HAVE_LIBCRYPT_CRYPT_R)
107         set(HAVE_CRYPT_R 1)
108         set(HAVE_LIBCRYPT 1)
109 else()
110         check_library_exists(crypt crypt "" HAVE_LIBCRYPT)
111 endif()
112 check_function_exists(crypt_r HAVE_CRYPT_R)
113 check_function_exists(crypt HAVE_CRYPT)
115 check_include_files(sys/inotify.h HAVE_SYS_INOTIFY_H)
116 if(HAVE_SYS_INOTIFY_H)
117         check_function_exists(inotify_init HAVE_INOTIFY_INIT)
118 endif()
120 set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
121 check_type_size(socklen_t HAVE_SOCKLEN_T)
122 set(CMAKE_EXTRA_INCLUDE_FILES)
124 check_include_files(linux/random.h HAVE_LINUX_RANDOM_H)
125 set(CMAKE_EXTRA_INCLUDE_FILES linux/random.h)
126 check_function_exists(getrandom HAVE_GETRANDOM)
127 set(CMAKE_EXTRA_INCLUDE_FILES)
129 check_type_size(long SIZEOF_LONG)
130 check_type_size(off_t SIZEOF_OFF_T)
132 check_function_exists(arc4random HAVE_ARC4RANDOM)
133 check_function_exists(chroot HAVE_CHROOT)
134 check_function_exists(epoll_ctl HAVE_EPOLL_CTL)
135 check_function_exists(fork HAVE_FORK)
136 check_function_exists(getentropy HAVE_GETENTROPY)
137 check_function_exists(getrlimit HAVE_GETRLIMIT)
138 check_function_exists(getuid HAVE_GETUID)
139 check_function_exists(gmtime_r HAVE_GMTIME_R)
140 check_function_exists(inet_ntop HAVE_INET_NTOP)
141 check_function_exists(jrand48 HAVE_JRAND48)
142 check_function_exists(kqueue HAVE_KQUEUE)
143 check_function_exists(localtime_r HAVE_LOCALTIME_R)
144 check_function_exists(lstat HAVE_LSTAT)
145 check_function_exists(madvise HAVE_MADVISE)
146 check_function_exists(memcpy HAVE_MEMCPY)
147 check_function_exists(memset HAVE_MEMSET)
148 check_function_exists(mmap HAVE_MMAP)
149 check_function_exists(pathconf HAVE_PATHCONF)
150 check_function_exists(poll HAVE_POLL)
151 check_function_exists(port_create HAVE_PORT_CREATE)
152 check_function_exists(prctl HAVE_PRCTL)
153 check_function_exists(pread HAVE_PREAD)
154 check_function_exists(posix_fadvise HAVE_POSIX_FADVISE)
155 check_function_exists(select HAVE_SELECT)
156 check_function_exists(sendfile HAVE_SENDFILE)
157 check_function_exists(send_file HAVE_SEND_FILE)
158 check_function_exists(sendfile64 HAVE_SENDFILE64)
159 check_function_exists(sendfilev HAVE_SENDFILEV)
160 check_function_exists(sigaction HAVE_SIGACTION)
161 check_function_exists(signal HAVE_SIGNAL)
162 check_function_exists(sigtimedwait HAVE_SIGTIMEDWAIT)
163 check_function_exists(srandom HAVE_SRANDOM)
164 check_function_exists(strptime HAVE_STRPTIME)
165 check_function_exists(syslog HAVE_SYSLOG)
166 check_function_exists(writev HAVE_WRITEV)
167 check_function_exists(inet_aton HAVE_INET_ATON)
168 check_function_exists(issetugid HAVE_ISSETUGID)
169 check_function_exists(inet_pton HAVE_INET_PTON)
170 check_function_exists(memset_s HAVE_MEMSET_S)
171 check_function_exists(explicit_bzero HAVE_EXPLICIT_BZERO)
172 check_symbol_exists(clock_gettime "time.h" HAVE_CLOCK_GETTIME)
173 if (NOT HAVE_CLOCK_GETTIME)
174         check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME)
175 endif()
176 check_c_source_compiles("
177         #include <sys/types.h>
178         #include <sys/socket.h>
179         #include <netinet/in.h>
181         int main() {
182                 struct sockaddr_in6 s; struct in6_addr t=in6addr_any; int i=AF_INET6; s; t.s6_addr[0] = 0;
183                 return 0;
184         }" HAVE_IPV6)
185 check_c_source_compiles("
186         __attribute__((weak)) void __dummy(void *x) { }
187         int main() {
188                 void *x;
189                 __dummy(x);
190         }
191         " HAVE_WEAK_SYMBOLS)
192 check_c_source_compiles("
193         #include <time.h>
194         int main(void) {
195                 struct tm t;
196                 t.tm_gmtoff = 0;
197                 return 0;
198         }
199         " HAVE_STRUCT_TM_GMTOFF)
201 ## refactor me
202 macro(XCONFIG _package _include_DIR _link_DIR _link_FLAGS _cflags)
203 # reset the variables at the beginning
204         set(${_include_DIR})
205         set(${_link_DIR})
206         set(${_link_FLAGS})
207         set(${_cflags})
209         find_program(${_package}CONFIG_EXECUTABLE NAMES ${_package} PATHS /usr/local/bin )
211         # if pkg-config has been found
212         if(${_package}CONFIG_EXECUTABLE)
213                 set(XCONFIG_EXECUTABLE "${${_package}CONFIG_EXECUTABLE}")
214                 message(STATUS "found ${_package}: ${XCONFIG_EXECUTABLE}")
216                 exec_program(${XCONFIG_EXECUTABLE} ARGS --libs OUTPUT_VARIABLE __link_FLAGS)
217                 string(REPLACE "\n" "" ${_link_FLAGS} ${__link_FLAGS})
218                 exec_program(${XCONFIG_EXECUTABLE} ARGS --cflags OUTPUT_VARIABLE __cflags)
219                 string(REPLACE "\n" "" ${_cflags} ${__cflags})
220         else()
221                 message(STATUS "found ${_package}: no")
222         endif()
223 endmacro(XCONFIG _package _include_DIR _link_DIR _link_FLAGS _cflags)
225 if(WITH_XATTR)
226         check_include_files(attr/attributes.h HAVE_ATTR_ATTRIBUTES_H)
227         if(HAVE_ATTR_ATTRIBUTES_H)
228                 check_library_exists(attr attr_get "" HAVE_XATTR)
229         endif()
230 else()
231         unset(HAVE_ATTR_ATTRIBUTES_H)
232         unset(HAVE_XATTR)
233 endif()
235 if(WITH_MYSQL)
236         xconfig(mysql_config MYSQL_INCDIR MYSQL_LIBDIR MYSQL_LDFLAGS MYSQL_CFLAGS)
238         set(CMAKE_REQUIRED_INCLUDES /usr/include/mysql)
239         check_include_files(mysql.h HAVE_MYSQL_H)
240         set(CMAKE_REQUIRED_INCLUDES)
241         if(HAVE_MYSQL_H)
242                 check_library_exists(mysqlclient mysql_real_connect "" HAVE_MYSQL)
243         endif()
244 else()
245         unset(HAVE_MYSQL_H)
246         unset(HAVE_MYSQL)
247 endif()
249 if(WITH_OPENSSL)
250         if(APPLE)
251                 set(CMAKE_REQUIRED_INCLUDES /opt/local/include)
252         endif()
253         check_include_files(openssl/ssl.h HAVE_OPENSSL_SSL_H)
254         if(APPLE)
255                 set(CMAKE_REQUIRED_INCLUDES)
256         endif()
257         if(HAVE_OPENSSL_SSL_H)
258                 check_library_exists(crypto BIO_f_base64 "" HAVE_LIBCRYPTO)
259                 if(HAVE_LIBCRYPTO)
260                         check_library_exists(ssl SSL_new "" HAVE_LIBSSL)
261                 endif()
262         endif()
263 else()
264         unset(HAVE_OPENSSL_SSL_H)
265         unset(HAVE_LIBCRYPTO)
266         unset(HAVE_LIBSSL)
267 endif()
269 if(WITH_PCRE)
270         ## if we have pcre-config, use it
271         xconfig(pcre-config PCRE_INCDIR PCRE_LIBDIR PCRE_LDFLAGS PCRE_CFLAGS)
272         if(PCRE_LDFLAGS OR PCRE_CFLAGS)
273                 message(STATUS "found pcre at: LDFLAGS: ${PCRE_LDFLAGS} CFLAGS: ${PCRE_CFLAGS}")
275                 if(NOT PCRE_CFLAGS STREQUAL "\n")
276                         ## if it is empty we'll get newline returned
277                         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PCRE_CFLAGS}")
278                 endif()
280                 set(HAVE_PCRE_H 1)
281                 set(HAVE_LIBPCRE 1)
282         else()
283                 if(NOT WIN32)
284                         check_include_files(pcre.h HAVE_PCRE_H)
285                         check_library_exists(pcre pcre_exec "" HAVE_LIBPCRE)
286                         set(PCRE_LDFLAGS -lpcre)
287                 else()
288                         find_path(PCRE_INCLUDE_DIR pcre.h
289                         /usr/local/include
290                         /usr/include
291                         )
293                         set(PCRE_NAMES pcre)
294                         find_library(PCRE_LIBRARY
295                         NAMES ${PCRE_NAMES}
296                         PATHS /usr/lib /usr/local/lib
297                         )
299                         if(PCRE_INCLUDE_DIR AND PCRE_LIBRARY)
300                                 set(CMAKE_REQUIRED_INCLUDES ${PCRE_INCLUDE_DIR})
301                                 set(CMAKE_REQUIRED_LIBRARIES ${PCRE_LIBRARY})
302                                 check_include_files(pcre.h HAVE_PCRE_H)
303                                 check_library_exists(pcre pcre_exec "" HAVE_LIBPCRE)
304                                 set(CMAKE_REQUIRED_INCLUDES)
305                                 set(CMAKE_REQUIRED_LIBRARIES)
306                                 include_directories(${PCRE_INCLUDE_DIR})
307                         endif()
308                 endif()
309         endif()
311         if(NOT HAVE_PCRE_H)
312                 message(FATAL_ERROR "pcre.h couldn't be found")
313         endif()
314         if(NOT HAVE_LIBPCRE)
315                 message(FATAL_ERROR "libpcre couldn't be found")
316         endif()
317 else()
318         unset(HAVE_PCRE_H)
319         unset(HAVE_LIBPCRE)
320 endif()
323 if(WITH_XML)
324         xconfig(xml2-config XML2_INCDIR XML2_LIBDIR XML2_LDFLAGS XML2_CFLAGS)
325         if(XML2_LDFLAGS OR XML2_CFLAGS)
326                 message(STATUS "found xml2 at: LDFLAGS: ${XML2_LDFLAGS} CFLAGS: ${XML2_CFLAGS}")
328                 ## if it is empty we'll get newline returned
329                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${XML2_CFLAGS}")
331                 check_include_files(libxml/tree.h HAVE_LIBXML_H)
333                 set(CMAKE_REQUIRED_FLAGS ${XML2_LDFLAGS})
334                 check_library_exists(xml2 xmlParseChunk "" HAVE_LIBXML)
335                 set(CMAKE_REQUIRED_FLAGS)
336         else()
337                 check_include_files(libxml.h HAVE_LIBXML_H)
338                 check_library_exists(xml2 xmlParseChunk "" HAVE_LIBXML)
339         endif()
341         if(NOT HAVE_LIBXML_H)
342                 message(FATAL_ERROR "libxml/tree.h couldn't be found")
343         endif()
344         if(NOT HAVE_LIBXML)
345                 message(FATAL_ERROR "libxml2 couldn't be found")
346         endif()
347 else()
348         unset(HAVE_LIBXML_H)
349         unset(HAVE_LIBXML)
350 endif()
352 if(WITH_SQLITE3)
353         check_include_files(sqlite3.h HAVE_SQLITE3_H)
354         check_library_exists(sqlite3 sqlite3_reset "" HAVE_SQLITE3)
355 else()
356         unset(HAVE_SQLITE3_H)
357         unset(HAVE_SQLITE3)
358 endif()
360 if(WITH_UUID)
361         check_include_files(uuid/uuid.h HAVE_UUID_UUID_H)
362         check_library_exists(uuid uuid_generate "" NEED_LIBUUID)
363         if(NOT NEED_LIBUUID)
364                 check_function_exists(uuid_generate HAVE_LIBUUID)
365         else()
366                 set(HAVE_LIBUUID 1)
367         endif()
368 else()
369         unset(HAVE_UUID_UUID_H)
370         unset(NEED_LIBUUID)
371         unset(HAVE_LIBUUID)
372 endif()
374 if(WITH_ZLIB)
375         if(NOT WIN32)
376                 check_include_files(zlib.h HAVE_ZLIB_H)
377                 check_library_exists(z deflate "" HAVE_LIBZ)
378                 set(ZLIB_LIBRARY z)
379         else()
380                 find_path(ZLIB_INCLUDE_DIR zlib.h
381                         /usr/local/include
382                         /usr/include
383                 )
385                 set(ZLIB_NAMES z zlib zdll)
386                         find_library(ZLIB_LIBRARY
387                         NAMES ${ZLIB_NAMES}
388                         PATHS /usr/lib /usr/local/lib
389                 )
391                 if(ZLIB_INCLUDE_DIR AND ZLIB_LIBRARY)
392                         set(CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIR})
393                         set(CMAKE_REQUIRED_LIBRARIES ${ZLIB_LIBRARY})
394                         get_filename_component(ZLIB_NAME ${ZLIB_LIBRARY} NAME)
395                         check_include_files(zlib.h HAVE_ZLIB_H)
396                         check_library_exists(${ZLIB_NAME} deflate "" HAVE_LIBZ)
397                         set(CMAKE_REQUIRED_INCLUDES)
398                         set(CMAKE_REQUIRED_LIBRARIES)
399                         include_directories(${ZLIB_INCLUDE_DIR})
400                 endif()
401         endif()
402 else()
403         unset(HAVE_ZLIB_H)
404         unset(HAVE_LIBZ)
405         unset(ZLIB_INCLUDE_DIR)
406         unset(ZLIB_LIBRARY)
407 endif()
409 if(WITH_BZIP)
410         check_include_files(bzlib.h HAVE_BZLIB_H)
411         check_library_exists(bz2 BZ2_bzCompress "" HAVE_LIBBZ2)
412 else()
413         unset(HAVE_BZLIB_H)
414         unset(HAVE_LIBBZ2)
415 endif()
417 if(WITH_LDAP)
418         check_include_files(ldap.h HAVE_LDAP_H)
419         check_library_exists(ldap ldap_bind "" HAVE_LIBLDAP)
420         check_include_files(lber.h HAVE_LBER_H)
421         check_library_exists(lber ber_printf "" HAVE_LIBLBER)
422         set(LDAP_DEPRECATED 1) # Using deprecated ldap api
423 else()
424         unset(HAVE_LDAP_H)
425         unset(HAVE_LIBLDAP)
426         unset(HAVE_LBER_H)
427         unset(HAVE_LIBLBER)
428 endif()
430 if(WITH_LUA)
431         pkg_search_module(LUA REQUIRED lua5.3 lua-5.3 lua5.2 lua-5.2 lua5.1 lua-5.1 lua)
432         message(STATUS "found lua at: INCDIR: ${LUA_INCLUDE_DIRS} LIBDIR: ${LUA_LIBRARY_DIRS} LDFLAGS: ${LUA_LDFLAGS} CFLAGS: ${LUA_CFLAGS}")
433         set(HAVE_LIBLUA 1 "Have liblua")
434         set(HAVE_LUA_H  1 "Have liblua header")
435 else()
436         unset(HAVE_LIBLUA)
437         unset(HAVE_LUA_H)
438 endif()
440 if(WITH_FAM)
441         check_include_files(fam.h HAVE_FAM_H)
442         check_library_exists(fam FAMOpen2 "" HAVE_LIBFAM)
443         if(HAVE_LIBFAM)
444                 set(CMAKE_REQUIRED_LIBRARIES fam)
445                 check_function_exists(FAMNoExists HAVE_FAMNOEXISTS)
446         endif()
447 else()
448         unset(HAVE_FAM_H)
449         unset(HAVE_LIBFAM)
450         unset(HAVE_FAMNOEXISTS)
451 endif()
453 if(WITH_GDBM)
454         check_include_files(gdbm.h HAVE_GDBM_H)
455         check_library_exists(gdbm gdbm_open "" HAVE_GDBM)
456 else()
457         unset(HAVE_GDBM_H)
458         unset(HAVE_GDBM)
459 endif()
461 if(WITH_MEMCACHED)
462         check_include_files(libmemcached/memcached.h HAVE_LIBMEMCACHED_MEMCACHED_H)
463         check_library_exists(memcached memcached "" HAVE_LIBMEMCACHED)
464         if(HAVE_LIBMEMCACHED_MEMCACHED_H AND HAVE_LIBMEMCACHED)
465                 set(USE_MEMCACHED 1)
466         else()
467                 message(FATAL_ERROR "didn't find libmemcached")
468         endif()
469 endif()
471 if(WITH_GEOIP)
472         check_library_exists(geoip GeoIP_country_name_by_addr "" HAVE_GEOIP)
473 endif()
475 if(NOT BUILD_STATIC)
476         check_include_files(dlfcn.h HAVE_DLFCN_H)
477 else()
478         unset(HAVE_DLFCN_H)
479 endif()
481 if(HAVE_DLFCN_H)
482         check_library_exists(dl dlopen "" HAVE_LIBDL)
483 else()
484         unset(HAVE_LIBDL)
485 endif()
487 set(LIGHTTPD_VERSION_ID 10400)
488 set(PACKAGE_NAME "${CMAKE_PROJECT_NAME}")
489 set(PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}")
491 if(NOT SBINDIR)
492         set(SBINDIR "sbin")
493 endif()
495 if(NOT LIGHTTPD_MODULES_DIR)
496         set(LIGHTTPD_MODULES_DIR "lib${LIB_SUFFIX}/lighttpd")
497 endif()
499 if(NOT WIN32)
500         set(LIGHTTPD_LIBRARY_DIR "${CMAKE_INSTALL_PREFIX}/${LIGHTTPD_MODULES_DIR}")
501 else()
502         ## We use relative path in windows
503         set(LIGHTTPD_LIBRARY_DIR "lib")
504 endif()
506 ## Write out config.h
507 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
509 add_definitions(-DHAVE_CONFIG_H)
511 include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
513 set(COMMON_SRC
514         base64.c buffer.c log.c
515         keyvalue.c chunk.c
516         http_chunk.c stream.c fdevent.c
517         stat_cache.c plugin.c joblist.c etag.c array.c
518         data_string.c data_array.c
519         data_integer.c md5.c data_fastcgi.c
520         vector.c
521         fdevent_select.c fdevent_libev.c
522         fdevent_poll.c fdevent_linux_sysepoll.c
523         fdevent_solaris_devpoll.c fdevent_solaris_port.c
524         fdevent_freebsd_kqueue.c
525         data_config.c
526         inet_ntop_cache.c crc32.c
527         connections-glue.c
528         configfile-glue.c
529         http-header-glue.c
530         http_auth.c
531         splaytree.c network_writev.c
532         network_write_mmap.c network_write_no_mmap.c
533         network_write.c network_linux_sendfile.c
534         network_freebsd_sendfile.c
535         network_solaris_sendfilev.c network_openssl.c
536         rand.c
537         status_counter.c safe_memclear.c network_darwin_sendfile.c
540 if(WIN32)
541         message(STATUS "Adding local getopt implementation.")
542         set(COMMON_SRC ${COMMON_SRC} xgetopt.c)
543 endif()
545 add_executable(lemon lemon.c)
547 ## Build parsers by using lemon...
548 lemon_parser(configparser.y)
549 lemon_parser(mod_ssi_exprparser.y)
551 set(L_INSTALL_TARGETS)
553 add_executable(lighttpd-angel lighttpd-angel.c)
554 set(L_INSTALL_TARGETS ${L_INSTALL_TARGETS} lighttpd-angel)
555 add_target_properties(lighttpd-angel COMPILE_FLAGS "-DSBIN_DIR=\\\\\"${CMAKE_INSTALL_PREFIX}/${SBINDIR}\\\\\"")
557 add_executable(lighttpd
558         server.c
559         response.c
560         connections.c
561         network.c
562         configfile.c
563         configparser.c
564         request.c
565         proc_open.c
566         ${COMMON_SRC}
568 set(L_INSTALL_TARGETS ${L_INSTALL_TARGETS} lighttpd)
570 add_and_install_library(mod_access mod_access.c)
571 add_and_install_library(mod_accesslog mod_accesslog.c)
572 add_and_install_library(mod_alias mod_alias.c)
573 add_and_install_library(mod_auth "mod_auth.c")
574 add_and_install_library(mod_authn_file "mod_authn_file.c")
575 if(NOT WIN32)
576         add_and_install_library(mod_cgi mod_cgi.c)
577 endif()
578 add_and_install_library(mod_compress mod_compress.c)
579 add_and_install_library(mod_deflate mod_deflate.c)
580 add_and_install_library(mod_dirlisting mod_dirlisting.c)
581 add_and_install_library(mod_evasive mod_evasive.c)
582 add_and_install_library(mod_evhost mod_evhost.c)
583 add_and_install_library(mod_expire mod_expire.c)
584 add_and_install_library(mod_extforward mod_extforward.c)
585 add_and_install_library(mod_fastcgi mod_fastcgi.c)
586 add_and_install_library(mod_flv_streaming mod_flv_streaming.c)
587 add_and_install_library(mod_indexfile mod_indexfile.c)
588 add_and_install_library(mod_proxy mod_proxy.c)
589 add_and_install_library(mod_redirect mod_redirect.c)
590 add_and_install_library(mod_rewrite mod_rewrite.c)
591 add_and_install_library(mod_rrdtool mod_rrdtool.c)
592 add_and_install_library(mod_scgi mod_scgi.c)
593 add_and_install_library(mod_secdownload mod_secdownload.c)
594 add_and_install_library(mod_setenv mod_setenv.c)
595 add_and_install_library(mod_simple_vhost mod_simple_vhost.c)
596 add_and_install_library(mod_ssi "mod_ssi_exprparser.c;mod_ssi_expr.c;mod_ssi.c")
597 add_and_install_library(mod_staticfile mod_staticfile.c)
598 add_and_install_library(mod_status mod_status.c)
599 add_and_install_library(mod_uploadprogress mod_uploadprogress.c)
600 add_and_install_library(mod_userdir mod_userdir.c)
601 add_and_install_library(mod_usertrack mod_usertrack.c)
602 add_and_install_library(mod_webdav mod_webdav.c)
604 add_executable(test_buffer
605         test_buffer.c
606         buffer.c
608 add_test(NAME test_buffer COMMAND test_buffer)
610 add_executable(test_base64
611         test_base64.c
612         buffer.c
613         base64.c
615 add_test(NAME test_base64 COMMAND test_base64)
617 add_executable(test_configfile
618         test_configfile.c
619         buffer.c
620         array.c
621         data_string.c
622         keyvalue.c
623         vector.c
624         log.c
626 add_test(NAME test_configfile COMMAND test_configfile)
628 if(HAVE_PCRE_H)
629         target_link_libraries(lighttpd ${PCRE_LDFLAGS})
630         add_target_properties(lighttpd COMPILE_FLAGS ${PCRE_CFLAGS})
631         target_link_libraries(mod_rewrite ${PCRE_LDFLAGS})
632         add_target_properties(mod_rewrite COMPILE_FLAGS ${PCRE_CFLAGS})
633         target_link_libraries(mod_dirlisting ${PCRE_LDFLAGS})
634         add_target_properties(mod_dirlisting COMPILE_FLAGS ${PCRE_CFLAGS})
635         target_link_libraries(mod_redirect ${PCRE_LDFLAGS})
636         add_target_properties(mod_redirect COMPILE_FLAGS ${PCRE_CFLAGS})
637         target_link_libraries(test_configfile ${PCRE_LDFLAGS})
638         add_target_properties(test_configfile COMPILE_FLAGS ${PCRE_CFLAGS})
639 endif()
641 if(WITH_PCRE AND (WITH_MEMCACHED OR WITH_GDBM))
642         add_and_install_library(mod_trigger_b4_dl mod_trigger_b4_dl.c)
643         target_link_libraries(mod_trigger_b4_dl ${PCRE_LDFLAGS})
644         add_target_properties(mod_trigger_b4_dl COMPILE_FLAGS ${PCRE_CFLAGS})
645 endif()
647 if(WITH_LUA)
648         add_and_install_library(mod_magnet "mod_magnet.c;mod_magnet_cache.c")
649         target_link_libraries(mod_magnet ${LUA_LDFLAGS})
650         add_target_properties(mod_magnet COMPILE_FLAGS ${LUA_CFLAGS})
652         add_and_install_library(mod_cml "mod_cml.c;mod_cml_lua.c;mod_cml_funcs.c")
653         target_link_libraries(mod_cml ${LUA_LDFLAGS})
654         add_target_properties(mod_cml COMPILE_FLAGS ${LUA_CFLAGS})
655 endif()
657 if(WITH_GEOIP)
658         add_and_install_library(mod_geoip mod_geoip.c)
659         target_link_libraries(mod_geoip GeoIP)
660 endif()
662 if(HAVE_MYSQL_H AND HAVE_MYSQL)
663         add_and_install_library(mod_mysql_vhost "mod_mysql_vhost.c")
664         target_link_libraries(mod_mysql_vhost mysqlclient)
665         include_directories(/usr/include/mysql)
667         add_and_install_library(mod_authn_mysql "mod_authn_mysql.c")
668         set(L_MOD_AUTHN_MYSQL)
669         if(HAVE_LIBCRYPT)
670                 set(L_MOD_AUTHN_MYSQL ${L_MOD_AUTHN_MYSQL} crypt)
671         endif()
672         target_link_libraries(mod_authn_mysql ${L_MOD_AUTHN_MYSQL} mysqlclient)
673 endif()
675 set(L_MOD_WEBDAV)
676 if(HAVE_SQLITE3_H)
677         set(L_MOD_WEBDAV ${L_MOD_WEBDAV} sqlite3)
678 endif()
679 if(HAVE_LIBXML_H)
680         target_link_libraries(mod_webdav ${XML2_LDFLAGS})
681 endif()
682 if(HAVE_UUID_H)
683         if(NEED_LIBUUID)
684                 set(L_MOD_WEBDAV ${L_MOD_WEBDAV} uuid)
685         endif()
686 endif()
688 target_link_libraries(mod_webdav ${L_MOD_WEBDAV})
690 set(L_MOD_AUTHN_FILE)
691 if(HAVE_LIBCRYPT)
692         set(L_MOD_AUTHN_FILE ${L_MOD_AUTHN_FILE} crypt)
693 endif()
694 target_link_libraries(mod_authn_file ${L_MOD_AUTHN_FILE})
696 if(WITH_KRB5)
697         check_library_exists(krb5 krb5_init_context "" HAVE_KRB5)
698         add_and_install_library(mod_authn_gssapi "mod_authn_gssapi.c")
699         set(L_MOD_AUTHN_GSSAPI ${L_MOD_AUTHN_GSSAPI} krb5 gssapi_krb5)
700         target_link_libraries(mod_authn_gssapi ${L_MOD_AUTHN_GSSAPI})
701 endif()
703 if(WITH_LDAP)
704         add_and_install_library(mod_authn_ldap "mod_authn_ldap.c")
705         set(L_MOD_AUTHN_LDAP ${L_MOD_AUTHN_LDAP} ldap lber)
706         target_link_libraries(mod_authn_ldap ${L_MOD_AUTHN_LDAP})
707 endif()
709 if(HAVE_ZLIB_H)
710         if(HAVE_BZLIB_H)
711                 target_link_libraries(mod_compress ${ZLIB_LIBRARY} bz2)
712                 target_link_libraries(mod_deflate ${ZLIB_LIBRARY} bz2)
713         else()
714                 target_link_libraries(mod_compress ${ZLIB_LIBRARY})
715                 target_link_libraries(mod_deflate ${ZLIB_LIBRARY})
716         endif()
717 endif()
719 if(HAVE_LIBFAM)
720         target_link_libraries(lighttpd fam)
721 endif()
723 if(HAVE_GDBM_H)
724         target_link_libraries(mod_trigger_b4_dl gdbm)
725 endif()
727 if(WITH_MEMCACHED)
728         target_link_libraries(mod_trigger_b4_dl memcached)
729 endif()
731 if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang")
732         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wall -g -Wshadow -W -pedantic ${WARN_CFLAGS}")
733         set(CMAKE_C_FLAGS_RELEASE        "${CMAKE_C_FLAGS_RELEASE}     -O2")
734         set(CMAKE_C_FLAGS_DEBUG          "${CMAKE_C_FLAGS_DEBUG}       -O0")
735         set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_WITHDEBINFO} -O2")
736         set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${WARN_LDFLAGS}")
737         set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${WARN_LDFLAGS}")
738 endif()
740 if((NOT APPLE) OR CMAKE_C_COMPILER_ID MATCHES "GNU")
741         add_target_properties(lighttpd LINK_FLAGS "-Wl,-export-dynamic")
742 endif()
744 set_target_properties(lighttpd PROPERTIES CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
746 if(WIN32)
747         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNVALGRIND")
748         add_target_properties(lighttpd COMPILE_FLAGS "-DLI_DECLARE_EXPORTS")
749         target_link_libraries(lighttpd ws2_32)
750         target_link_libraries(mod_proxy ws2_32)
751         target_link_libraries(mod_fcgi ws2_32)
752         target_link_libraries(mod_scgi ws2_32)
753         target_link_libraries(mod_ssi ws2_32)
755         if(MINGW)
756                 target_link_libraries(lighttpd msvcr70)
757                 add_target_properties(lighttpd LINK_FLAGS "-Wl,-subsystem,console")
758         endif()
759 endif()
761 if(NOT BUILD_STATIC)
762         if(HAVE_LIBDL)
763                 target_link_libraries(lighttpd dl)
764         endif()
765 endif()
767 if(HAVE_LIBSSL AND HAVE_LIBCRYPTO)
768         target_link_libraries(lighttpd ssl)
769         target_link_libraries(lighttpd crypto)
770 endif()
772 if(WITH_LIBEV)
773         target_link_libraries(lighttpd ${LIBEV_LDFLAGS})
774         add_target_properties(lighttpd COMPILE_FLAGS ${LIBEV_CFLAGS})
775 endif()
777 if(WITH_LIBUNWIND)
778         target_link_libraries(lighttpd ${LIBUNWIND_LDFLAGS})
779         add_target_properties(lighttpd COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
781         target_link_libraries(test_buffer ${LIBUNWIND_LDFLAGS})
782         add_target_properties(test_buffer COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
783         target_link_libraries(test_base64 ${LIBUNWIND_LDFLAGS})
784         add_target_properties(test_base64 COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
785         target_link_libraries(test_configfile ${PCRE_LDFLAGS} ${LIBUNWIND_LDFLAGS})
786         add_target_properties(test_configfile COMPILE_FLAGS ${PCRE_CFLAGS} ${LIBUNWIND_CFLAGS})
787 endif()
789 if(NOT WIN32)
790 install(TARGETS ${L_INSTALL_TARGETS}
791         RUNTIME DESTINATION ${SBINDIR}
792         LIBRARY DESTINATION ${LIGHTTPD_MODULES_DIR}
793         ARCHIVE DESTINATION ${LIGHTTPD_MODULES_DIR}/static)
794 else()
795 ## HACK to make win32 to install our libraries in desired directory..
796 install(TARGETS lighttpd
797         RUNTIME DESTINATION ${SBINDIR}
798         ARCHIVE DESTINATION lib/static)
799 list(REMOVE_ITEM L_INSTALL_TARGETS lighttpd)
800 install(TARGETS ${L_INSTALL_TARGETS}
801         RUNTIME DESTINATION ${SBINDIR}/lib
802         LIBRARY DESTINATION lib
803         ARCHIVE DESTINATION lib/static)
804 endif()