[config] server.bsd-accept-filter option
[lighttpd.git] / src / CMakeLists.txt
blobb89b2dd75147936b1d4c7ccea128463afb096c8b
1 include(CheckCSourceCompiles)
2 include(CheckIncludeFiles)
3 include(CheckFunctionExists)
4 include(CheckVariableExists)
5 include(CheckTypeSize)
6 include(CheckLibraryExists)
7 include(CMakeDetermineCCompiler)
8 include(FindThreads)
9 include(FindPkgConfig)
11 include(LighttpdMacros)
13 add_definitions(-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGE_FILES)
15 option(WITH_XATTR "with xattr-support for the stat-cache [default: off]")
16 option(WITH_MYSQL "with mysql-support for the mod_sql_vhost [default: off]")
17 # option(WITH_POSTGRESQL "with postgress-support for the mod_sql_vhost [default: off]")
18 option(WITH_OPENSSL "with openssl-support [default: off]")
19 option(WITH_PCRE "with regex support [default: on]" ON)
20 option(WITH_WEBDAV_PROPS "with property-support for mod_webdav [default: off]")
21 option(WITH_WEBDAV_LOCKS "locks in webdav [default: off]")
22 option(WITH_BZIP "with bzip2-support for mod_compress [default: off]")
23 option(WITH_ZLIB "with deflate-support for mod_compress [default: on]" ON)
24 option(WITH_LDAP "with LDAP-support for the mod_auth [default: off]")
25 option(WITH_LUA "with lua 5.1 for mod_magnet [default: off]")
26 # option(WITH_VALGRIND "with internal support for valgrind [default: off]")
27 # option(WITH_KERBEROS5 "use Kerberos5 support with OpenSSL [default: off]")
28 option(WITH_FAM "fam/gamin for reducing number of stat() calls [default: off]")
29 option(WITH_GDBM "gdbm storage for mod_trigger_b4_dl [default: off]")
30 option(WITH_MEMCACHED "memcached storage for mod_trigger_b4_dl [default: off]")
31 option(WITH_LIBEV "libev support for fdevent handlers [default: off]")
32 option(WITH_LIBUNWIND "with libunwind to print backtraces in asserts [default: off]")
34 if(CMAKE_COMPILER_IS_GNUCC)
35         option(BUILD_EXTRA_WARNINGS "extra warnings")
37         if(BUILD_EXTRA_WARNINGS)
38                 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")
39                 set(WARN_LDFLAGS "-Wl,--as-needed")
40                 # -Werror -Wbad-function-cast -Wmissing-prototypes
41         endif()
42 endif()
44 option(BUILD_STATIC "build a static lighttpd with all modules added")
46 if(BUILD_STATIC)
47         set(LIGHTTPD_STATIC 1)
48 elseif(APPLE)
49         set(CMAKE_SHARED_MODULE_PREFIX "")
50 else()
51         set(CMAKE_SHARED_LIBRARY_PREFIX "")
52 endif()
54 if(WITH_LIBEV)
55         find_package(LibEV REQUIRED)
56         set(HAVE_LIBEV 1)
57 endif()
59 if(WITH_LIBUNWIND)
60         pkg_check_modules(LIBUNWIND REQUIRED libunwind)
61         set(HAVE_LIBUNWIND 1)
62 endif()
64 if(WITH_WEBDAV_PROPS)
65         set(WITH_XML 1)
66         set(WITH_SQLITE3 1)
67         set(WITH_UUID 1)
68 endif()
70 check_include_files(sys/devpoll.h HAVE_SYS_DEVPOLL_H)
71 check_include_files(sys/epoll.h HAVE_SYS_EPOLL_H)
72 check_include_files(sys/event.h HAVE_SYS_EVENT_H)
73 check_include_files(sys/mman.h HAVE_SYS_MMAN_H)
74 check_include_files(sys/poll.h HAVE_SYS_POLL_H)
75 check_include_files(sys/port.h HAVE_SYS_PORT_H)
76 check_include_files(sys/prctl.h HAVE_SYS_PRCTL_H)
77 check_include_files(sys/resource.h HAVE_SYS_RESOURCE_H)
78 check_include_files(sys/sendfile.h HAVE_SYS_SENDFILE_H)
79 check_include_files(sys/select.h HAVE_SYS_SELECT_H)
80 check_include_files(sys/types.h HAVE_SYS_TYPES_H)
81 check_include_files(sys/uio.h HAVE_SYS_UIO_H)
82 check_include_files(sys/un.h HAVE_SYS_UN_H)
83 check_include_files(sys/wait.h HAVE_SYS_WAIT_H)
84 check_include_files(sys/time.h HAVE_SYS_TIME_H)
85 check_include_files(unistd.h HAVE_UNISTD_H)
86 check_include_files(pthread.h HAVE_PTHREAD_H)
87 check_include_files(getopt.h HAVE_GETOPT_H)
88 check_include_files(inttypes.h HAVE_INTTYPES_H)
89 check_include_files(poll.h HAVE_POLL_H)
90 check_include_files(pwd.h HAVE_PWD_H)
91 check_include_files(stddef.h HAVE_STDDEF_H)
92 check_include_files(stdint.h HAVE_STDINT_H)
93 check_include_files(syslog.h HAVE_SYSLOG_H)
95 # check for fastcgi lib, for the tests only
96 check_include_files(fastcgi.h HAVE_FASTCGI_H)
97 check_include_files(fastcgi/fastcgi.h HAVE_FASTCGI_FASTCGI_H)
99 # will be needed for auth
100 check_include_files(crypt.h HAVE_CRYPT_H)
101 # check if we need libcrypt for crypt_r()
102 check_library_exists(crypt crypt_r "" HAVE_LIBCRYPT_CRYPT_R)
103 if(HAVE_LIBCRYPT_CRYPT_R)
104         set(HAVE_CRYPT_R 1)
105         set(HAVE_LIBCRYPT 1)
106 else()
107         check_library_exists(crypt crypt "" HAVE_LIBCRYPT)
108 endif()
109 check_function_exists(crypt_r HAVE_CRYPT_R)
110 check_function_exists(crypt HAVE_CRYPT)
112 check_include_files(sys/inotify.h HAVE_SYS_INOTIFY_H)
113 if(HAVE_SYS_INOTIFY_H)
114         check_function_exists(inotify_init HAVE_INOTIFY_INIT)
115 endif()
117 set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
118 check_type_size(socklen_t HAVE_SOCKLEN_T)
119 set(CMAKE_EXTRA_INCLUDE_FILES)
121 check_type_size(long SIZEOF_LONG)
122 check_type_size(off_t SIZEOF_OFF_T)
124 check_function_exists(chroot HAVE_CHROOT)
125 check_function_exists(epoll_ctl HAVE_EPOLL_CTL)
126 check_function_exists(fork HAVE_FORK)
127 check_function_exists(getrlimit HAVE_GETRLIMIT)
128 check_function_exists(getuid HAVE_GETUID)
129 check_function_exists(gmtime_r HAVE_GMTIME_R)
130 check_function_exists(inet_ntop HAVE_INET_NTOP)
131 check_function_exists(kqueue HAVE_KQUEUE)
132 check_function_exists(localtime_r HAVE_LOCALTIME_R)
133 check_function_exists(lstat HAVE_LSTAT)
134 check_function_exists(madvise HAVE_MADVISE)
135 check_function_exists(memcpy HAVE_MEMCPY)
136 check_function_exists(memset HAVE_MEMSET)
137 check_function_exists(mmap HAVE_MMAP)
138 check_function_exists(pathconf HAVE_PATHCONF)
139 check_function_exists(poll HAVE_POLL)
140 check_function_exists(port_create HAVE_PORT_CREATE)
141 check_function_exists(prctl HAVE_PRCTL)
142 check_function_exists(pread HAVE_PREAD)
143 check_function_exists(posix_fadvise HAVE_POSIX_FADVISE)
144 check_function_exists(select HAVE_SELECT)
145 check_function_exists(sendfile HAVE_SENDFILE)
146 check_function_exists(send_file HAVE_SEND_FILE)
147 check_function_exists(sendfile64 HAVE_SENDFILE64)
148 check_function_exists(sendfilev HAVE_SENDFILEV)
149 check_function_exists(sigaction HAVE_SIGACTION)
150 check_function_exists(signal HAVE_SIGNAL)
151 check_function_exists(sigtimedwait HAVE_SIGTIMEDWAIT)
152 check_function_exists(strptime HAVE_STRPTIME)
153 check_function_exists(syslog HAVE_SYSLOG)
154 check_function_exists(writev HAVE_WRITEV)
155 check_function_exists(inet_aton HAVE_INET_ATON)
156 check_function_exists(issetugid HAVE_ISSETUGID)
157 check_function_exists(inet_pton HAVE_INET_PTON)
158 check_function_exists(memset_s HAVE_MEMSET_S)
159 check_function_exists(explicit_bzero HAVE_EXPLICIT_BZERO)
160 check_c_source_compiles("
161         #include <sys/types.h>
162         #include <sys/socket.h>
163         #include <netinet/in.h>
165         int main() {
166                 struct sockaddr_in6 s; struct in6_addr t=in6addr_any; int i=AF_INET6; s; t.s6_addr[0] = 0;
167                 return 0;
168         }" HAVE_IPV6)
169 check_c_source_compiles("
170         __attribute__((weak)) void __dummy(void *x) { }
171         int main() {
172                 void *x;
173                 __dummy(x);
174         }
175         " HAVE_WEAK_SYMBOLS)
177 ## refactor me
178 macro(XCONFIG _package _include_DIR _link_DIR _link_FLAGS _cflags)
179 # reset the variables at the beginning
180         set(${_include_DIR})
181         set(${_link_DIR})
182         set(${_link_FLAGS})
183         set(${_cflags})
185         find_program(${_package}CONFIG_EXECUTABLE NAMES ${_package} PATHS /usr/local/bin )
187         # if pkg-config has been found
188         if(${_package}CONFIG_EXECUTABLE)
189                 set(XCONFIG_EXECUTABLE "${${_package}CONFIG_EXECUTABLE}")
190                 message(STATUS "found ${_package}: ${XCONFIG_EXECUTABLE}")
192                 exec_program(${XCONFIG_EXECUTABLE} ARGS --libs OUTPUT_VARIABLE __link_FLAGS)
193                 string(REPLACE "\n" "" ${_link_FLAGS} ${__link_FLAGS})
194                 exec_program(${XCONFIG_EXECUTABLE} ARGS --cflags OUTPUT_VARIABLE __cflags)
195                 string(REPLACE "\n" "" ${_cflags} ${__cflags})
196         else()
197                 message(STATUS "found ${_package}: no")
198         endif()
199 endmacro(XCONFIG _package _include_DIR _link_DIR _link_FLAGS _cflags)
201 if(WITH_XATTR)
202         check_include_files(attr/attributes.h HAVE_ATTR_ATTRIBUTES_H)
203         if(HAVE_ATTR_ATTRIBUTES_H)
204                 check_library_exists(attr attr_get "" HAVE_XATTR)
205         endif()
206 else()
207         unset(HAVE_ATTR_ATTRIBUTES_H)
208         unset(HAVE_XATTR)
209 endif()
211 if(WITH_MYSQL)
212         xconfig(mysql_config MYSQL_INCDIR MYSQL_LIBDIR MYSQL_LDFLAGS MYSQL_CFLAGS)
214         set(CMAKE_REQUIRED_INCLUDES /usr/include/mysql)
215         check_include_files(mysql.h HAVE_MYSQL_H)
216         set(CMAKE_REQUIRED_INCLUDES)
217         if(HAVE_MYSQL_H)
218                 check_library_exists(mysqlclient mysql_real_connect "" HAVE_MYSQL)
219         endif()
220 else()
221         unset(HAVE_MYSQL_H)
222         unset(HAVE_MYSQL)
223 endif()
225 if(WITH_OPENSSL)
226         if(APPLE)
227                 set(CMAKE_REQUIRED_INCLUDES /opt/local/include)
228         endif()
229         check_include_files(openssl/ssl.h HAVE_OPENSSL_SSL_H)
230         if(APPLE)
231                 set(CMAKE_REQUIRED_INCLUDES)
232         endif()
233         if(HAVE_OPENSSL_SSL_H)
234                 check_library_exists(crypto BIO_f_base64 "" HAVE_LIBCRYPTO)
235                 if(HAVE_LIBCRYPTO)
236                         check_library_exists(ssl SSL_new "" HAVE_LIBSSL)
237                 endif()
238         endif()
239 else()
240         unset(HAVE_OPENSSL_SSL_H)
241         unset(HAVE_LIBCRYPTO)
242         unset(HAVE_LIBSSL)
243 endif()
245 if(WITH_PCRE)
246         ## if we have pcre-config, use it
247         xconfig(pcre-config PCRE_INCDIR PCRE_LIBDIR PCRE_LDFLAGS PCRE_CFLAGS)
248         if(PCRE_LDFLAGS OR PCRE_CFLAGS)
249                 message(STATUS "found pcre at: LDFLAGS: ${PCRE_LDFLAGS} CFLAGS: ${PCRE_CFLAGS}")
251                 if(NOT PCRE_CFLAGS STREQUAL "\n")
252                         ## if it is empty we'll get newline returned
253                         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PCRE_CFLAGS}")
254                 endif()
256                 set(HAVE_PCRE_H 1)
257                 set(HAVE_LIBPCRE 1)
258         else()
259                 if(NOT WIN32)
260                         check_include_files(pcre.h HAVE_PCRE_H)
261                         check_library_exists(pcre pcre_exec "" HAVE_LIBPCRE)
262                         set(PCRE_LDFLAGS -lpcre)
263                 else()
264                         find_path(PCRE_INCLUDE_DIR pcre.h
265                         /usr/local/include
266                         /usr/include
267                         )
269                         set(PCRE_NAMES pcre)
270                         find_library(PCRE_LIBRARY
271                         NAMES ${PCRE_NAMES}
272                         PATHS /usr/lib /usr/local/lib
273                         )
275                         if(PCRE_INCLUDE_DIR AND PCRE_LIBRARY)
276                                 set(CMAKE_REQUIRED_INCLUDES ${PCRE_INCLUDE_DIR})
277                                 set(CMAKE_REQUIRED_LIBRARIES ${PCRE_LIBRARY})
278                                 check_include_files(pcre.h HAVE_PCRE_H)
279                                 check_library_exists(pcre pcre_exec "" HAVE_LIBPCRE)
280                                 set(CMAKE_REQUIRED_INCLUDES)
281                                 set(CMAKE_REQUIRED_LIBRARIES)
282                                 include_directories(${PCRE_INCLUDE_DIR})
283                         endif()
284                 endif()
285         endif()
287         if(NOT HAVE_PCRE_H)
288                 message(FATAL_ERROR "pcre.h couldn't be found")
289         endif()
290         if(NOT HAVE_LIBPCRE)
291                 message(FATAL_ERROR "libpcre couldn't be found")
292         endif()
293 else()
294         unset(HAVE_PCRE_H)
295         unset(HAVE_LIBPCRE)
296 endif()
299 if(WITH_XML)
300         xconfig(xml2-config XML2_INCDIR XML2_LIBDIR XML2_LDFLAGS XML2_CFLAGS)
301         if(XML2_LDFLAGS OR XML2_CFLAGS)
302                 message(STATUS "found xml2 at: LDFLAGS: ${XML2_LDFLAGS} CFLAGS: ${XML2_CFLAGS}")
304                 ## if it is empty we'll get newline returned
305                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${XML2_CFLAGS}")
307                 check_include_files(libxml/tree.h HAVE_LIBXML_H)
309                 set(CMAKE_REQUIRED_FLAGS ${XML2_LDFLAGS})
310                 check_library_exists(xml2 xmlParseChunk "" HAVE_LIBXML)
311                 set(CMAKE_REQUIRED_FLAGS)
312         else()
313                 check_include_files(libxml.h HAVE_LIBXML_H)
314                 check_library_exists(xml2 xmlParseChunk "" HAVE_LIBXML)
315         endif()
317         if(NOT HAVE_LIBXML_H)
318                 message(FATAL_ERROR "libxml/tree.h couldn't be found")
319         endif()
320         if(NOT HAVE_LIBXML)
321                 message(FATAL_ERROR "libxml2 couldn't be found")
322         endif()
323 else()
324         unset(HAVE_LIBXML_H)
325         unset(HAVE_LIBXML)
326 endif()
328 if(WITH_SQLITE3)
329         check_include_files(sqlite3.h HAVE_SQLITE3_H)
330         check_library_exists(sqlite3 sqlite3_reset "" HAVE_SQLITE3)
331 else()
332         unset(HAVE_SQLITE3_H)
333         unset(HAVE_SQLITE3)
334 endif()
336 if(WITH_UUID)
337         check_include_files(uuid/uuid.h HAVE_UUID_UUID_H)
338         check_library_exists(uuid uuid_generate "" NEED_LIBUUID)
339         if(NOT NEED_LIBUUID)
340                 check_function_exists(uuid_generate HAVE_LIBUUID)
341         else()
342                 set(HAVE_LIBUUID 1)
343         endif()
344 else()
345         unset(HAVE_UUID_UUID_H)
346         unset(NEED_LIBUUID)
347         unset(HAVE_LIBUUID)
348 endif()
350 if(WITH_ZLIB)
351         if(NOT WIN32)
352                 check_include_files(zlib.h HAVE_ZLIB_H)
353                 check_library_exists(z deflate "" HAVE_LIBZ)
354                 set(ZLIB_LIBRARY z)
355         else()
356                 find_path(ZLIB_INCLUDE_DIR zlib.h
357                         /usr/local/include
358                         /usr/include
359                 )
361                 set(ZLIB_NAMES z zlib zdll)
362                         find_library(ZLIB_LIBRARY
363                         NAMES ${ZLIB_NAMES}
364                         PATHS /usr/lib /usr/local/lib
365                 )
367                 if(ZLIB_INCLUDE_DIR AND ZLIB_LIBRARY)
368                         set(CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIR})
369                         set(CMAKE_REQUIRED_LIBRARIES ${ZLIB_LIBRARY})
370                         get_filename_component(ZLIB_NAME ${ZLIB_LIBRARY} NAME)
371                         check_include_files(zlib.h HAVE_ZLIB_H)
372                         check_library_exists(${ZLIB_NAME} deflate "" HAVE_LIBZ)
373                         set(CMAKE_REQUIRED_INCLUDES)
374                         set(CMAKE_REQUIRED_LIBRARIES)
375                         include_directories(${ZLIB_INCLUDE_DIR})
376                 endif()
377         endif()
378 else()
379         unset(HAVE_ZLIB_H)
380         unset(HAVE_LIBZ)
381         unset(ZLIB_INCLUDE_DIR)
382         unset(ZLIB_LIBRARY)
383 endif()
385 if(WITH_BZIP)
386         check_include_files(bzlib.h HAVE_BZLIB_H)
387         check_library_exists(bz2 BZ2_bzCompress "" HAVE_LIBBZ2)
388 else()
389         unset(HAVE_BZLIB_H)
390         unset(HAVE_LIBBZ2)
391 endif()
393 if(WITH_LDAP)
394         check_include_files(ldap.h HAVE_LDAP_H)
395         check_library_exists(ldap ldap_bind "" HAVE_LIBLDAP)
396         check_include_files(lber.h HAVE_LBER_H)
397         check_library_exists(lber ber_printf "" HAVE_LIBLBER)
398         set(LDAP_DEPRECATED 1) # Using deprecated ldap api
399 else()
400         unset(HAVE_LDAP_H)
401         unset(HAVE_LIBLDAP)
402         unset(HAVE_LBER_H)
403         unset(HAVE_LIBLBER)
404 endif()
406 if(WITH_LUA)
407         pkg_search_module(LUA REQUIRED lua5.3 lua-5.3 lua5.2 lua-5.2 lua5.1 lua-5.1 lua)
408         message(STATUS "found lua at: INCDIR: ${LUA_INCLUDE_DIRS} LIBDIR: ${LUA_LIBRARY_DIRS} LDFLAGS: ${LUA_LDFLAGS} CFLAGS: ${LUA_CFLAGS}")
409         set(HAVE_LIBLUA 1 "Have liblua")
410         set(HAVE_LUA_H  1 "Have liblua header")
411 else()
412         unset(HAVE_LIBLUA)
413         unset(HAVE_LUA_H)
414 endif()
416 if(WITH_FAM)
417         check_include_files(fam.h HAVE_FAM_H)
418         check_library_exists(fam FAMOpen2 "" HAVE_LIBFAM)
419         if(HAVE_LIBFAM)
420                 set(CMAKE_REQUIRED_LIBRARIES fam)
421                 check_function_exists(FAMNoExists HAVE_FAMNOEXISTS)
422         endif()
423 else()
424         unset(HAVE_FAM_H)
425         unset(HAVE_LIBFAM)
426         unset(HAVE_FAMNOEXISTS)
427 endif()
429 if(WITH_GDBM)
430         check_include_files(gdbm.h HAVE_GDBM_H)
431         check_library_exists(gdbm gdbm_open "" HAVE_GDBM)
432 else()
433         unset(HAVE_GDBM_H)
434         unset(HAVE_GDBM)
435 endif()
437 if(WITH_MEMCACHED)
438         check_include_files(libmemcached/memcached.h HAVE_LIBMEMCACHED_MEMCACHED_H)
439         check_library_exists(memcached memcached "" HAVE_LIBMEMCACHED)
440         if(HAVE_LIBMEMCACHED_MEMCACHED_H AND HAVE_LIBMEMCACHED)
441                 set(USE_MEMCACHED 1)
442         else()
443                 message(FATAL_ERROR "didn't find libmemcached")
444         endif()
445 endif()
447 if(NOT BUILD_STATIC)
448         check_include_files(dlfcn.h HAVE_DLFCN_H)
449 else()
450         unset(HAVE_DLFCN_H)
451 endif()
453 if(HAVE_DLFCN_H)
454         check_library_exists(dl dlopen "" HAVE_LIBDL)
455 else()
456         unset(HAVE_LIBDL)
457 endif()
459 set(LIGHTTPD_VERSION_ID 10400)
460 set(PACKAGE_NAME "${CMAKE_PROJECT_NAME}")
461 set(PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}")
463 if(NOT SBINDIR)
464         set(SBINDIR "sbin")
465 endif()
467 if(NOT LIGHTTPD_MODULES_DIR)
468         set(LIGHTTPD_MODULES_DIR "lib${LIB_SUFFIX}/lighttpd")
469 endif()
471 if(NOT WIN32)
472         set(LIGHTTPD_LIBRARY_DIR "${CMAKE_INSTALL_PREFIX}/${LIGHTTPD_MODULES_DIR}")
473 else()
474         ## We use relative path in windows
475         set(LIGHTTPD_LIBRARY_DIR "lib")
476 endif()
478 ## Write out config.h
479 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
481 add_definitions(-DHAVE_CONFIG_H)
483 include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
485 set(COMMON_SRC
486         base64.c buffer.c log.c
487         keyvalue.c chunk.c
488         http_chunk.c stream.c fdevent.c
489         stat_cache.c plugin.c joblist.c etag.c array.c
490         data_string.c data_count.c data_array.c
491         data_integer.c md5.c data_fastcgi.c
492         vector.c
493         fdevent_select.c fdevent_libev.c
494         fdevent_poll.c fdevent_linux_sysepoll.c
495         fdevent_solaris_devpoll.c fdevent_solaris_port.c
496         fdevent_freebsd_kqueue.c
497         data_config.c
498         inet_ntop_cache.c crc32.c
499         connections-glue.c
500         configfile-glue.c
501         http-header-glue.c
502         splaytree.c network_writev.c
503         network_write_mmap.c network_write_no_mmap.c
504         network_write.c network_linux_sendfile.c
505         network_freebsd_sendfile.c
506         network_solaris_sendfilev.c network_openssl.c
507         status_counter.c safe_memclear.c network_darwin_sendfile.c
510 if(WIN32)
511         message(STATUS "Adding local getopt implementation.")
512         set(COMMON_SRC ${COMMON_SRC} xgetopt.c)
513 endif()
515 add_executable(lemon lemon.c)
517 ## Build parsers by using lemon...
518 lemon_parser(configparser.y)
519 lemon_parser(mod_ssi_exprparser.y)
521 set(L_INSTALL_TARGETS)
523 add_executable(lighttpd-angel lighttpd-angel.c)
524 set(L_INSTALL_TARGETS ${L_INSTALL_TARGETS} lighttpd-angel)
525 add_target_properties(lighttpd-angel COMPILE_FLAGS "-DSBIN_DIR=\\\\\"${CMAKE_INSTALL_PREFIX}/${SBINDIR}\\\\\"")
527 add_executable(lighttpd
528         server.c
529         response.c
530         connections.c
531         network.c
532         configfile.c
533         configparser.c
534         request.c
535         proc_open.c
536         ${COMMON_SRC}
538 set(L_INSTALL_TARGETS ${L_INSTALL_TARGETS} lighttpd)
540 add_and_install_library(mod_access mod_access.c)
541 add_and_install_library(mod_accesslog mod_accesslog.c)
542 add_and_install_library(mod_alias mod_alias.c)
543 add_and_install_library(mod_auth "mod_auth.c;http_auth.c")
544 if(NOT WIN32)
545         add_and_install_library(mod_cgi mod_cgi.c)
546 endif()
547 add_and_install_library(mod_cml "mod_cml.c;mod_cml_lua.c;mod_cml_funcs.c")
548 add_and_install_library(mod_compress mod_compress.c)
549 add_and_install_library(mod_dirlisting mod_dirlisting.c)
550 add_and_install_library(mod_evasive mod_evasive.c)
551 add_and_install_library(mod_evhost mod_evhost.c)
552 add_and_install_library(mod_expire mod_expire.c)
553 add_and_install_library(mod_extforward mod_extforward.c)
554 add_and_install_library(mod_fastcgi mod_fastcgi.c)
555 add_and_install_library(mod_flv_streaming mod_flv_streaming.c)
556 add_and_install_library(mod_indexfile mod_indexfile.c)
557 add_and_install_library(mod_magnet "mod_magnet.c;mod_magnet_cache.c")
558 add_and_install_library(mod_mysql_vhost mod_mysql_vhost.c)
559 add_and_install_library(mod_proxy mod_proxy.c)
560 add_and_install_library(mod_redirect mod_redirect.c)
561 add_and_install_library(mod_rewrite mod_rewrite.c)
562 add_and_install_library(mod_rrdtool mod_rrdtool.c)
563 add_and_install_library(mod_scgi mod_scgi.c)
564 add_and_install_library(mod_secdownload mod_secdownload.c)
565 add_and_install_library(mod_setenv mod_setenv.c)
566 add_and_install_library(mod_simple_vhost mod_simple_vhost.c)
567 add_and_install_library(mod_ssi "mod_ssi_exprparser.c;mod_ssi_expr.c;mod_ssi.c")
568 add_and_install_library(mod_staticfile mod_staticfile.c)
569 add_and_install_library(mod_status mod_status.c)
570 add_and_install_library(mod_trigger_b4_dl mod_trigger_b4_dl.c)
571 # add_and_install_library(mod_uploadprogress mod_uploadprogress.c)
572 add_and_install_library(mod_userdir mod_userdir.c)
573 add_and_install_library(mod_usertrack mod_usertrack.c)
574 add_and_install_library(mod_webdav mod_webdav.c)
576 add_executable(test_buffer
577         test_buffer.c
578         buffer.c
580 add_test(NAME test_buffer COMMAND test_buffer)
582 add_executable(test_base64
583         test_base64.c
584         buffer.c
585         base64.c
587 add_test(NAME test_base64 COMMAND test_base64)
589 add_executable(test_configfile
590         test_configfile.c
591         buffer.c
592         array.c
593         data_string.c
594         keyvalue.c
595         log.c
597 add_test(NAME test_configfile COMMAND test_configfile)
599 if(HAVE_PCRE_H)
600         target_link_libraries(lighttpd ${PCRE_LDFLAGS})
601         add_target_properties(lighttpd COMPILE_FLAGS ${PCRE_CFLAGS})
602         target_link_libraries(mod_rewrite ${PCRE_LDFLAGS})
603         add_target_properties(mod_rewrite COMPILE_FLAGS ${PCRE_CFLAGS})
604         target_link_libraries(mod_dirlisting ${PCRE_LDFLAGS})
605         add_target_properties(mod_dirlisting COMPILE_FLAGS ${PCRE_CFLAGS})
606         target_link_libraries(mod_redirect ${PCRE_LDFLAGS})
607         add_target_properties(mod_redirect COMPILE_FLAGS ${PCRE_CFLAGS})
608         target_link_libraries(mod_trigger_b4_dl ${PCRE_LDFLAGS})
609         add_target_properties(mod_trigger_b4_dl COMPILE_FLAGS ${PCRE_CFLAGS})
610         target_link_libraries(test_configfile ${PCRE_LDFLAGS})
611         add_target_properties(test_configfile COMPILE_FLAGS ${PCRE_CFLAGS})
612 endif()
614 target_link_libraries(mod_magnet ${LUA_LDFLAGS})
615 add_target_properties(mod_magnet COMPILE_FLAGS ${LUA_CFLAGS})
617 target_link_libraries(mod_cml ${LUA_LDFLAGS})
618 add_target_properties(mod_cml COMPILE_FLAGS ${LUA_CFLAGS})
620 if(HAVE_MYSQL_H AND HAVE_MYSQL)
621         target_link_libraries(mod_mysql_vhost mysqlclient)
622         include_directories(/usr/include/mysql)
623 endif()
625 set(L_MOD_WEBDAV)
626 if(HAVE_SQLITE3_H)
627         set(L_MOD_WEBDAV ${L_MOD_WEBDAV} sqlite3)
628 endif()
629 if(HAVE_LIBXML_H)
630         target_link_libraries(mod_webdav ${XML2_LDFLAGS})
631 endif()
632 if(HAVE_UUID_H)
633         if(NEED_LIBUUID)
634                 set(L_MOD_WEBDAV ${L_MOD_WEBDAV} uuid)
635         endif()
636 endif()
638 target_link_libraries(mod_webdav ${L_MOD_WEBDAV})
640 set(L_MOD_AUTH)
641 if(HAVE_LIBCRYPT)
642         set(L_MOD_AUTH ${L_MOD_AUTH} crypt)
643 endif()
645 if(HAVE_LDAP_H)
646         set(L_MOD_AUTH ${L_MOD_AUTH} ldap lber)
647 endif()
648 target_link_libraries(mod_auth ${L_MOD_AUTH})
650 if(HAVE_ZLIB_H)
651         if(HAVE_BZLIB_H)
652                 target_link_libraries(mod_compress ${ZLIB_LIBRARY} bz2)
653         else()
654                 target_link_libraries(mod_compress ${ZLIB_LIBRARY})
655         endif()
656 endif()
658 if(HAVE_LIBFAM)
659         target_link_libraries(lighttpd fam)
660 endif()
662 if(HAVE_GDBM_H)
663         target_link_libraries(mod_trigger_b4_dl gdbm)
664 endif()
666 if(WITH_MEMCACHED)
667         target_link_libraries(mod_trigger_b4_dl memcached)
668 endif()
670 if(CMAKE_COMPILER_IS_GNUCC)
671         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wall -g -Wshadow -W -pedantic ${WARN_CFLAGS}")
672         set(CMAKE_C_FLAGS_RELEASE        "${CMAKE_C_FLAGS_RELEASE}     -O2")
673         set(CMAKE_C_FLAGS_DEBUG          "${CMAKE_C_FLAGS_DEBUG}       -O0")
674         set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_WITHDEBINFO} -O2")
675         set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${WARN_LDFLAGS}")
676         set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${WARN_LDFLAGS}")
677         add_definitions(-D_GNU_SOURCE)
678 endif()
680 if((NOT APPLE) OR CMAKE_COMPILER_IS_GNUCC)
681 add_target_properties(lighttpd LINK_FLAGS "-Wl,-export-dynamic")
682 endif()
684 set_target_properties(lighttpd PROPERTIES CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
686 if(WIN32)
687         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNVALGRIND")
688         add_target_properties(lighttpd COMPILE_FLAGS "-DLI_DECLARE_EXPORTS")
689         target_link_libraries(lighttpd ws2_32)
690         target_link_libraries(mod_proxy ws2_32)
691         target_link_libraries(mod_fcgi ws2_32)
692         target_link_libraries(mod_scgi ws2_32)
693         target_link_libraries(mod_ssi ws2_32)
695         if(MINGW)
696                 target_link_libraries(lighttpd msvcr70)
697                 add_target_properties(lighttpd LINK_FLAGS "-Wl,-subsystem,console")
698         endif()
699 endif()
701 if(NOT BUILD_STATIC)
702         if(HAVE_LIBDL)
703                 target_link_libraries(lighttpd dl)
704         endif()
705 endif()
707 if(HAVE_LIBSSL AND HAVE_LIBCRYPTO)
708         target_link_libraries(lighttpd ssl)
709         target_link_libraries(lighttpd crypto)
710 endif()
712 if(WITH_LIBEV)
713         target_link_libraries(lighttpd ${LIBEV_LDFLAGS})
714         add_target_properties(lighttpd COMPILE_FLAGS ${LIBEV_CFLAGS})
715 endif()
717 if(WITH_LIBUNWIND)
718         target_link_libraries(lighttpd ${LIBUNWIND_LDFLAGS})
719         add_target_properties(lighttpd COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
721         target_link_libraries(test_buffer ${LIBUNWIND_LDFLAGS})
722         add_target_properties(test_buffer COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
723         target_link_libraries(test_base64 ${LIBUNWIND_LDFLAGS})
724         add_target_properties(test_base64 COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
725         target_link_libraries(test_configfile ${PCRE_LDFLAGS} ${LIBUNWIND_LDFLAGS})
726         add_target_properties(test_configfile COMPILE_FLAGS ${PCRE_CFLAGS} ${LIBUNWIND_CFLAGS})
727 endif()
729 if(NOT WIN32)
730 install(TARGETS ${L_INSTALL_TARGETS}
731         RUNTIME DESTINATION ${SBINDIR}
732         LIBRARY DESTINATION ${LIGHTTPD_MODULES_DIR}
733         ARCHIVE DESTINATION ${LIGHTTPD_MODULES_DIR}/static)
734 else()
735 ## HACK to make win32 to install our libraries in desired directory..
736 install(TARGETS lighttpd
737         RUNTIME DESTINATION ${SBINDIR}
738         ARCHIVE DESTINATION lib/static)
739 list(REMOVE_ITEM L_INSTALL_TARGETS lighttpd)
740 install(TARGETS ${L_INSTALL_TARGETS}
741         RUNTIME DESTINATION ${SBINDIR}/lib
742         LIBRARY DESTINATION lib
743         ARCHIVE DESTINATION lib/static)
744 endif()