[mod_cgi] fix pipe_cloexec() when no O_CLOEXEC
[lighttpd.git] / src / CMakeLists.txt
blob3d01272a955cd719b283c146fbbffae12b3420c2
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]")
36 if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang")
37         option(BUILD_EXTRA_WARNINGS "extra warnings")
39         if(BUILD_EXTRA_WARNINGS)
40                 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")
41                 set(WARN_LDFLAGS "-Wl,--as-needed")
42                 # -Werror -Wbad-function-cast -Wmissing-prototypes
43         endif()
44 endif()
46 option(BUILD_STATIC "build a static lighttpd with all modules added")
48 if(BUILD_STATIC)
49         set(LIGHTTPD_STATIC 1)
50 elseif(APPLE)
51         set(CMAKE_SHARED_MODULE_PREFIX "")
52 else()
53         set(CMAKE_SHARED_LIBRARY_PREFIX "")
54 endif()
56 if(WITH_LIBEV)
57         find_package(LibEV REQUIRED)
58         set(HAVE_LIBEV 1)
59 endif()
61 if(WITH_LIBUNWIND)
62         pkg_check_modules(LIBUNWIND REQUIRED libunwind)
63         set(HAVE_LIBUNWIND 1)
64 endif()
66 if(WITH_WEBDAV_PROPS)
67         set(WITH_XML 1)
68         set(WITH_SQLITE3 1)
69         set(WITH_UUID 1)
70 endif()
72 check_include_files(sys/devpoll.h HAVE_SYS_DEVPOLL_H)
73 check_include_files(sys/epoll.h HAVE_SYS_EPOLL_H)
74 check_include_files(sys/event.h HAVE_SYS_EVENT_H)
75 check_include_files(sys/mman.h HAVE_SYS_MMAN_H)
76 check_include_files(sys/poll.h HAVE_SYS_POLL_H)
77 check_include_files(sys/port.h HAVE_SYS_PORT_H)
78 check_include_files(sys/prctl.h HAVE_SYS_PRCTL_H)
79 check_include_files(sys/resource.h HAVE_SYS_RESOURCE_H)
80 check_include_files(sys/sendfile.h HAVE_SYS_SENDFILE_H)
81 check_include_files(sys/select.h HAVE_SYS_SELECT_H)
82 check_include_files(sys/types.h HAVE_SYS_TYPES_H)
83 check_include_files(sys/uio.h HAVE_SYS_UIO_H)
84 check_include_files(sys/un.h HAVE_SYS_UN_H)
85 check_include_files(sys/wait.h HAVE_SYS_WAIT_H)
86 check_include_files(sys/time.h HAVE_SYS_TIME_H)
87 check_include_files(unistd.h HAVE_UNISTD_H)
88 check_include_files(pthread.h HAVE_PTHREAD_H)
89 check_include_files(getopt.h HAVE_GETOPT_H)
90 check_include_files(inttypes.h HAVE_INTTYPES_H)
91 check_include_files(poll.h HAVE_POLL_H)
92 check_include_files(pwd.h HAVE_PWD_H)
93 check_include_files(stddef.h HAVE_STDDEF_H)
94 check_include_files(stdint.h HAVE_STDINT_H)
95 check_include_files(syslog.h HAVE_SYSLOG_H)
97 # check for fastcgi lib, for the tests only
98 check_include_files(fastcgi.h HAVE_FASTCGI_H)
99 check_include_files(fastcgi/fastcgi.h HAVE_FASTCGI_FASTCGI_H)
101 # will be needed for auth
102 check_include_files(crypt.h HAVE_CRYPT_H)
103 # check if we need libcrypt for crypt_r()
104 check_library_exists(crypt crypt_r "" HAVE_LIBCRYPT_CRYPT_R)
105 if(HAVE_LIBCRYPT_CRYPT_R)
106         set(HAVE_CRYPT_R 1)
107         set(HAVE_LIBCRYPT 1)
108 else()
109         check_library_exists(crypt crypt "" HAVE_LIBCRYPT)
110 endif()
111 check_function_exists(crypt_r HAVE_CRYPT_R)
112 check_function_exists(crypt HAVE_CRYPT)
114 check_include_files(sys/inotify.h HAVE_SYS_INOTIFY_H)
115 if(HAVE_SYS_INOTIFY_H)
116         check_function_exists(inotify_init HAVE_INOTIFY_INIT)
117 endif()
119 set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
120 check_type_size(socklen_t HAVE_SOCKLEN_T)
121 set(CMAKE_EXTRA_INCLUDE_FILES)
123 check_include_files(linux/random.h HAVE_LINUX_RANDOM_H)
124 set(CMAKE_EXTRA_INCLUDE_FILES linux/random.h)
125 check_function_exists(getrandom HAVE_GETRANDOM)
126 set(CMAKE_EXTRA_INCLUDE_FILES)
128 check_type_size(long SIZEOF_LONG)
129 check_type_size(off_t SIZEOF_OFF_T)
131 check_function_exists(arc4random HAVE_ARC4RANDOM)
132 check_function_exists(chroot HAVE_CHROOT)
133 check_function_exists(epoll_ctl HAVE_EPOLL_CTL)
134 check_function_exists(fork HAVE_FORK)
135 check_function_exists(getentropy HAVE_GETENTROPY)
136 check_function_exists(getrlimit HAVE_GETRLIMIT)
137 check_function_exists(getuid HAVE_GETUID)
138 check_function_exists(gmtime_r HAVE_GMTIME_R)
139 check_function_exists(inet_ntop HAVE_INET_NTOP)
140 check_function_exists(jrand48 HAVE_JRAND48)
141 check_function_exists(kqueue HAVE_KQUEUE)
142 check_function_exists(localtime_r HAVE_LOCALTIME_R)
143 check_function_exists(lstat HAVE_LSTAT)
144 check_function_exists(madvise HAVE_MADVISE)
145 check_function_exists(memcpy HAVE_MEMCPY)
146 check_function_exists(memset HAVE_MEMSET)
147 check_function_exists(mmap HAVE_MMAP)
148 check_function_exists(pathconf HAVE_PATHCONF)
149 check_function_exists(poll HAVE_POLL)
150 check_function_exists(port_create HAVE_PORT_CREATE)
151 check_function_exists(prctl HAVE_PRCTL)
152 check_function_exists(pread HAVE_PREAD)
153 check_function_exists(posix_fadvise HAVE_POSIX_FADVISE)
154 check_function_exists(select HAVE_SELECT)
155 check_function_exists(sendfile HAVE_SENDFILE)
156 check_function_exists(send_file HAVE_SEND_FILE)
157 check_function_exists(sendfile64 HAVE_SENDFILE64)
158 check_function_exists(sendfilev HAVE_SENDFILEV)
159 check_function_exists(sigaction HAVE_SIGACTION)
160 check_function_exists(signal HAVE_SIGNAL)
161 check_function_exists(sigtimedwait HAVE_SIGTIMEDWAIT)
162 check_function_exists(strptime HAVE_STRPTIME)
163 check_function_exists(syslog HAVE_SYSLOG)
164 check_function_exists(writev HAVE_WRITEV)
165 check_function_exists(inet_aton HAVE_INET_ATON)
166 check_function_exists(issetugid HAVE_ISSETUGID)
167 check_function_exists(inet_pton HAVE_INET_PTON)
168 check_function_exists(memset_s HAVE_MEMSET_S)
169 check_function_exists(explicit_bzero HAVE_EXPLICIT_BZERO)
170 check_symbol_exists(clock_gettime "time.h" HAVE_CLOCK_GETTIME)
171 if (NOT HAVE_CLOCK_GETTIME)
172         check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME)
173 endif()
174 check_c_source_compiles("
175         #include <sys/types.h>
176         #include <sys/socket.h>
177         #include <netinet/in.h>
179         int main() {
180                 struct sockaddr_in6 s; struct in6_addr t=in6addr_any; int i=AF_INET6; s; t.s6_addr[0] = 0;
181                 return 0;
182         }" HAVE_IPV6)
183 check_c_source_compiles("
184         __attribute__((weak)) void __dummy(void *x) { }
185         int main() {
186                 void *x;
187                 __dummy(x);
188         }
189         " HAVE_WEAK_SYMBOLS)
190 check_c_source_compiles("
191         #include <time.h>
192         int main(void) {
193                 struct tm t;
194                 t.tm_gmtoff = 0;
195                 return 0;
196         }
197         " HAVE_STRUCT_TM_GMTOFF)
199 ## refactor me
200 macro(XCONFIG _package _include_DIR _link_DIR _link_FLAGS _cflags)
201 # reset the variables at the beginning
202         set(${_include_DIR})
203         set(${_link_DIR})
204         set(${_link_FLAGS})
205         set(${_cflags})
207         find_program(${_package}CONFIG_EXECUTABLE NAMES ${_package} PATHS /usr/local/bin )
209         # if pkg-config has been found
210         if(${_package}CONFIG_EXECUTABLE)
211                 set(XCONFIG_EXECUTABLE "${${_package}CONFIG_EXECUTABLE}")
212                 message(STATUS "found ${_package}: ${XCONFIG_EXECUTABLE}")
214                 exec_program(${XCONFIG_EXECUTABLE} ARGS --libs OUTPUT_VARIABLE __link_FLAGS)
215                 string(REPLACE "\n" "" ${_link_FLAGS} ${__link_FLAGS})
216                 exec_program(${XCONFIG_EXECUTABLE} ARGS --cflags OUTPUT_VARIABLE __cflags)
217                 string(REPLACE "\n" "" ${_cflags} ${__cflags})
218         else()
219                 message(STATUS "found ${_package}: no")
220         endif()
221 endmacro(XCONFIG _package _include_DIR _link_DIR _link_FLAGS _cflags)
223 if(WITH_XATTR)
224         check_include_files(attr/attributes.h HAVE_ATTR_ATTRIBUTES_H)
225         if(HAVE_ATTR_ATTRIBUTES_H)
226                 check_library_exists(attr attr_get "" HAVE_XATTR)
227         endif()
228 else()
229         unset(HAVE_ATTR_ATTRIBUTES_H)
230         unset(HAVE_XATTR)
231 endif()
233 if(WITH_MYSQL)
234         xconfig(mysql_config MYSQL_INCDIR MYSQL_LIBDIR MYSQL_LDFLAGS MYSQL_CFLAGS)
236         set(CMAKE_REQUIRED_INCLUDES /usr/include/mysql)
237         check_include_files(mysql.h HAVE_MYSQL_H)
238         set(CMAKE_REQUIRED_INCLUDES)
239         if(HAVE_MYSQL_H)
240                 check_library_exists(mysqlclient mysql_real_connect "" HAVE_MYSQL)
241         endif()
242 else()
243         unset(HAVE_MYSQL_H)
244         unset(HAVE_MYSQL)
245 endif()
247 if(WITH_OPENSSL)
248         if(APPLE)
249                 set(CMAKE_REQUIRED_INCLUDES /opt/local/include)
250         endif()
251         check_include_files(openssl/ssl.h HAVE_OPENSSL_SSL_H)
252         if(APPLE)
253                 set(CMAKE_REQUIRED_INCLUDES)
254         endif()
255         if(HAVE_OPENSSL_SSL_H)
256                 check_library_exists(crypto BIO_f_base64 "" HAVE_LIBCRYPTO)
257                 if(HAVE_LIBCRYPTO)
258                         check_library_exists(ssl SSL_new "" HAVE_LIBSSL)
259                 endif()
260         endif()
261 else()
262         unset(HAVE_OPENSSL_SSL_H)
263         unset(HAVE_LIBCRYPTO)
264         unset(HAVE_LIBSSL)
265 endif()
267 if(WITH_PCRE)
268         ## if we have pcre-config, use it
269         xconfig(pcre-config PCRE_INCDIR PCRE_LIBDIR PCRE_LDFLAGS PCRE_CFLAGS)
270         if(PCRE_LDFLAGS OR PCRE_CFLAGS)
271                 message(STATUS "found pcre at: LDFLAGS: ${PCRE_LDFLAGS} CFLAGS: ${PCRE_CFLAGS}")
273                 if(NOT PCRE_CFLAGS STREQUAL "\n")
274                         ## if it is empty we'll get newline returned
275                         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PCRE_CFLAGS}")
276                 endif()
278                 set(HAVE_PCRE_H 1)
279                 set(HAVE_LIBPCRE 1)
280         else()
281                 if(NOT WIN32)
282                         check_include_files(pcre.h HAVE_PCRE_H)
283                         check_library_exists(pcre pcre_exec "" HAVE_LIBPCRE)
284                         set(PCRE_LDFLAGS -lpcre)
285                 else()
286                         find_path(PCRE_INCLUDE_DIR pcre.h
287                         /usr/local/include
288                         /usr/include
289                         )
291                         set(PCRE_NAMES pcre)
292                         find_library(PCRE_LIBRARY
293                         NAMES ${PCRE_NAMES}
294                         PATHS /usr/lib /usr/local/lib
295                         )
297                         if(PCRE_INCLUDE_DIR AND PCRE_LIBRARY)
298                                 set(CMAKE_REQUIRED_INCLUDES ${PCRE_INCLUDE_DIR})
299                                 set(CMAKE_REQUIRED_LIBRARIES ${PCRE_LIBRARY})
300                                 check_include_files(pcre.h HAVE_PCRE_H)
301                                 check_library_exists(pcre pcre_exec "" HAVE_LIBPCRE)
302                                 set(CMAKE_REQUIRED_INCLUDES)
303                                 set(CMAKE_REQUIRED_LIBRARIES)
304                                 include_directories(${PCRE_INCLUDE_DIR})
305                         endif()
306                 endif()
307         endif()
309         if(NOT HAVE_PCRE_H)
310                 message(FATAL_ERROR "pcre.h couldn't be found")
311         endif()
312         if(NOT HAVE_LIBPCRE)
313                 message(FATAL_ERROR "libpcre couldn't be found")
314         endif()
315 else()
316         unset(HAVE_PCRE_H)
317         unset(HAVE_LIBPCRE)
318 endif()
321 if(WITH_XML)
322         xconfig(xml2-config XML2_INCDIR XML2_LIBDIR XML2_LDFLAGS XML2_CFLAGS)
323         if(XML2_LDFLAGS OR XML2_CFLAGS)
324                 message(STATUS "found xml2 at: LDFLAGS: ${XML2_LDFLAGS} CFLAGS: ${XML2_CFLAGS}")
326                 ## if it is empty we'll get newline returned
327                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${XML2_CFLAGS}")
329                 check_include_files(libxml/tree.h HAVE_LIBXML_H)
331                 set(CMAKE_REQUIRED_FLAGS ${XML2_LDFLAGS})
332                 check_library_exists(xml2 xmlParseChunk "" HAVE_LIBXML)
333                 set(CMAKE_REQUIRED_FLAGS)
334         else()
335                 check_include_files(libxml.h HAVE_LIBXML_H)
336                 check_library_exists(xml2 xmlParseChunk "" HAVE_LIBXML)
337         endif()
339         if(NOT HAVE_LIBXML_H)
340                 message(FATAL_ERROR "libxml/tree.h couldn't be found")
341         endif()
342         if(NOT HAVE_LIBXML)
343                 message(FATAL_ERROR "libxml2 couldn't be found")
344         endif()
345 else()
346         unset(HAVE_LIBXML_H)
347         unset(HAVE_LIBXML)
348 endif()
350 if(WITH_SQLITE3)
351         check_include_files(sqlite3.h HAVE_SQLITE3_H)
352         check_library_exists(sqlite3 sqlite3_reset "" HAVE_SQLITE3)
353 else()
354         unset(HAVE_SQLITE3_H)
355         unset(HAVE_SQLITE3)
356 endif()
358 if(WITH_UUID)
359         check_include_files(uuid/uuid.h HAVE_UUID_UUID_H)
360         check_library_exists(uuid uuid_generate "" NEED_LIBUUID)
361         if(NOT NEED_LIBUUID)
362                 check_function_exists(uuid_generate HAVE_LIBUUID)
363         else()
364                 set(HAVE_LIBUUID 1)
365         endif()
366 else()
367         unset(HAVE_UUID_UUID_H)
368         unset(NEED_LIBUUID)
369         unset(HAVE_LIBUUID)
370 endif()
372 if(WITH_ZLIB)
373         if(NOT WIN32)
374                 check_include_files(zlib.h HAVE_ZLIB_H)
375                 check_library_exists(z deflate "" HAVE_LIBZ)
376                 set(ZLIB_LIBRARY z)
377         else()
378                 find_path(ZLIB_INCLUDE_DIR zlib.h
379                         /usr/local/include
380                         /usr/include
381                 )
383                 set(ZLIB_NAMES z zlib zdll)
384                         find_library(ZLIB_LIBRARY
385                         NAMES ${ZLIB_NAMES}
386                         PATHS /usr/lib /usr/local/lib
387                 )
389                 if(ZLIB_INCLUDE_DIR AND ZLIB_LIBRARY)
390                         set(CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIR})
391                         set(CMAKE_REQUIRED_LIBRARIES ${ZLIB_LIBRARY})
392                         get_filename_component(ZLIB_NAME ${ZLIB_LIBRARY} NAME)
393                         check_include_files(zlib.h HAVE_ZLIB_H)
394                         check_library_exists(${ZLIB_NAME} deflate "" HAVE_LIBZ)
395                         set(CMAKE_REQUIRED_INCLUDES)
396                         set(CMAKE_REQUIRED_LIBRARIES)
397                         include_directories(${ZLIB_INCLUDE_DIR})
398                 endif()
399         endif()
400 else()
401         unset(HAVE_ZLIB_H)
402         unset(HAVE_LIBZ)
403         unset(ZLIB_INCLUDE_DIR)
404         unset(ZLIB_LIBRARY)
405 endif()
407 if(WITH_BZIP)
408         check_include_files(bzlib.h HAVE_BZLIB_H)
409         check_library_exists(bz2 BZ2_bzCompress "" HAVE_LIBBZ2)
410 else()
411         unset(HAVE_BZLIB_H)
412         unset(HAVE_LIBBZ2)
413 endif()
415 if(WITH_LDAP)
416         check_include_files(ldap.h HAVE_LDAP_H)
417         check_library_exists(ldap ldap_bind "" HAVE_LIBLDAP)
418         check_include_files(lber.h HAVE_LBER_H)
419         check_library_exists(lber ber_printf "" HAVE_LIBLBER)
420         set(LDAP_DEPRECATED 1) # Using deprecated ldap api
421 else()
422         unset(HAVE_LDAP_H)
423         unset(HAVE_LIBLDAP)
424         unset(HAVE_LBER_H)
425         unset(HAVE_LIBLBER)
426 endif()
428 if(WITH_LUA)
429         pkg_search_module(LUA REQUIRED lua5.3 lua-5.3 lua5.2 lua-5.2 lua5.1 lua-5.1 lua)
430         message(STATUS "found lua at: INCDIR: ${LUA_INCLUDE_DIRS} LIBDIR: ${LUA_LIBRARY_DIRS} LDFLAGS: ${LUA_LDFLAGS} CFLAGS: ${LUA_CFLAGS}")
431         set(HAVE_LIBLUA 1 "Have liblua")
432         set(HAVE_LUA_H  1 "Have liblua header")
433 else()
434         unset(HAVE_LIBLUA)
435         unset(HAVE_LUA_H)
436 endif()
438 if(WITH_FAM)
439         check_include_files(fam.h HAVE_FAM_H)
440         check_library_exists(fam FAMOpen2 "" HAVE_LIBFAM)
441         if(HAVE_LIBFAM)
442                 set(CMAKE_REQUIRED_LIBRARIES fam)
443                 check_function_exists(FAMNoExists HAVE_FAMNOEXISTS)
444         endif()
445 else()
446         unset(HAVE_FAM_H)
447         unset(HAVE_LIBFAM)
448         unset(HAVE_FAMNOEXISTS)
449 endif()
451 if(WITH_GDBM)
452         check_include_files(gdbm.h HAVE_GDBM_H)
453         check_library_exists(gdbm gdbm_open "" HAVE_GDBM)
454 else()
455         unset(HAVE_GDBM_H)
456         unset(HAVE_GDBM)
457 endif()
459 if(WITH_MEMCACHED)
460         check_include_files(libmemcached/memcached.h HAVE_LIBMEMCACHED_MEMCACHED_H)
461         check_library_exists(memcached memcached "" HAVE_LIBMEMCACHED)
462         if(HAVE_LIBMEMCACHED_MEMCACHED_H AND HAVE_LIBMEMCACHED)
463                 set(USE_MEMCACHED 1)
464         else()
465                 message(FATAL_ERROR "didn't find libmemcached")
466         endif()
467 endif()
469 if(NOT BUILD_STATIC)
470         check_include_files(dlfcn.h HAVE_DLFCN_H)
471 else()
472         unset(HAVE_DLFCN_H)
473 endif()
475 if(HAVE_DLFCN_H)
476         check_library_exists(dl dlopen "" HAVE_LIBDL)
477 else()
478         unset(HAVE_LIBDL)
479 endif()
481 set(LIGHTTPD_VERSION_ID 10400)
482 set(PACKAGE_NAME "${CMAKE_PROJECT_NAME}")
483 set(PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}")
485 if(NOT SBINDIR)
486         set(SBINDIR "sbin")
487 endif()
489 if(NOT LIGHTTPD_MODULES_DIR)
490         set(LIGHTTPD_MODULES_DIR "lib${LIB_SUFFIX}/lighttpd")
491 endif()
493 if(NOT WIN32)
494         set(LIGHTTPD_LIBRARY_DIR "${CMAKE_INSTALL_PREFIX}/${LIGHTTPD_MODULES_DIR}")
495 else()
496         ## We use relative path in windows
497         set(LIGHTTPD_LIBRARY_DIR "lib")
498 endif()
500 ## Write out config.h
501 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
503 add_definitions(-DHAVE_CONFIG_H)
505 include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
507 set(COMMON_SRC
508         base64.c buffer.c log.c
509         keyvalue.c chunk.c
510         http_chunk.c stream.c fdevent.c
511         stat_cache.c plugin.c joblist.c etag.c array.c
512         data_string.c data_array.c
513         data_integer.c md5.c data_fastcgi.c
514         vector.c
515         fdevent_select.c fdevent_libev.c
516         fdevent_poll.c fdevent_linux_sysepoll.c
517         fdevent_solaris_devpoll.c fdevent_solaris_port.c
518         fdevent_freebsd_kqueue.c
519         data_config.c
520         inet_ntop_cache.c crc32.c
521         connections-glue.c
522         configfile-glue.c
523         http-header-glue.c
524         http_auth.c
525         splaytree.c network_writev.c
526         network_write_mmap.c network_write_no_mmap.c
527         network_write.c network_linux_sendfile.c
528         network_freebsd_sendfile.c
529         network_solaris_sendfilev.c network_openssl.c
530         rand.c
531         status_counter.c safe_memclear.c network_darwin_sendfile.c
534 if(WIN32)
535         message(STATUS "Adding local getopt implementation.")
536         set(COMMON_SRC ${COMMON_SRC} xgetopt.c)
537 endif()
539 add_executable(lemon lemon.c)
541 ## Build parsers by using lemon...
542 lemon_parser(configparser.y)
543 lemon_parser(mod_ssi_exprparser.y)
545 set(L_INSTALL_TARGETS)
547 add_executable(lighttpd-angel lighttpd-angel.c)
548 set(L_INSTALL_TARGETS ${L_INSTALL_TARGETS} lighttpd-angel)
549 add_target_properties(lighttpd-angel COMPILE_FLAGS "-DSBIN_DIR=\\\\\"${CMAKE_INSTALL_PREFIX}/${SBINDIR}\\\\\"")
551 add_executable(lighttpd
552         server.c
553         response.c
554         connections.c
555         network.c
556         configfile.c
557         configparser.c
558         request.c
559         proc_open.c
560         ${COMMON_SRC}
562 set(L_INSTALL_TARGETS ${L_INSTALL_TARGETS} lighttpd)
564 add_and_install_library(mod_access mod_access.c)
565 add_and_install_library(mod_accesslog mod_accesslog.c)
566 add_and_install_library(mod_alias mod_alias.c)
567 add_and_install_library(mod_auth "mod_auth.c")
568 add_and_install_library(mod_authn_file "mod_authn_file.c")
569 add_and_install_library(mod_authn_ldap "mod_authn_ldap.c")
570 add_and_install_library(mod_authn_mysql "mod_authn_mysql.c")
571 if(NOT WIN32)
572         add_and_install_library(mod_cgi mod_cgi.c)
573 endif()
574 add_and_install_library(mod_cml "mod_cml.c;mod_cml_lua.c;mod_cml_funcs.c")
575 add_and_install_library(mod_compress mod_compress.c)
576 add_and_install_library(mod_deflate mod_deflate.c)
577 add_and_install_library(mod_dirlisting mod_dirlisting.c)
578 add_and_install_library(mod_evasive mod_evasive.c)
579 add_and_install_library(mod_evhost mod_evhost.c)
580 add_and_install_library(mod_expire mod_expire.c)
581 add_and_install_library(mod_extforward mod_extforward.c)
582 add_and_install_library(mod_fastcgi mod_fastcgi.c)
583 add_and_install_library(mod_flv_streaming mod_flv_streaming.c)
584 add_and_install_library(mod_geoip mod_geoip.c)
585 add_and_install_library(mod_indexfile mod_indexfile.c)
586 add_and_install_library(mod_magnet "mod_magnet.c;mod_magnet_cache.c")
587 add_and_install_library(mod_mysql_vhost mod_mysql_vhost.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_trigger_b4_dl mod_trigger_b4_dl.c)
600 add_and_install_library(mod_uploadprogress mod_uploadprogress.c)
601 add_and_install_library(mod_userdir mod_userdir.c)
602 add_and_install_library(mod_usertrack mod_usertrack.c)
603 add_and_install_library(mod_webdav mod_webdav.c)
605 add_executable(test_buffer
606         test_buffer.c
607         buffer.c
609 add_test(NAME test_buffer COMMAND test_buffer)
611 add_executable(test_base64
612         test_base64.c
613         buffer.c
614         base64.c
616 add_test(NAME test_base64 COMMAND test_base64)
618 add_executable(test_configfile
619         test_configfile.c
620         buffer.c
621         array.c
622         data_string.c
623         keyvalue.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(mod_trigger_b4_dl ${PCRE_LDFLAGS})
638         add_target_properties(mod_trigger_b4_dl COMPILE_FLAGS ${PCRE_CFLAGS})
639         target_link_libraries(test_configfile ${PCRE_LDFLAGS})
640         add_target_properties(test_configfile COMPILE_FLAGS ${PCRE_CFLAGS})
641 endif()
643 target_link_libraries(mod_magnet ${LUA_LDFLAGS})
644 add_target_properties(mod_magnet COMPILE_FLAGS ${LUA_CFLAGS})
646 target_link_libraries(mod_cml ${LUA_LDFLAGS})
647 add_target_properties(mod_cml COMPILE_FLAGS ${LUA_CFLAGS})
649 if(HAVE_GEOIP)
650         target_link_libraries(mod_geoip GeoIP)
651 endif()
653 if(HAVE_MYSQL_H AND HAVE_MYSQL)
654         target_link_libraries(mod_mysql_vhost mysqlclient)
655         include_directories(/usr/include/mysql)
657         set(L_MOD_AUTHN_MYSQL)
658         if(HAVE_LIBCRYPT)
659                 set(L_MOD_AUTHN_MYSQL ${L_MOD_AUTHN_MYSQL} crypt)
660         endif()
661         target_link_libraries(mod_authn_mysql ${L_MOD_AUTHN_MYSQL} mysqlclient)
662 endif()
664 set(L_MOD_WEBDAV)
665 if(HAVE_SQLITE3_H)
666         set(L_MOD_WEBDAV ${L_MOD_WEBDAV} sqlite3)
667 endif()
668 if(HAVE_LIBXML_H)
669         target_link_libraries(mod_webdav ${XML2_LDFLAGS})
670 endif()
671 if(HAVE_UUID_H)
672         if(NEED_LIBUUID)
673                 set(L_MOD_WEBDAV ${L_MOD_WEBDAV} uuid)
674         endif()
675 endif()
677 target_link_libraries(mod_webdav ${L_MOD_WEBDAV})
679 set(L_MOD_AUTHN_FILE)
680 if(HAVE_LIBCRYPT)
681         set(L_MOD_AUTHN_FILE ${L_MOD_AUTHN_FILE} crypt)
682 endif()
683 target_link_libraries(mod_authn_file ${L_MOD_AUTHN_FILE})
685 if(HAVE_KRB5)
686         set(L_MOD_AUTHN_GSSAPI ${L_MOD_AUTHN_GSSAPI} resolv krb5 gssapi_krb5)
687         add_and_install_library(mod_authn_gssapi "mod_authn_gssapi.c")
688         target_link_libraries(mod_authn_gssapi ${L_MOD_AUTHN_GSSAPI})
689 endif()
691 if(HAVE_LDAP_H)
692         set(L_MOD_AUTHN_LDAP ${L_MOD_AUTHN_LDAP} ldap lber)
693 endif()
694 target_link_libraries(mod_authn_ldap ${L_MOD_AUTHN_LDAP})
696 if(HAVE_ZLIB_H)
697         if(HAVE_BZLIB_H)
698                 target_link_libraries(mod_compress ${ZLIB_LIBRARY} bz2)
699                 target_link_libraries(mod_deflate ${ZLIB_LIBRARY} bz2)
700         else()
701                 target_link_libraries(mod_compress ${ZLIB_LIBRARY})
702                 target_link_libraries(mod_deflate ${ZLIB_LIBRARY})
703         endif()
704 endif()
706 if(HAVE_LIBFAM)
707         target_link_libraries(lighttpd fam)
708 endif()
710 if(HAVE_GDBM_H)
711         target_link_libraries(mod_trigger_b4_dl gdbm)
712 endif()
714 if(WITH_MEMCACHED)
715         target_link_libraries(mod_trigger_b4_dl memcached)
716 endif()
718 if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang")
719         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wall -g -Wshadow -W -pedantic ${WARN_CFLAGS}")
720         set(CMAKE_C_FLAGS_RELEASE        "${CMAKE_C_FLAGS_RELEASE}     -O2")
721         set(CMAKE_C_FLAGS_DEBUG          "${CMAKE_C_FLAGS_DEBUG}       -O0")
722         set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_WITHDEBINFO} -O2")
723         set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${WARN_LDFLAGS}")
724         set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${WARN_LDFLAGS}")
725 endif()
727 if((NOT APPLE) OR CMAKE_C_COMPILER_ID MATCHES "GNU")
728         add_target_properties(lighttpd LINK_FLAGS "-Wl,-export-dynamic")
729 endif()
731 set_target_properties(lighttpd PROPERTIES CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
733 if(WIN32)
734         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNVALGRIND")
735         add_target_properties(lighttpd COMPILE_FLAGS "-DLI_DECLARE_EXPORTS")
736         target_link_libraries(lighttpd ws2_32)
737         target_link_libraries(mod_proxy ws2_32)
738         target_link_libraries(mod_fcgi ws2_32)
739         target_link_libraries(mod_scgi ws2_32)
740         target_link_libraries(mod_ssi ws2_32)
742         if(MINGW)
743                 target_link_libraries(lighttpd msvcr70)
744                 add_target_properties(lighttpd LINK_FLAGS "-Wl,-subsystem,console")
745         endif()
746 endif()
748 if(NOT BUILD_STATIC)
749         if(HAVE_LIBDL)
750                 target_link_libraries(lighttpd dl)
751         endif()
752 endif()
754 if(HAVE_LIBSSL AND HAVE_LIBCRYPTO)
755         target_link_libraries(lighttpd ssl)
756         target_link_libraries(lighttpd crypto)
757 endif()
759 if(WITH_LIBEV)
760         target_link_libraries(lighttpd ${LIBEV_LDFLAGS})
761         add_target_properties(lighttpd COMPILE_FLAGS ${LIBEV_CFLAGS})
762 endif()
764 if(WITH_LIBUNWIND)
765         target_link_libraries(lighttpd ${LIBUNWIND_LDFLAGS})
766         add_target_properties(lighttpd COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
768         target_link_libraries(test_buffer ${LIBUNWIND_LDFLAGS})
769         add_target_properties(test_buffer COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
770         target_link_libraries(test_base64 ${LIBUNWIND_LDFLAGS})
771         add_target_properties(test_base64 COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
772         target_link_libraries(test_configfile ${PCRE_LDFLAGS} ${LIBUNWIND_LDFLAGS})
773         add_target_properties(test_configfile COMPILE_FLAGS ${PCRE_CFLAGS} ${LIBUNWIND_CFLAGS})
774 endif()
776 if(NOT WIN32)
777 install(TARGETS ${L_INSTALL_TARGETS}
778         RUNTIME DESTINATION ${SBINDIR}
779         LIBRARY DESTINATION ${LIGHTTPD_MODULES_DIR}
780         ARCHIVE DESTINATION ${LIGHTTPD_MODULES_DIR}/static)
781 else()
782 ## HACK to make win32 to install our libraries in desired directory..
783 install(TARGETS lighttpd
784         RUNTIME DESTINATION ${SBINDIR}
785         ARCHIVE DESTINATION lib/static)
786 list(REMOVE_ITEM L_INSTALL_TARGETS lighttpd)
787 install(TARGETS ${L_INSTALL_TARGETS}
788         RUNTIME DESTINATION ${SBINDIR}/lib
789         LIBRARY DESTINATION lib
790         ARCHIVE DESTINATION lib/static)
791 endif()