[core] remove some unused header includes
[lighttpd.git] / src / CMakeLists.txt
blobb37b192ba7c19ed2d5ac7274a33bfa00ed5fd5d1
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         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_buf HAVE_ARC4RANDOM_BUF)
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(getloadavg HAVE_GETLOADAVG)
138 check_function_exists(getrlimit HAVE_GETRLIMIT)
139 check_function_exists(getuid HAVE_GETUID)
140 check_function_exists(gmtime_r HAVE_GMTIME_R)
141 check_function_exists(inet_ntop HAVE_INET_NTOP)
142 check_function_exists(jrand48 HAVE_JRAND48)
143 check_function_exists(kqueue HAVE_KQUEUE)
144 check_function_exists(localtime_r HAVE_LOCALTIME_R)
145 check_function_exists(lstat HAVE_LSTAT)
146 check_function_exists(madvise HAVE_MADVISE)
147 check_function_exists(memcpy HAVE_MEMCPY)
148 check_function_exists(memset HAVE_MEMSET)
149 check_function_exists(mmap HAVE_MMAP)
150 check_function_exists(pathconf HAVE_PATHCONF)
151 check_function_exists(pipe2 HAVE_PIPE2)
152 check_function_exists(poll HAVE_POLL)
153 check_function_exists(port_create HAVE_PORT_CREATE)
154 check_function_exists(prctl HAVE_PRCTL)
155 check_function_exists(pread HAVE_PREAD)
156 check_function_exists(posix_fadvise HAVE_POSIX_FADVISE)
157 check_function_exists(select HAVE_SELECT)
158 check_function_exists(sendfile HAVE_SENDFILE)
159 check_function_exists(send_file HAVE_SEND_FILE)
160 check_function_exists(sendfile64 HAVE_SENDFILE64)
161 check_function_exists(sendfilev HAVE_SENDFILEV)
162 check_function_exists(sigaction HAVE_SIGACTION)
163 check_function_exists(signal HAVE_SIGNAL)
164 check_function_exists(sigtimedwait HAVE_SIGTIMEDWAIT)
165 check_function_exists(srandom HAVE_SRANDOM)
166 check_function_exists(strptime HAVE_STRPTIME)
167 check_function_exists(syslog HAVE_SYSLOG)
168 check_function_exists(writev HAVE_WRITEV)
169 check_function_exists(inet_aton HAVE_INET_ATON)
170 check_function_exists(issetugid HAVE_ISSETUGID)
171 check_function_exists(inet_pton HAVE_INET_PTON)
172 check_function_exists(memset_s HAVE_MEMSET_S)
173 check_function_exists(explicit_bzero HAVE_EXPLICIT_BZERO)
174 check_symbol_exists(clock_gettime "time.h" HAVE_CLOCK_GETTIME)
175 if (NOT HAVE_CLOCK_GETTIME)
176         check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME)
177 endif()
178 check_c_source_compiles("
179         #include <sys/types.h>
180         #include <sys/socket.h>
181         #include <netinet/in.h>
183         int main() {
184                 struct sockaddr_in6 s; struct in6_addr t=in6addr_any; int i=AF_INET6; s; t.s6_addr[0] = 0;
185                 return 0;
186         }" HAVE_IPV6)
187 check_c_source_compiles("
188         __attribute__((weak)) void __dummy(void *x) { }
189         int main() {
190                 void *x;
191                 __dummy(x);
192         }
193         " HAVE_WEAK_SYMBOLS)
194 check_c_source_compiles("
195         #include <time.h>
196         int main(void) {
197                 struct tm t;
198                 t.tm_gmtoff = 0;
199                 return 0;
200         }
201         " HAVE_STRUCT_TM_GMTOFF)
203 ## refactor me
204 macro(XCONFIG _package _include_DIR _link_DIR _link_FLAGS _cflags)
205 # reset the variables at the beginning
206         set(${_include_DIR})
207         set(${_link_DIR})
208         set(${_link_FLAGS})
209         set(${_cflags})
211         find_program(${_package}CONFIG_EXECUTABLE NAMES ${_package} PATHS /usr/local/bin )
213         # if pkg-config has been found
214         if(${_package}CONFIG_EXECUTABLE)
215                 set(XCONFIG_EXECUTABLE "${${_package}CONFIG_EXECUTABLE}")
216                 message(STATUS "found ${_package}: ${XCONFIG_EXECUTABLE}")
218                 exec_program(${XCONFIG_EXECUTABLE} ARGS --libs OUTPUT_VARIABLE __link_FLAGS)
219                 string(REPLACE "\n" "" ${_link_FLAGS} ${__link_FLAGS})
220                 exec_program(${XCONFIG_EXECUTABLE} ARGS --cflags OUTPUT_VARIABLE __cflags)
221                 string(REPLACE "\n" "" ${_cflags} ${__cflags})
222         else()
223                 message(STATUS "found ${_package}: no")
224         endif()
225 endmacro(XCONFIG _package _include_DIR _link_DIR _link_FLAGS _cflags)
227 if(WITH_XATTR)
228         check_include_files(attr/attributes.h HAVE_ATTR_ATTRIBUTES_H)
229         if(HAVE_ATTR_ATTRIBUTES_H)
230                 check_library_exists(attr attr_get "" HAVE_XATTR)
231         endif()
232 else()
233         unset(HAVE_ATTR_ATTRIBUTES_H)
234         unset(HAVE_XATTR)
235 endif()
237 if(WITH_MYSQL)
238         xconfig(mysql_config MYSQL_INCDIR MYSQL_LIBDIR MYSQL_LDFLAGS MYSQL_CFLAGS)
240         set(CMAKE_REQUIRED_INCLUDES /usr/include/mysql)
241         check_include_files(mysql.h HAVE_MYSQL_H)
242         set(CMAKE_REQUIRED_INCLUDES)
243         if(HAVE_MYSQL_H)
244                 check_library_exists(mysqlclient mysql_real_connect "" HAVE_MYSQL)
245         endif()
246 else()
247         unset(HAVE_MYSQL_H)
248         unset(HAVE_MYSQL)
249 endif()
251 if(WITH_PGSQL)
252         xconfig(pg_config PGSQL_INCDIR PGSQL_LIBDIR PGSQL_LDFLAGS PGSQL_CFLAGS)
254         check_include_files(libpq-fe.h HAVE_PGSQL_H)
255         if(HAVE_PGSQL_H)
256                 check_library_exists(pq PQsetdbLogin "" HAVE_PGSQL)
257         endif()
258 else()
259         unset(HAVE_PGSQL_H)
260         unset(HAVE_PGSQL)
261 endif()
263 if(WITH_DBI)
264         check_include_files(dbi/dbi.h HAVE_DBI_H)
265         if(HAVE_DBI_H)
266                 check_library_exists(dbi dbi_conn_connect "" HAVE_DBI)
267         endif()
268 else()
269         unset(HAVE_DBI_H)
270         unset(HAVE_DBI)
271 endif()
273 if(WITH_OPENSSL)
274         if(APPLE)
275                 set(CMAKE_REQUIRED_INCLUDES /opt/local/include)
276         endif()
277         check_include_files(openssl/ssl.h HAVE_OPENSSL_SSL_H)
278         if(APPLE)
279                 set(CMAKE_REQUIRED_INCLUDES)
280         endif()
281         if(HAVE_OPENSSL_SSL_H)
282                 check_library_exists(crypto BIO_f_base64 "" HAVE_LIBCRYPTO)
283                 if(HAVE_LIBCRYPTO)
284                         check_library_exists(ssl SSL_new "" HAVE_LIBSSL)
285                 endif()
286         endif()
287 else()
288         unset(HAVE_OPENSSL_SSL_H)
289         unset(HAVE_LIBCRYPTO)
290         unset(HAVE_LIBSSL)
291 endif()
293 if(WITH_PCRE)
294         ## if we have pcre-config, use it
295         xconfig(pcre-config PCRE_INCDIR PCRE_LIBDIR PCRE_LDFLAGS PCRE_CFLAGS)
296         if(PCRE_LDFLAGS OR PCRE_CFLAGS)
297                 message(STATUS "found pcre at: LDFLAGS: ${PCRE_LDFLAGS} CFLAGS: ${PCRE_CFLAGS}")
299                 if(NOT PCRE_CFLAGS STREQUAL "\n")
300                         ## if it is empty we'll get newline returned
301                         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PCRE_CFLAGS}")
302                 endif()
304                 set(HAVE_PCRE_H 1)
305                 set(HAVE_LIBPCRE 1)
306         else()
307                 if(NOT WIN32)
308                         check_include_files(pcre.h HAVE_PCRE_H)
309                         check_library_exists(pcre pcre_exec "" HAVE_LIBPCRE)
310                         set(PCRE_LDFLAGS -lpcre)
311                 else()
312                         find_path(PCRE_INCLUDE_DIR pcre.h
313                         /usr/local/include
314                         /usr/include
315                         )
317                         set(PCRE_NAMES pcre)
318                         find_library(PCRE_LIBRARY
319                         NAMES ${PCRE_NAMES}
320                         PATHS /usr/lib /usr/local/lib
321                         )
323                         if(PCRE_INCLUDE_DIR AND PCRE_LIBRARY)
324                                 set(CMAKE_REQUIRED_INCLUDES ${PCRE_INCLUDE_DIR})
325                                 set(CMAKE_REQUIRED_LIBRARIES ${PCRE_LIBRARY})
326                                 check_include_files(pcre.h HAVE_PCRE_H)
327                                 check_library_exists(pcre pcre_exec "" HAVE_LIBPCRE)
328                                 set(CMAKE_REQUIRED_INCLUDES)
329                                 set(CMAKE_REQUIRED_LIBRARIES)
330                                 include_directories(${PCRE_INCLUDE_DIR})
331                         endif()
332                 endif()
333         endif()
335         if(NOT HAVE_PCRE_H)
336                 message(FATAL_ERROR "pcre.h couldn't be found")
337         endif()
338         if(NOT HAVE_LIBPCRE)
339                 message(FATAL_ERROR "libpcre couldn't be found")
340         endif()
341 else()
342         unset(HAVE_PCRE_H)
343         unset(HAVE_LIBPCRE)
344 endif()
347 if(WITH_XML)
348         xconfig(xml2-config XML2_INCDIR XML2_LIBDIR XML2_LDFLAGS XML2_CFLAGS)
349         if(XML2_LDFLAGS OR XML2_CFLAGS)
350                 message(STATUS "found xml2 at: LDFLAGS: ${XML2_LDFLAGS} CFLAGS: ${XML2_CFLAGS}")
352                 ## if it is empty we'll get newline returned
353                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${XML2_CFLAGS}")
355                 check_include_files(libxml/tree.h HAVE_LIBXML_H)
357                 set(CMAKE_REQUIRED_FLAGS ${XML2_LDFLAGS})
358                 check_library_exists(xml2 xmlParseChunk "" HAVE_LIBXML)
359                 set(CMAKE_REQUIRED_FLAGS)
360         else()
361                 check_include_files(libxml.h HAVE_LIBXML_H)
362                 check_library_exists(xml2 xmlParseChunk "" HAVE_LIBXML)
363         endif()
365         if(NOT HAVE_LIBXML_H)
366                 message(FATAL_ERROR "libxml/tree.h couldn't be found")
367         endif()
368         if(NOT HAVE_LIBXML)
369                 message(FATAL_ERROR "libxml2 couldn't be found")
370         endif()
371 else()
372         unset(HAVE_LIBXML_H)
373         unset(HAVE_LIBXML)
374 endif()
376 if(WITH_SQLITE3)
377         check_include_files(sqlite3.h HAVE_SQLITE3_H)
378         check_library_exists(sqlite3 sqlite3_reset "" HAVE_SQLITE3)
379 else()
380         unset(HAVE_SQLITE3_H)
381         unset(HAVE_SQLITE3)
382 endif()
384 if(WITH_UUID)
385         check_include_files(uuid/uuid.h HAVE_UUID_UUID_H)
386         check_library_exists(uuid uuid_generate "" NEED_LIBUUID)
387         if(NOT NEED_LIBUUID)
388                 check_function_exists(uuid_generate HAVE_LIBUUID)
389         else()
390                 set(HAVE_LIBUUID 1)
391         endif()
392 else()
393         unset(HAVE_UUID_UUID_H)
394         unset(NEED_LIBUUID)
395         unset(HAVE_LIBUUID)
396 endif()
398 if(WITH_ZLIB)
399         if(NOT WIN32)
400                 check_include_files(zlib.h HAVE_ZLIB_H)
401                 check_library_exists(z deflate "" HAVE_LIBZ)
402                 set(ZLIB_LIBRARY z)
403         else()
404                 find_path(ZLIB_INCLUDE_DIR zlib.h
405                         /usr/local/include
406                         /usr/include
407                 )
409                 set(ZLIB_NAMES z zlib zdll)
410                         find_library(ZLIB_LIBRARY
411                         NAMES ${ZLIB_NAMES}
412                         PATHS /usr/lib /usr/local/lib
413                 )
415                 if(ZLIB_INCLUDE_DIR AND ZLIB_LIBRARY)
416                         set(CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIR})
417                         set(CMAKE_REQUIRED_LIBRARIES ${ZLIB_LIBRARY})
418                         get_filename_component(ZLIB_NAME ${ZLIB_LIBRARY} NAME)
419                         check_include_files(zlib.h HAVE_ZLIB_H)
420                         check_library_exists(${ZLIB_NAME} deflate "" HAVE_LIBZ)
421                         set(CMAKE_REQUIRED_INCLUDES)
422                         set(CMAKE_REQUIRED_LIBRARIES)
423                         include_directories(${ZLIB_INCLUDE_DIR})
424                 endif()
425         endif()
426 else()
427         unset(HAVE_ZLIB_H)
428         unset(HAVE_LIBZ)
429         unset(ZLIB_INCLUDE_DIR)
430         unset(ZLIB_LIBRARY)
431 endif()
433 if(WITH_BZIP)
434         check_include_files(bzlib.h HAVE_BZLIB_H)
435         check_library_exists(bz2 BZ2_bzCompress "" HAVE_LIBBZ2)
436 else()
437         unset(HAVE_BZLIB_H)
438         unset(HAVE_LIBBZ2)
439 endif()
441 if(WITH_LDAP)
442         check_include_files(ldap.h HAVE_LDAP_H)
443         check_library_exists(ldap ldap_bind "" HAVE_LIBLDAP)
444         check_include_files(lber.h HAVE_LBER_H)
445         check_library_exists(lber ber_printf "" HAVE_LIBLBER)
446         set(LDAP_DEPRECATED 1) # Using deprecated ldap api
447 else()
448         unset(HAVE_LDAP_H)
449         unset(HAVE_LIBLDAP)
450         unset(HAVE_LBER_H)
451         unset(HAVE_LIBLBER)
452 endif()
454 if(WITH_LUA)
455         pkg_search_module(LUA REQUIRED lua5.3 lua-5.3 lua5.2 lua-5.2 lua5.1 lua-5.1 lua)
456         message(STATUS "found lua at: INCDIR: ${LUA_INCLUDE_DIRS} LIBDIR: ${LUA_LIBRARY_DIRS} LDFLAGS: ${LUA_LDFLAGS} CFLAGS: ${LUA_CFLAGS}")
457         set(HAVE_LIBLUA 1 "Have liblua")
458         set(HAVE_LUA_H  1 "Have liblua header")
459 else()
460         unset(HAVE_LIBLUA)
461         unset(HAVE_LUA_H)
462 endif()
464 if(WITH_FAM)
465         check_include_files(fam.h HAVE_FAM_H)
466         check_library_exists(fam FAMOpen2 "" HAVE_LIBFAM)
467         if(HAVE_LIBFAM)
468                 set(CMAKE_REQUIRED_LIBRARIES fam)
469                 check_function_exists(FAMNoExists HAVE_FAMNOEXISTS)
470         endif()
471 else()
472         unset(HAVE_FAM_H)
473         unset(HAVE_LIBFAM)
474         unset(HAVE_FAMNOEXISTS)
475 endif()
477 if(WITH_GDBM)
478         check_include_files(gdbm.h HAVE_GDBM_H)
479         check_library_exists(gdbm gdbm_open "" HAVE_GDBM)
480 else()
481         unset(HAVE_GDBM_H)
482         unset(HAVE_GDBM)
483 endif()
485 if(WITH_MEMCACHED)
486         check_include_files(libmemcached/memcached.h HAVE_LIBMEMCACHED_MEMCACHED_H)
487         check_library_exists(memcached memcached "" HAVE_LIBMEMCACHED)
488         if(HAVE_LIBMEMCACHED_MEMCACHED_H AND HAVE_LIBMEMCACHED)
489                 set(USE_MEMCACHED 1)
490         else()
491                 message(FATAL_ERROR "didn't find libmemcached")
492         endif()
493 endif()
495 if(WITH_GEOIP)
496         check_library_exists(geoip GeoIP_country_name_by_addr "" HAVE_GEOIP)
497 endif()
499 if(NOT BUILD_STATIC)
500         check_include_files(dlfcn.h HAVE_DLFCN_H)
501 else()
502         unset(HAVE_DLFCN_H)
503 endif()
505 if(HAVE_DLFCN_H)
506         check_library_exists(dl dlopen "" HAVE_LIBDL)
507 else()
508         unset(HAVE_LIBDL)
509 endif()
511 set(LIGHTTPD_VERSION_ID 10400)
512 set(PACKAGE_NAME "${CMAKE_PROJECT_NAME}")
513 set(PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}")
515 if(NOT SBINDIR)
516         set(SBINDIR "sbin")
517 endif()
519 if(NOT LIGHTTPD_MODULES_DIR)
520         set(LIGHTTPD_MODULES_DIR "lib${LIB_SUFFIX}/lighttpd")
521 endif()
523 if(NOT WIN32)
524         set(LIGHTTPD_LIBRARY_DIR "${CMAKE_INSTALL_PREFIX}/${LIGHTTPD_MODULES_DIR}")
525 else()
526         ## We use relative path in windows
527         set(LIGHTTPD_LIBRARY_DIR "lib")
528 endif()
530 ## Write out config.h
531 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
533 add_definitions(-DHAVE_CONFIG_H)
535 include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
537 set(COMMON_SRC
538         base64.c buffer.c log.c
539         keyvalue.c chunk.c
540         http_chunk.c stream.c fdevent.c
541         stat_cache.c plugin.c joblist.c etag.c array.c
542         data_string.c data_array.c
543         data_integer.c md5.c data_fastcgi.c
544         vector.c
545         fdevent_select.c fdevent_libev.c
546         fdevent_poll.c fdevent_linux_sysepoll.c
547         fdevent_solaris_devpoll.c fdevent_solaris_port.c
548         fdevent_freebsd_kqueue.c
549         data_config.c
550         inet_ntop_cache.c crc32.c
551         connections-glue.c
552         configfile-glue.c
553         http-header-glue.c
554         http_auth.c
555         http_vhostdb.c
556         splaytree.c
557         rand.c
558         status_counter.c safe_memclear.c
561 if(WIN32)
562         message(STATUS "Adding local getopt implementation.")
563         set(COMMON_SRC ${COMMON_SRC} xgetopt.c)
564 endif()
566 add_executable(lemon lemon.c)
568 ## Build parsers by using lemon...
569 lemon_parser(configparser.y)
570 lemon_parser(mod_ssi_exprparser.y)
572 set(L_INSTALL_TARGETS)
574 add_executable(lighttpd-angel lighttpd-angel.c)
575 set(L_INSTALL_TARGETS ${L_INSTALL_TARGETS} lighttpd-angel)
576 add_target_properties(lighttpd-angel COMPILE_FLAGS "-DSBIN_DIR=\\\\\"${CMAKE_INSTALL_PREFIX}/${SBINDIR}\\\\\"")
578 add_executable(lighttpd
579         server.c
580         response.c
581         connections.c
582         network.c
583         network_darwin_sendfile.c
584         network_freebsd_sendfile.c
585         network_linux_sendfile.c
586         network_solaris_sendfilev.c
587         network_write.c
588         network_write_mmap.c
589         network_write_no_mmap.c
590         network_writev.c
591         configfile.c
592         configparser.c
593         request.c
594         proc_open.c
595         ${COMMON_SRC}
597 set(L_INSTALL_TARGETS ${L_INSTALL_TARGETS} lighttpd)
599 add_and_install_library(mod_access mod_access.c)
600 add_and_install_library(mod_accesslog mod_accesslog.c)
601 add_and_install_library(mod_alias mod_alias.c)
602 add_and_install_library(mod_auth "mod_auth.c")
603 add_and_install_library(mod_authn_file "mod_authn_file.c")
604 if(NOT WIN32)
605         add_and_install_library(mod_cgi mod_cgi.c)
606 endif()
607 add_and_install_library(mod_compress mod_compress.c)
608 add_and_install_library(mod_deflate mod_deflate.c)
609 add_and_install_library(mod_dirlisting mod_dirlisting.c)
610 add_and_install_library(mod_evasive mod_evasive.c)
611 add_and_install_library(mod_evhost mod_evhost.c)
612 add_and_install_library(mod_expire mod_expire.c)
613 add_and_install_library(mod_extforward mod_extforward.c)
614 add_and_install_library(mod_fastcgi mod_fastcgi.c)
615 add_and_install_library(mod_flv_streaming mod_flv_streaming.c)
616 add_and_install_library(mod_indexfile mod_indexfile.c)
617 add_and_install_library(mod_proxy mod_proxy.c)
618 add_and_install_library(mod_redirect mod_redirect.c)
619 add_and_install_library(mod_rewrite mod_rewrite.c)
620 add_and_install_library(mod_rrdtool mod_rrdtool.c)
621 add_and_install_library(mod_scgi mod_scgi.c)
622 add_and_install_library(mod_secdownload mod_secdownload.c)
623 add_and_install_library(mod_setenv mod_setenv.c)
624 add_and_install_library(mod_simple_vhost mod_simple_vhost.c)
625 add_and_install_library(mod_ssi "mod_ssi_exprparser.c;mod_ssi_expr.c;mod_ssi.c")
626 add_and_install_library(mod_staticfile mod_staticfile.c)
627 add_and_install_library(mod_status mod_status.c)
628 add_and_install_library(mod_uploadprogress mod_uploadprogress.c)
629 add_and_install_library(mod_userdir mod_userdir.c)
630 add_and_install_library(mod_usertrack mod_usertrack.c)
631 add_and_install_library(mod_vhostdb mod_vhostdb.c)
632 add_and_install_library(mod_webdav mod_webdav.c)
634 add_executable(test_buffer
635         test_buffer.c
636         buffer.c
638 add_test(NAME test_buffer COMMAND test_buffer)
640 add_executable(test_base64
641         test_base64.c
642         buffer.c
643         base64.c
645 add_test(NAME test_base64 COMMAND test_base64)
647 add_executable(test_configfile
648         test_configfile.c
649         buffer.c
650         array.c
651         data_string.c
652         keyvalue.c
653         vector.c
654         log.c
656 add_test(NAME test_configfile COMMAND test_configfile)
658 if(HAVE_PCRE_H)
659         target_link_libraries(lighttpd ${PCRE_LDFLAGS})
660         add_target_properties(lighttpd COMPILE_FLAGS ${PCRE_CFLAGS})
661         target_link_libraries(mod_rewrite ${PCRE_LDFLAGS})
662         add_target_properties(mod_rewrite COMPILE_FLAGS ${PCRE_CFLAGS})
663         target_link_libraries(mod_dirlisting ${PCRE_LDFLAGS})
664         add_target_properties(mod_dirlisting COMPILE_FLAGS ${PCRE_CFLAGS})
665         target_link_libraries(mod_redirect ${PCRE_LDFLAGS})
666         add_target_properties(mod_redirect COMPILE_FLAGS ${PCRE_CFLAGS})
667         target_link_libraries(test_configfile ${PCRE_LDFLAGS})
668         add_target_properties(test_configfile COMPILE_FLAGS ${PCRE_CFLAGS})
669 endif()
671 if(WITH_PCRE AND (WITH_MEMCACHED OR WITH_GDBM))
672         add_and_install_library(mod_trigger_b4_dl mod_trigger_b4_dl.c)
673         target_link_libraries(mod_trigger_b4_dl ${PCRE_LDFLAGS})
674         add_target_properties(mod_trigger_b4_dl COMPILE_FLAGS ${PCRE_CFLAGS})
675 endif()
677 if(WITH_LUA)
678         add_and_install_library(mod_magnet "mod_magnet.c;mod_magnet_cache.c")
679         target_link_libraries(mod_magnet ${LUA_LDFLAGS})
680         add_target_properties(mod_magnet COMPILE_FLAGS ${LUA_CFLAGS})
682         add_and_install_library(mod_cml "mod_cml.c;mod_cml_lua.c;mod_cml_funcs.c")
683         target_link_libraries(mod_cml ${LUA_LDFLAGS})
684         add_target_properties(mod_cml COMPILE_FLAGS ${LUA_CFLAGS})
685 endif()
687 if(WITH_GEOIP)
688         add_and_install_library(mod_geoip mod_geoip.c)
689         target_link_libraries(mod_geoip GeoIP)
690 endif()
692 if(HAVE_MYSQL_H AND HAVE_MYSQL)
693         add_and_install_library(mod_mysql_vhost "mod_mysql_vhost.c")
694         target_link_libraries(mod_mysql_vhost mysqlclient)
695         add_and_install_library(mod_vhostdb_mysql "mod_vhostdb_mysql.c")
696         target_link_libraries(mod_vhostdb_mysql mysqlclient)
697         include_directories(/usr/include/mysql)
699         add_and_install_library(mod_authn_mysql "mod_authn_mysql.c")
700         set(L_MOD_AUTHN_MYSQL)
701         if(HAVE_LIBCRYPT)
702                 set(L_MOD_AUTHN_MYSQL ${L_MOD_AUTHN_MYSQL} crypt)
703         endif()
704         target_link_libraries(mod_authn_mysql ${L_MOD_AUTHN_MYSQL} mysqlclient)
705 endif()
707 if(HAVE_PGSQL_H AND HAVE_PGSQL)
708         add_and_install_library(mod_vhostdb_pgsql "mod_vhostdb_pgsql.c")
709         target_link_libraries(mod_vhostdb_pgsql pq)
710 endif()
712 if(HAVE_DBI_H AND HAVE_DBI)
713         add_and_install_library(mod_vhostdb_dbi "mod_vhostdb_dbi.c")
714         target_link_libraries(mod_vhostdb_dbi dbi)
715 endif()
717 set(L_MOD_WEBDAV)
718 if(HAVE_SQLITE3_H)
719         set(L_MOD_WEBDAV ${L_MOD_WEBDAV} sqlite3)
720 endif()
721 if(HAVE_LIBXML_H)
722         target_link_libraries(mod_webdav ${XML2_LDFLAGS})
723 endif()
724 if(HAVE_UUID_H)
725         if(NEED_LIBUUID)
726                 set(L_MOD_WEBDAV ${L_MOD_WEBDAV} uuid)
727         endif()
728 endif()
730 target_link_libraries(mod_webdav ${L_MOD_WEBDAV})
732 set(L_MOD_AUTHN_FILE)
733 if(HAVE_LIBCRYPT)
734         set(L_MOD_AUTHN_FILE ${L_MOD_AUTHN_FILE} crypt)
735 endif()
736 target_link_libraries(mod_authn_file ${L_MOD_AUTHN_FILE})
738 if(WITH_KRB5)
739         check_library_exists(krb5 krb5_init_context "" HAVE_KRB5)
740         add_and_install_library(mod_authn_gssapi "mod_authn_gssapi.c")
741         set(L_MOD_AUTHN_GSSAPI ${L_MOD_AUTHN_GSSAPI} krb5 gssapi_krb5)
742         target_link_libraries(mod_authn_gssapi ${L_MOD_AUTHN_GSSAPI})
743 endif()
745 if(WITH_LDAP)
746         set(L_MOD_AUTHN_LDAP ${L_MOD_AUTHN_LDAP} ldap lber)
747         add_and_install_library(mod_authn_ldap "mod_authn_ldap.c")
748         target_link_libraries(mod_authn_ldap ${L_MOD_AUTHN_LDAP})
749         add_and_install_library(mod_vhostdb_ldap "mod_vhostdb_ldap.c")
750         target_link_libraries(mod_vhostdb_ldap ${L_MOD_AUTHN_LDAP})
751 endif()
753 if(HAVE_ZLIB_H)
754         if(HAVE_BZLIB_H)
755                 target_link_libraries(mod_compress ${ZLIB_LIBRARY} bz2)
756                 target_link_libraries(mod_deflate ${ZLIB_LIBRARY} bz2)
757         else()
758                 target_link_libraries(mod_compress ${ZLIB_LIBRARY})
759                 target_link_libraries(mod_deflate ${ZLIB_LIBRARY})
760         endif()
761 endif()
763 if(HAVE_LIBFAM)
764         target_link_libraries(lighttpd fam)
765 endif()
767 if(HAVE_GDBM_H)
768         target_link_libraries(mod_trigger_b4_dl gdbm)
769 endif()
771 if(WITH_MEMCACHED)
772         target_link_libraries(mod_trigger_b4_dl memcached)
773 endif()
775 if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang")
776         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wall -g -Wshadow -W -pedantic ${WARN_CFLAGS}")
777         set(CMAKE_C_FLAGS_RELEASE        "${CMAKE_C_FLAGS_RELEASE}     -O2")
778         set(CMAKE_C_FLAGS_DEBUG          "${CMAKE_C_FLAGS_DEBUG}       -O0")
779         set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_WITHDEBINFO} -O2")
780         set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${WARN_LDFLAGS}")
781         set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${WARN_LDFLAGS}")
782 endif()
784 if((NOT APPLE) OR CMAKE_C_COMPILER_ID MATCHES "GNU")
785         add_target_properties(lighttpd LINK_FLAGS "-Wl,-export-dynamic")
786 endif()
788 set_target_properties(lighttpd PROPERTIES CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
790 if(WIN32)
791         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNVALGRIND")
792         add_target_properties(lighttpd COMPILE_FLAGS "-DLI_DECLARE_EXPORTS")
793         target_link_libraries(lighttpd ws2_32)
794         target_link_libraries(mod_proxy ws2_32)
795         target_link_libraries(mod_fcgi ws2_32)
796         target_link_libraries(mod_scgi ws2_32)
797         target_link_libraries(mod_ssi ws2_32)
799         if(MINGW)
800                 target_link_libraries(lighttpd msvcr70)
801                 add_target_properties(lighttpd LINK_FLAGS "-Wl,-subsystem,console")
802         endif()
803 endif()
805 if(NOT BUILD_STATIC)
806         if(HAVE_LIBDL)
807                 target_link_libraries(lighttpd dl)
808         endif()
809 endif()
811 if(HAVE_LIBSSL AND HAVE_LIBCRYPTO)
812         target_link_libraries(lighttpd ssl)
813         target_link_libraries(lighttpd crypto)
814         add_and_install_library(mod_openssl "mod_openssl.c")
815         set(L_MOD_OPENSSL ${L_MOD_OPENSSL} ssl crypto)
816         target_link_libraries(mod_openssl ${L_MOD_OPENSSL})
817         set(L_MOD_AUTHN_FILE ${L_MOD_AUTHN_FILE} crypto)
818         target_link_libraries(mod_authn_file ${L_MOD_AUTHN_FILE})
819         target_link_libraries(mod_secdownload crypto)
820 endif()
822 if(WITH_LIBEV)
823         target_link_libraries(lighttpd ${LIBEV_LDFLAGS})
824         add_target_properties(lighttpd COMPILE_FLAGS ${LIBEV_CFLAGS})
825 endif()
827 if(WITH_LIBUNWIND)
828         target_link_libraries(lighttpd ${LIBUNWIND_LDFLAGS})
829         add_target_properties(lighttpd COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
831         target_link_libraries(test_buffer ${LIBUNWIND_LDFLAGS})
832         add_target_properties(test_buffer COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
833         target_link_libraries(test_base64 ${LIBUNWIND_LDFLAGS})
834         add_target_properties(test_base64 COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
835         target_link_libraries(test_configfile ${PCRE_LDFLAGS} ${LIBUNWIND_LDFLAGS})
836         add_target_properties(test_configfile COMPILE_FLAGS ${PCRE_CFLAGS} ${LIBUNWIND_CFLAGS})
837 endif()
839 if(NOT WIN32)
840 install(TARGETS ${L_INSTALL_TARGETS}
841         RUNTIME DESTINATION ${SBINDIR}
842         LIBRARY DESTINATION ${LIGHTTPD_MODULES_DIR}
843         ARCHIVE DESTINATION ${LIGHTTPD_MODULES_DIR}/static)
844 else()
845 ## HACK to make win32 to install our libraries in desired directory..
846 install(TARGETS lighttpd
847         RUNTIME DESTINATION ${SBINDIR}
848         ARCHIVE DESTINATION lib/static)
849 list(REMOVE_ITEM L_INSTALL_TARGETS lighttpd)
850 install(TARGETS ${L_INSTALL_TARGETS}
851         RUNTIME DESTINATION ${SBINDIR}/lib
852         LIBRARY DESTINATION lib
853         ARCHIVE DESTINATION lib/static)
854 endif()