<commit_before>INCLUDE(CheckCSourceCompiles)
INCLUDE(CheckIncludeFiles)
INCLUDE(CheckFunctionExists)
INCLUDE(CheckVariableExists)
INCLUDE(CheckTypeSize)
INCLUDE(CheckLibraryExists)
INCLUDE(CMakeDetermineCCompiler)
INCLUDE(FindThreads)
INCLUDE(FindPkgConfig)

INCLUDE(LighttpdMacros)

ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGE_FILES)

OPTION(WITH_XATTR "with xattr-support for the stat-cache [default: off]")
OPTION(WITH_MYSQL "with mysql-support for the mod_sql_vhost [default: off]")
# OPTION(WITH_POSTGRESQL "with postgress-support for the mod_sql_vhost [default: off]")
OPTION(WITH_OPENSSL "with openssl-support [default: off]")
OPTION(WITH_PCRE "with regex support [default: on]" ON)
OPTION(WITH_WEBDAV_PROPS "with property-support for mod_webdav [default: off]")
OPTION(WITH_WEBDAV_LOCKS "locks in webdav [default: off]")
OPTION(WITH_BZIP "with bzip2-support for mod_compress [default: off]")
OPTION(WITH_ZLIB "with deflate-support for mod_compress [default: on]" ON)
OPTION(WITH_LDAP "with LDAP-support for the mod_auth [default: off]")
OPTION(WITH_LUA "with lua 5.1 for mod_magnet [default: off]")
# OPTION(WITH_VALGRIND "with internal support for valgrind [default: off]")
# OPTION(WITH_KERBEROS5 "use Kerberos5 support with OpenSSL [default: off]")
OPTION(WITH_FAM "fam/gamin for reducing number of stat() calls [default: off]")
OPTION(WITH_GDBM "gdbm storage for mod_trigger_b4_dl [default: off]")
OPTION(WITH_MEMCACHE "memcached storage for mod_trigger_b4_dl [default: off]")

IF(CMAKE_COMPILER_IS_GNUCC)
	OPTION(BUILD_EXTRA_WARNINGS "extra warnings")

	IF(BUILD_EXTRA_WARNINGS)
		SET(WARN_FLAGS "-g -O2 -g2 -Wall -Wmissing-declarations -Wdeclaration-after-statement -Wno-pointer-sign -Wcast-align -Winline -Wsign-compare -Wnested-externs -Wpointer-arith -Wformat-security")
		# -Wl,--as-needed
		# -Werror -Wbad-function-cast -Wmissing-prototypes
	ELSE(BUILD_EXTRA_WARNINGS)
		SET(WARN_FLAGS "")
	ENDIF(BUILD_EXTRA_WARNINGS)
ENDIF(CMAKE_COMPILER_IS_GNUCC)

OPTION(BUILD_STATIC "build a static lighttpd with all modules added")

IF(BUILD_STATIC)
  SET(LIGHTTPD_STATIC 1)
ELSE(BUILD_STATIC)
  SET(CMAKE_SHARED_LIBRARY_PREFIX "")
ENDIF(BUILD_STATIC)

IF(WITH_WEBDAV_PROPS)
  SET(WITH_XML 1)
  SET(WITH_SQLITE3 1)
  SET(WITH_UUID 1)
ENDIF(WITH_WEBDAV_PROPS)

CHECK_INCLUDE_FILES(sys/devpoll.h HAVE_SYS_DEVPOLL_H)
CHECK_INCLUDE_FILES(sys/epoll.h HAVE_SYS_EPOLL_H)
CHECK_INCLUDE_FILES(sys/event.h HAVE_SYS_EVENT_H)
CHECK_INCLUDE_FILES(sys/mman.h HAVE_SYS_MMAN_H)
CHECK_INCLUDE_FILES(sys/poll.h HAVE_SYS_POLL_H)
CHECK_INCLUDE_FILES(sys/port.h HAVE_SYS_PORT_H)
CHECK_INCLUDE_FILES(sys/prctl.h HAVE_SYS_PRCTL_H)
CHECK_INCLUDE_FILES(sys/resource.h HAVE_SYS_RESOURCE_H)
CHECK_INCLUDE_FILES(sys/sendfile.h HAVE_SYS_SENDFILE_H)
CHECK_INCLUDE_FILES(sys/select.h HAVE_SYS_SELECT_H)
CHECK_INCLUDE_FILES(sys/syslimits.h HAVE_SYS_SYSLIMITS_H)
CHECK_INCLUDE_FILES(sys/types.h HAVE_SYS_TYPES_H)
CHECK_INCLUDE_FILES(sys/uio.h HAVE_SYS_UIO_H)
CHECK_INCLUDE_FILES(sys/un.h HAVE_SYS_UN_H)
CHECK_INCLUDE_FILES(sys/wait.h HAVE_SYS_WAIT_H)
CHECK_INCLUDE_FILES(sys/time.h HAVE_SYS_TIME_H)
CHECK_INCLUDE_FILES(unistd.h HAVE_UNISTD_H)
CHECK_INCLUDE_FILES(pthread.h HAVE_PTHREAD_H)
CHECK_INCLUDE_FILES(getopt.h HAVE_GETOPT_H)
CHECK_INCLUDE_FILES(inttypes.h HAVE_INTTYPES_H)
CHECK_INCLUDE_FILES(poll.h HAVE_POLL_H)
CHECK_INCLUDE_FILES(pwd.h HAVE_PWD_H)
CHECK_INCLUDE_FILES(stddef.h HAVE_STDDEF_H)
CHECK_INCLUDE_FILES(stdint.h HAVE_STDINT_H)
CHECK_INCLUDE_FILES(syslog.h HAVE_SYSLOG_H)

# check for fastcgi lib, for the tests only
CHECK_INCLUDE_FILES(fastcgi.h HAVE_FASTCGI_H)
CHECK_INCLUDE_FILES(fastcgi/fastcgi.h HAVE_FASTCGI_FASTCGI_H)

CHECK_INCLUDE_FILES(crypt.h HAVE_CRYPT_H)
IF(HAVE_CRYPT_H)
  ## check if we need libcrypt for crypt()
  CHECK_LIBRARY_EXISTS(crypt crypt "" HAVE_LIBCRYPT)
ENDIF(HAVE_CRYPT_H)

CHECK_INCLUDE_FILES(sys/inotify.h HAVE_SYS_INOTIFY_H)
IF(HAVE_SYS_INOTIFY_H)
  CHECK_FUNCTION_EXISTS(inotify_init HAVE_INOTIFY_INIT)
ENDIF(HAVE_SYS_INOTIFY_H)

SET(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
CHECK_TYPE_SIZE(socklen_t HAVE_SOCKLEN_T)
SET(CMAKE_EXTRA_INCLUDE_FILES)

CHECK_TYPE_SIZE(long SIZEOF_LONG)
CHECK_TYPE_SIZE(off_t SIZEOF_OFF_T)

CHECK_FUNCTION_EXISTS(chroot HAVE_CHROOT)
CHECK_FUNCTION_EXISTS(crypt HAVE_CRYPT)
CHECK_FUNCTION_EXISTS(epoll_ctl HAVE_EPOLL_CTL)
CHECK_FUNCTION_EXISTS(fork HAVE_FORK)
CHECK_FUNCTION_EXISTS(getrlimit HAVE_GETRLIMIT)
CHECK_FUNCTION_EXISTS(getuid HAVE_GETUID)
CHECK_FUNCTION_EXISTS(gmtime_r HAVE_GMTIME_R)
CHECK_FUNCTION_EXISTS(inet_ntop HAVE_INET_NTOP)
CHECK_FUNCTION_EXISTS(kqueue HAVE_KQUEUE)
CHECK_FUNCTION_EXISTS(localtime_r HAVE_LOCALTIME_R)
CHECK_FUNCTION_EXISTS(lstat HAVE_LSTAT)
CHECK_FUNCTION_EXISTS(madvise HAVE_MADVISE)
CHECK_FUNCTION_EXISTS(memcpy HAVE_MEMCPY)
CHECK_FUNCTION_EXISTS(memset HAVE_MEMSET)
CHECK_FUNCTION_EXISTS(mmap HAVE_MMAP)
CHECK_FUNCTION_EXISTS(pathconf HAVE_PATHCONF)
CHECK_FUNCTION_EXISTS(poll HAVE_POLL)
CHECK_FUNCTION_EXISTS(port_create HAVE_PORT_CREATE)
CHECK_FUNCTION_EXISTS(prctl HAVE_PRCTL)
CHECK_FUNCTION_EXISTS(pread HAVE_PREAD)
CHECK_FUNCTION_EXISTS(posix_fadvise HAVE_POSIX_FADVISE)
CHECK_FUNCTION_EXISTS(select HAVE_SELECT)
CHECK_FUNCTION_EXISTS(sendfile HAVE_SENDFILE)
CHECK_FUNCTION_EXISTS(send_file HAVE_SEND_FILE)
CHECK_FUNCTION_EXISTS(sendfile64 HAVE_SENDFILE64)
CHECK_FUNCTION_EXISTS(sendfilev HAVE_SENDFILEV)
CHECK_FUNCTION_EXISTS(sigaction HAVE_SIGACTION)
CHECK_FUNCTION_EXISTS(signal HAVE_SIGNAL)
CHECK_FUNCTION_EXISTS(sigtimedwait HAVE_SIGTIMEDWAIT)
CHECK_FUNCTION_EXISTS(strptime HAVE_STRPTIME)
CHECK_FUNCTION_EXISTS(syslog HAVE_SYSLOG)
CHECK_FUNCTION_EXISTS(writev HAVE_WRITEV)
CHECK_FUNCTION_EXISTS(inet_aton HAVE_INET_ATON)
CHECK_C_SOURCE_COMPILES("
	#include <sys/types.h>
	#include <sys/socket.h>
	#include <netinet/in.h>
	
	int main() {
		struct sockaddr_in6 s; struct in6_addr t=in6addr_any; int i=AF_INET6; s; t.s6_addr[0] = 0;
		return 0;
	}" HAVE_IPV6)
CHECK_FUNCTION_EXISTS(issetugid HAVE_ISSETUGID)
CHECK_FUNCTION_EXISTS(inet_pton HAVE_INET_PTON)

## refactor me
MACRO(XCONFIG _package _include_DIR _link_DIR _link_FLAGS _cflags)
# reset the variables at the beginning
  SET(${_include_DIR})
  SET(${_link_DIR})
  SET(${_link_FLAGS})
  SET(${_cflags})

  FIND_PROGRAM(${_package}CONFIG_EXECUTABLE NAMES ${_package} PATHS /usr/local/bin )

  # if pkg-config has been found
  IF(${_package}CONFIG_EXECUTABLE)
    SET(XCONFIG_EXECUTABLE "${${_package}CONFIG_EXECUTABLE}")
    MESSAGE(STATUS "found ${_package}: ${XCONFIG_EXECUTABLE}")

    EXEC_PROGRAM(${XCONFIG_EXECUTABLE} ARGS --libs OUTPUT_VARIABLE __link_FLAGS)
    STRING(REPLACE "\n" "" ${_link_FLAGS} ${__link_FLAGS})
    EXEC_PROGRAM(${XCONFIG_EXECUTABLE} ARGS --cflags OUTPUT_VARIABLE __cflags)
    STRING(REPLACE "\n" "" ${_cflags} ${__cflags})

  ELSE(${_package}CONFIG_EXECUTABLE)
    MESSAGE(STATUS "found ${_package}: no")
  ENDIF(${_package}CONFIG_EXECUTABLE)
ENDMACRO(XCONFIG _package _include_DIR _link_DIR _link_FLAGS _cflags)

IF(WITH_XATTR)
  CHECK_INCLUDE_FILES(attr/attributes.h HAVE_ATTR_ATTRIBUTES_H)
  IF(HAVE_ATTR_ATTRIBUTES_H)
    CHECK_LIBRARY_EXISTS(attr attr_get "" HAVE_XATTR)
  ENDIF(HAVE_ATTR_ATTRIBUTES_H)
ENDIF(WITH_XATTR)

IF(WITH_MYSQL)
  XCONFIG(mysql_config MYSQL_INCDIR MYSQL_LIBDIR MYSQL_LDFLAGS MYSQL_CFLAGS)

  SET(CMAKE_REQUIRED_INCLUDES /usr/include/mysql)
  CHECK_INCLUDE_FILES(mysql.h HAVE_MYSQL_H)
  SET(CMAKE_REQUIRED_INCLUDES)
  IF(HAVE_MYSQL_H)
    CHECK_LIBRARY_EXISTS(mysqlclient mysql_real_connect "" HAVE_MYSQL)
  ENDIF(HAVE_MYSQL_H)
ENDIF(WITH_MYSQL)

IF(WITH_OPENSSL)
  CHECK_INCLUDE_FILES(openssl/ssl.h HAVE_OPENSSL_SSL_H)
  IF(HAVE_OPENSSL_SSL_H)
    CHECK_LIBRARY_EXISTS(crypto BIO_f_base64 "" HAVE_LIBCRYPTO)
    IF(HAVE_LIBCRYPTO)
      SET(OPENSSL_NO_KRB5 1)
      CHECK_LIBRARY_EXISTS(ssl SSL_new "" HAVE_LIBSSL)
    ENDIF(HAVE_LIBCRYPTO)
  ENDIF(HAVE_OPENSSL_SSL_H)
ENDIF(WITH_OPENSSL)

IF(WITH_PCRE)
  ## if we have pcre-config, use it
  XCONFIG(pcre-config PCRE_INCDIR PCRE_LIBDIR PCRE_LDFLAGS PCRE_CFLAGS)
  IF(PCRE_LDFLAGS OR PCRE_CFLAGS)
    MESSAGE(STATUS "found pcre at: LDFLAGS: ${PCRE_LDFLAGS} CFLAGS: ${PCRE_CFLAGS}")

    IF(NOT PCRE_CFLAGS STREQUAL "\n")
      ## if it is empty we'll get newline returned
      SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PCRE_CFLAGS}")
    ENDIF(NOT PCRE_CFLAGS STREQUAL "\n")

    SET(HAVE_PCRE_H 1)
    SET(HAVE_LIBPCRE 1)
  ELSE(PCRE_LDFLAGS OR PCRE_CFLAGS) 
    IF(NOT WIN32)
      CHECK_INCLUDE_FILES(pcre.h HAVE_PCRE_H)
      CHECK_LIBRARY_EXISTS(pcre pcre_exec "" HAVE_LIBPCRE)
      SET(PCRE_LDFLAGS -lpcre)
    ELSE(NOT WIN32)
      FIND_PATH(PCRE_INCLUDE_DIR pcre.h
      /usr/local/include
      /usr/include
      )
  
      SET(PCRE_NAMES pcre)
      FIND_LIBRARY(PCRE_LIBRARY
      NAMES ${PCRE_NAMES}
      PATHS /usr/lib /usr/local/lib
      )
  
      IF(PCRE_INCLUDE_DIR AND PCRE_LIBRARY)
        SET(CMAKE_REQUIRED_INCLUDES ${PCRE_INCLUDE_DIR})
        SET(CMAKE_REQUIRED_LIBRARIES ${PCRE_LIBRARY})
        CHECK_INCLUDE_FILES(pcre.h HAVE_PCRE_H)
        CHECK_LIBRARY_EXISTS(pcre pcre_exec "" HAVE_LIBPCRE)
        SET(CMAKE_REQUIRED_INCLUDES)
        SET(CMAKE_REQUIRED_LIBRARIES)
        INCLUDE_DIRECTORIES(${PCRE_INCLUDE_DIR})
      ENDIF(PCRE_INCLUDE_DIR AND PCRE_LIBRARY)
    ENDIF(NOT WIN32)
  ENDIF(PCRE_LDFLAGS OR PCRE_CFLAGS) 

  IF(NOT HAVE_PCRE_H)
    MESSAGE(FATAL_ERROR "pcre.h couldn't be found")
  ENDIF(NOT HAVE_PCRE_H)
  IF(NOT HAVE_LIBPCRE)
    MESSAGE(FATAL_ERROR "libpcre couldn't be found")
  ENDIF(NOT HAVE_LIBPCRE)

ENDIF(WITH_PCRE)


IF(WITH_XML)
  XCONFIG(xml2-config XML2_INCDIR XML2_LIBDIR XML2_LDFLAGS XML2_CFLAGS)
  IF(XML2_LDFLAGS OR XML2_CFLAGS) 
    MESSAGE(STATUS "found xml2 at: LDFLAGS: ${XML2_LDFLAGS} CFLAGS: ${XML2_CFLAGS}")

    ## if it is empty we'll get newline returned
    SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${XML2_CFLAGS}")

    CHECK_INCLUDE_FILES(libxml/tree.h HAVE_LIBXML_H)

    SET(CMAKE_REQUIRED_FLAGS ${XML2_LDFLAGS})
    CHECK_LIBRARY_EXISTS(xml2 xmlParseChunk "" HAVE_LIBXML)
    SET(CMAKE_REQUIRED_FLAGS)
  ELSE(XML2_LDFLAGS OR XML2_CFLAGS) 
    CHECK_INCLUDE_FILES(libxml.h HAVE_LIBXML_H)
    CHECK_LIBRARY_EXISTS(xml2 xmlParseChunk "" HAVE_LIBXML)
  ENDIF(XML2_LDFLAGS OR XML2_CFLAGS) 

  IF(NOT HAVE_LIBXML_H)
    MESSAGE(FATAL_ERROR "libxml/tree.h couldn't be found")
  ENDIF(NOT HAVE_LIBXML_H)
  IF(NOT HAVE_LIBXML)
    MESSAGE(FATAL_ERROR "libxml2 couldn't be found")
  ENDIF(NOT HAVE_LIBXML)

ENDIF(WITH_XML)

IF(WITH_SQLITE3)
  CHECK_INCLUDE_FILES(sqlite3.h HAVE_SQLITE3_H)
  CHECK_LIBRARY_EXISTS(sqlite3 sqlite3_reset "" HAVE_SQLITE3)
ENDIF(WITH_SQLITE3)

IF(WITH_UUID)
  CHECK_INCLUDE_FILES(uuid/uuid.h HAVE_UUID_UUID_H)
  CHECK_LIBRARY_EXISTS(uuid uuid_generate "" NEED_LIBUUID)
  IF(NOT NEED_LIBUUID)
    CHECK_FUNCTION_EXISTS(uuid_generate HAVE_LIBUUID)
  ELSE(NOT NEED_LIBUUID)
    SET(HAVE_LIBUUID 1)
  ENDIF(NOT NEED_LIBUUID)
ENDIF(WITH_UUID)

IF(WITH_ZLIB)
  IF(NOT WIN32)
    CHECK_INCLUDE_FILES(zlib.h HAVE_ZLIB_H)
    CHECK_LIBRARY_EXISTS(z deflate "" HAVE_LIBZ)
		SET(ZLIB_LIBRARY z)
  ELSE(NOT WIN32)
    FIND_PATH(ZLIB_INCLUDE_DIR zlib.h
    /usr/local/include
    /usr/include
    )
  
    SET(ZLIB_NAMES z zlib zdll)
    FIND_LIBRARY(ZLIB_LIBRARY
    NAMES ${ZLIB_NAMES}
    PATHS /usr/lib /usr/local/lib
    )
  
  
    IF(ZLIB_INCLUDE_DIR AND ZLIB_LIBRARY)
      SET(CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIR})
      SET(CMAKE_REQUIRED_LIBRARIES ${ZLIB_LIBRARY})
      GET_FILENAME_COMPONENT(ZLIB_NAME ${ZLIB_LIBRARY} NAME)
      CHECK_INCLUDE_FILES(zlib.h HAVE_ZLIB_H)
      CHECK_LIBRARY_EXISTS(${ZLIB_NAME} deflate "" HAVE_LIBZ)
      SET(CMAKE_REQUIRED_INCLUDES)
      SET(CMAKE_REQUIRED_LIBRARIES)
      INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR})
  
    ENDIF(ZLIB_INCLUDE_DIR AND ZLIB_LIBRARY)
  ENDIF(NOT WIN32)
ENDIF(WITH_ZLIB)

IF(WITH_BZIP)
  CHECK_INCLUDE_FILES(bzlib.h HAVE_BZLIB_H)
  CHECK_LIBRARY_EXISTS(bz2 BZ2_bzCompress "" HAVE_LIBBZ2)
ENDIF(WITH_BZIP)

IF(WITH_LDAP)
  CHECK_INCLUDE_FILES(ldap.h HAVE_LDAP_H)
  CHECK_LIBRARY_EXISTS(ldap ldap_bind "" HAVE_LIBLDAP)
  CHECK_INCLUDE_FILES(lber.h HAVE_LBER_H)
  CHECK_LIBRARY_EXISTS(lber ber_printf "" HAVE_LIBLBER)
  SET(LDAP_DEPRECATED 1) # Using deprecated ldap api
ENDIF(WITH_LDAP)

IF(WITH_LUA)
  pkg_search_module(LUA REQUIRED lua lua5.1)
  MESSAGE(STATUS "found lua at: INCDIR: ${LUA_INCLUDE_DIRS} LIBDIR: ${LUA_LIBRARY_DIRS} LDFLAGS: ${LUA_LDFLAGS} CFLAGS: ${LUA_CFLAGS}")
  SET(HAVE_LIBLUA 1 "Have liblua")
  SET(HAVE_LUA_H  1 "Have liblua header")
ENDIF(WITH_LUA)

IF(WITH_FAM)
  CHECK_INCLUDE_FILES(fam.h HAVE_FAM_H)
  CHECK_LIBRARY_EXISTS(fam FAMOpen2 "" HAVE_LIBFAM)
  IF(HAVE_LIBFAM)
    SET(CMAKE_REQUIRED_LIBRARIES fam)
    CHECK_FUNCTION_EXISTS(FAMNoExists HAVE_FAMNOEXISTS)
  ENDIF(HAVE_LIBFAM)
ENDIF(WITH_FAM)

IF(WITH_GDBM)
  CHECK_INCLUDE_FILES(gdbm.h HAVE_GDBM_H)
  CHECK_LIBRARY_EXISTS(gdbm gdbm_open "" HAVE_GDBM)
ENDIF(WITH_GDBM)

IF(WITH_MEMCACHE)
  CHECK_INCLUDE_FILES(memcache.h HAVE_MEMCACHE_H)
  CHECK_LIBRARY_EXISTS(memcache mc_new "" HAVE_MEMCACHE)
ENDIF(WITH_MEMCACHE)

IF(NOT BUILD_STATIC)
  CHECK_INCLUDE_FILES(dlfcn.h HAVE_DLFCN_H)
ENDIF(NOT BUILD_STATIC)

IF(HAVE_DLFCN_H)
  CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
ENDIF(HAVE_DLFCN_H)

SET(LIGHTTPD_VERSION_ID 10400)
SET(PACKAGE_NAME "${CMAKE_PROJECT_NAME}")
SET(PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}")
EXEC_PROGRAM(date ARGS "'+%b %d %Y %H:%M:%S UTC'" OUTPUT_VARIABLE PACKAGE_BUILD_DATE)

IF(NOT SBINDIR)
    SET(SBINDIR "sbin")
ENDIF(NOT SBINDIR)

IF(NOT LIGHTTPD_MODULES_DIR)
    SET(LIGHTTPD_MODULES_DIR "lib${LIB_SUFFIX}/lighttpd")
ENDIF(NOT LIGHTTPD_MODULES_DIR)

IF(NOT WIN32)
	SET(LIGHTTPD_LIBRARY_DIR "${CMAKE_INSTALL_PREFIX}/${LIGHTTPD_MODULES_DIR}")
ELSE(NOT WIN32)
	## We use relative path in windows
	SET(LIGHTTPD_LIBRARY_DIR "lib")
ENDIF(NOT WIN32)

## Write out config.h
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)

ADD_DEFINITIONS(-DHAVE_CONFIG_H)

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})

SET(COMMON_SRC
	buffer.c log.c
	keyvalue.c chunk.c
	http_chunk.c stream.c fdevent.c
	stat_cache.c plugin.c joblist.c etag.c array.c
	data_string.c data_count.c data_array.c
	data_integer.c md5.c data_fastcgi.c
	fdevent_select.c fdevent_linux_rtsig.c
	fdevent_poll.c fdevent_linux_sysepoll.c
	fdevent_solaris_devpoll.c fdevent_freebsd_kqueue.c
	data_config.c bitset.c
	inet_ntop_cache.c crc32.c
	connections-glue.c
	configfile-glue.c
	http-header-glue.c
	splaytree.c network_writev.c
	network_write.c network_linux_sendfile.c
	network_freebsd_sendfile.c
	network_solaris_sendfilev.c network_openssl.c
	status_counter.c
)

IF(WIN32)
  MESSAGE(STATUS "Adding local getopt implementation.")
  SET(COMMON_SRC ${COMMON_SRC} xgetopt.c)
ENDIF(WIN32)

ADD_EXECUTABLE(lemon lemon.c)

## Build parsers by using lemon...
LEMON_PARSER(configparser.y)
LEMON_PARSER(mod_ssi_exprparser.y)

SET(L_INSTALL_TARGETS)

ADD_EXECUTABLE(lighttpd-angel lighttpd-angel.c)
SET(L_INSTALL_TARGETS ${L_INSTALL_TARGETS} lighttpd-angel)
ADD_TARGET_PROPERTIES(lighttpd-angel COMPILE_FLAGS "-DSBIN_DIR=\\\\\"${CMAKE_INSTALL_PREFIX}/${SBINDIR}\\\\\"")

ADD_EXECUTABLE(lighttpd
	server.c
	response.c
	connections.c
	network.c
	configfile.c
	configparser.c
	request.c
	proc_open.c
	${COMMON_SRC}
)
SET(L_INSTALL_TARGETS ${L_INSTALL_TARGETS} lighttpd)

ADD_AND_INSTALL_LIBRARY(mod_access mod_access.c)
ADD_AND_INSTALL_LIBRARY(mod_accesslog mod_accesslog.c)
ADD_AND_INSTALL_LIBRARY(mod_alias mod_alias.c)
ADD_AND_INSTALL_LIBRARY(mod_auth "mod_auth.c;http_auth_digest.c;http_auth.c")
IF(NOT WIN32)
ADD_AND_INSTALL_LIBRARY(mod_cgi mod_cgi.c)
ENDIF(NOT WIN32)
ADD_AND_INSTALL_LIBRARY(mod_cml "mod_cml.c;mod_cml_lua.c;mod_cml_funcs.c")
ADD_AND_INSTALL_LIBRARY(mod_compress mod_compress.c)
ADD_AND_INSTALL_LIBRARY(mod_dirlisting mod_dirlisting.c)
ADD_AND_INSTALL_LIBRARY(mod_evasive mod_evasive.c)
ADD_AND_INSTALL_LIBRARY(mod_evhost mod_evhost.c)
ADD_AND_INSTALL_LIBRARY(mod_expire mod_expire.c)
ADD_AND_INSTALL_LIBRARY(mod_extforward mod_extforward.c)
ADD_AND_INSTALL_LIBRARY(mod_fastcgi mod_fastcgi.c)
ADD_AND_INSTALL_LIBRARY(mod_flv_streaming mod_flv_streaming.c)
ADD_AND_INSTALL_LIBRARY(mod_indexfile mod_indexfile.c)
ADD_AND_INSTALL_LIBRARY(mod_magnet "mod_magnet.c;mod_magnet_cache.c")
ADD_AND_INSTALL_LIBRARY(mod_mysql_vhost mod_mysql_vhost.c)
ADD_AND_INSTALL_LIBRARY(mod_proxy mod_proxy.c)
ADD_AND_INSTALL_LIBRARY(mod_redirect mod_redirect.c)
ADD_AND_INSTALL_LIBRARY(mod_rewrite mod_rewrite.c)
ADD_AND_INSTALL_LIBRARY(mod_rrdtool mod_rrdtool.c)
ADD_AND_INSTALL_LIBRARY(mod_scgi mod_scgi.c)
ADD_AND_INSTALL_LIBRARY(mod_secdownload mod_secure_download.c)
ADD_AND_INSTALL_LIBRARY(mod_setenv mod_setenv.c)
ADD_AND_INSTALL_LIBRARY(mod_simple_vhost mod_simple_vhost.c)
ADD_AND_INSTALL_LIBRARY(mod_ssi "mod_ssi_exprparser.c;mod_ssi_expr.c;mod_ssi.c")
ADD_AND_INSTALL_LIBRARY(mod_staticfile mod_staticfile.c)
ADD_AND_INSTALL_LIBRARY(mod_status mod_status.c)
ADD_AND_INSTALL_LIBRARY(mod_trigger_b4_dl mod_trigger_b4_dl.c)
# ADD_AND_INSTALL_LIBRARY(mod_uploadprogress mod_uploadprogress.c)
ADD_AND_INSTALL_LIBRARY(mod_userdir mod_userdir.c)
ADD_AND_INSTALL_LIBRARY(mod_usertrack mod_usertrack.c)
ADD_AND_INSTALL_LIBRARY(mod_webdav mod_webdav.c)

IF(HAVE_PCRE_H)
  ADD_TARGET_PROPERTIES(lighttpd LINK_FLAGS ${PCRE_LDFLAGS})
  ADD_TARGET_PROPERTIES(lighttpd COMPILE_FLAGS ${PCRE_CFLAGS})
  ADD_TARGET_PROPERTIES(mod_rewrite LINK_FLAGS ${PCRE_LDFLAGS})
  ADD_TARGET_PROPERTIES(mod_rewrite COMPILE_FLAGS ${PCRE_CFLAGS})
  ADD_TARGET_PROPERTIES(mod_dirlisting LINK_FLAGS ${PCRE_LDFLAGS})
  ADD_TARGET_PROPERTIES(mod_dirlisting COMPILE_FLAGS ${PCRE_CFLAGS})
  ADD_TARGET_PROPERTIES(mod_redirect LINK_FLAGS ${PCRE_LDFLAGS})
  ADD_TARGET_PROPERTIES(mod_redirect COMPILE_FLAGS ${PCRE_CFLAGS})
  ADD_TARGET_PROPERTIES(mod_ssi LINK_FLAGS ${PCRE_LDFLAGS})
  ADD_TARGET_PROPERTIES(mod_ssi COMPILE_FLAGS ${PCRE_CFLAGS})
  ADD_TARGET_PROPERTIES(mod_trigger_b4_dl LINK_FLAGS ${PCRE_LDFLAGS})
  ADD_TARGET_PROPERTIES(mod_trigger_b4_dl COMPILE_FLAGS ${PCRE_CFLAGS})
ENDIF(HAVE_PCRE_H)

ADD_TARGET_PROPERTIES(mod_magnet LINK_FLAGS ${LUA_LDFLAGS})
ADD_TARGET_PROPERTIES(mod_magnet COMPILE_FLAGS ${LUA_CFLAGS})

ADD_TARGET_PROPERTIES(mod_cml LINK_FLAGS ${LUA_LDFLAGS})
ADD_TARGET_PROPERTIES(mod_cml COMPILE_FLAGS ${LUA_CFLAGS})

IF(HAVE_MYSQL_H AND HAVE_MYSQL)
  TARGET_LINK_LIBRARIES(mod_mysql_vhost mysqlclient)
  INCLUDE_DIRECTORIES(/usr/include/mysql)
ENDIF(HAVE_MYSQL_H AND HAVE_MYSQL)

SET(L_MOD_WEBDAV)
IF(HAVE_SQLITE3_H)
  SET(L_MOD_WEBDAV ${L_MOD_WEBDAV} sqlite3)
ENDIF(HAVE_SQLITE3_H)
IF(HAVE_LIBXML_H)
  SET_TARGET_PROPERTIES(mod_webdav PROPERTIES LINK_FLAGS ${XML2_LDFLAGS})
ENDIF(HAVE_LIBXML_H)
IF(HAVE_UUID_H)
  IF(NEED_LIBUUID)
    SET(L_MOD_WEBDAV ${L_MOD_WEBDAV} uuid)
  ENDIF(NEED_LIBUUID)
ENDIF(HAVE_UUID_H)

TARGET_LINK_LIBRARIES(mod_webdav ${L_MOD_WEBDAV})

SET(L_MOD_AUTH)
IF(HAVE_LIBCRYPT)
  SET(L_MOD_AUTH ${L_MOD_AUTH} crypt)
ENDIF(HAVE_LIBCRYPT)

IF(HAVE_LDAP_H)
  SET(L_MOD_AUTH ${L_MOD_AUTH} ldap lber)
ENDIF(HAVE_LDAP_H)
TARGET_LINK_LIBRARIES(mod_auth ${L_MOD_AUTH})

IF(HAVE_ZLIB_H)
  IF(HAVE_BZLIB_H)
    TARGET_LINK_LIBRARIES(mod_compress ${ZLIB_LIBRARY} bz2)
  ELSE(HAVE_BZLIB_H)
    TARGET_LINK_LIBRARIES(mod_compress ${ZLIB_LIBRARY})
  ENDIF(HAVE_BZLIB_H)
ENDIF(HAVE_ZLIB_H)

IF(HAVE_LIBFAM)
  TARGET_LINK_LIBRARIES(lighttpd fam)
ENDIF(HAVE_LIBFAM)

IF(HAVE_GDBM_H)
  TARGET_LINK_LIBRARIES(mod_trigger_b4_dl gdbm)
ENDIF(HAVE_GDBM_H)

IF(HAVE_MEMCACHE_H)
  TARGET_LINK_LIBRARIES(mod_trigger_b4_dl memcache)
ENDIF(HAVE_MEMCACHE_H)

IF(CMAKE_COMPILER_IS_GNUCC)
  SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wall -g -Wshadow -W -pedantic ${WARN_FLAGS}")
  SET(CMAKE_C_FLAGS_RELEASE        "${CMAKE_C_FLAGS_RELEASE}     -O2")
  SET(CMAKE_C_FLAGS_DEBUG          "${CMAKE_C_FLAGS_DEBUG}       -O0")
  SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_WITHDEBINFO} -O2")
  ADD_DEFINITIONS(-D_GNU_SOURCE)
ENDIF(CMAKE_COMPILER_IS_GNUCC)

SET_TARGET_PROPERTIES(lighttpd PROPERTIES CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})

IF(WIN32)
  SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNVALGRIND")
  ADD_TARGET_PROPERTIES(lighttpd COMPILE_FLAGS "-DLI_DECLARE_EXPORTS")
  TARGET_LINK_LIBRARIES(lighttpd ws2_32)
  TARGET_LINK_LIBRARIES(mod_proxy ws2_32)
  TARGET_LINK_LIBRARIES(mod_fcgi ws2_32)
  TARGET_LINK_LIBRARIES(mod_scgi ws2_32)
  TARGET_LINK_LIBRARIES(mod_ssi ws2_32)

  IF(MINGW)
    TARGET_LINK_LIBRARIES(lighttpd msvcr70)
    ADD_TARGET_PROPERTIES(lighttpd LINK_FLAGS "-Wl,-subsystem,console")
  ENDIF(MINGW)
ENDIF(WIN32)

IF(NOT BUILD_STATIC)
  IF(HAVE_LIBDL)
    TARGET_LINK_LIBRARIES(lighttpd dl)
  ENDIF(HAVE_LIBDL)
ENDIF(NOT BUILD_STATIC)

IF(HAVE_LIBSSL AND HAVE_LIBCRYPTO)
  TARGET_LINK_LIBRARIES(lighttpd ssl)
  TARGET_LINK_LIBRARIES(lighttpd crypto)
ENDIF(HAVE_LIBSSL AND HAVE_LIBCRYPTO)

IF(NOT WIN32)
INSTALL(TARGETS ${L_INSTALL_TARGETS}
	RUNTIME DESTINATION ${SBINDIR}
	LIBRARY DESTINATION ${LIGHTTPD_MODULES_DIR}
	ARCHIVE DESTINATION ${LIGHTTPD_MODULES_DIR}/static)
ELSE(NOT WIN32)
## HACK to make win32 to install our libraries in desired directory..
INSTALL(TARGETS lighttpd
	RUNTIME DESTINATION ${SBINDIR}
	ARCHIVE DESTINATION lib/static)
LIST(REMOVE_ITEM L_INSTALL_TARGETS lighttpd)
INSTALL(TARGETS ${L_INSTALL_TARGETS}
	RUNTIME DESTINATION ${SBINDIR}/lib
	LIBRARY DESTINATION lib
	ARCHIVE DESTINATION lib/static)
ENDIF(NOT WIN32)
<commit_msg>[cmake] Remove -Wno-pointer-sign from extra warnings<commit_after>INCLUDE(CheckCSourceCompiles)
INCLUDE(CheckIncludeFiles)
INCLUDE(CheckFunctionExists)
INCLUDE(CheckVariableExists)
INCLUDE(CheckTypeSize)
INCLUDE(CheckLibraryExists)
INCLUDE(CMakeDetermineCCompiler)
INCLUDE(FindThreads)
INCLUDE(FindPkgConfig)

INCLUDE(LighttpdMacros)

ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGE_FILES)

OPTION(WITH_XATTR "with xattr-support for the stat-cache [default: off]")
OPTION(WITH_MYSQL "with mysql-support for the mod_sql_vhost [default: off]")
# OPTION(WITH_POSTGRESQL "with postgress-support for the mod_sql_vhost [default: off]")
OPTION(WITH_OPENSSL "with openssl-support [default: off]")
OPTION(WITH_PCRE "with regex support [default: on]" ON)
OPTION(WITH_WEBDAV_PROPS "with property-support for mod_webdav [default: off]")
OPTION(WITH_WEBDAV_LOCKS "locks in webdav [default: off]")
OPTION(WITH_BZIP "with bzip2-support for mod_compress [default: off]")
OPTION(WITH_ZLIB "with deflate-support for mod_compress [default: on]" ON)
OPTION(WITH_LDAP "with LDAP-support for the mod_auth [default: off]")
OPTION(WITH_LUA "with lua 5.1 for mod_magnet [default: off]")
# OPTION(WITH_VALGRIND "with internal support for valgrind [default: off]")
# OPTION(WITH_KERBEROS5 "use Kerberos5 support with OpenSSL [default: off]")
OPTION(WITH_FAM "fam/gamin for reducing number of stat() calls [default: off]")
OPTION(WITH_GDBM "gdbm storage for mod_trigger_b4_dl [default: off]")
OPTION(WITH_MEMCACHE "memcached storage for mod_trigger_b4_dl [default: off]")

IF(CMAKE_COMPILER_IS_GNUCC)
	OPTION(BUILD_EXTRA_WARNINGS "extra warnings")

	IF(BUILD_EXTRA_WARNINGS)
		SET(WARN_FLAGS "-g -O2 -g2 -Wall -Wmissing-declarations -Wdeclaration-after-statement -Wcast-align -Winline -Wsign-compare -Wnested-externs -Wpointer-arith -Wformat-security")
		# -Wl,--as-needed
		# -Werror -Wbad-function-cast -Wmissing-prototypes
	ELSE(BUILD_EXTRA_WARNINGS)
		SET(WARN_FLAGS "")
	ENDIF(BUILD_EXTRA_WARNINGS)
ENDIF(CMAKE_COMPILER_IS_GNUCC)

OPTION(BUILD_STATIC "build a static lighttpd with all modules added")

IF(BUILD_STATIC)
  SET(LIGHTTPD_STATIC 1)
ELSE(BUILD_STATIC)
  SET(CMAKE_SHARED_LIBRARY_PREFIX "")
ENDIF(BUILD_STATIC)

IF(WITH_WEBDAV_PROPS)
  SET(WITH_XML 1)
  SET(WITH_SQLITE3 1)
  SET(WITH_UUID 1)
ENDIF(WITH_WEBDAV_PROPS)

CHECK_INCLUDE_FILES(sys/devpoll.h HAVE_SYS_DEVPOLL_H)
CHECK_INCLUDE_FILES(sys/epoll.h HAVE_SYS_EPOLL_H)
CHECK_INCLUDE_FILES(sys/event.h HAVE_SYS_EVENT_H)
CHECK_INCLUDE_FILES(sys/mman.h HAVE_SYS_MMAN_H)
CHECK_INCLUDE_FILES(sys/poll.h HAVE_SYS_POLL_H)
CHECK_INCLUDE_FILES(sys/port.h HAVE_SYS_PORT_H)
CHECK_INCLUDE_FILES(sys/prctl.h HAVE_SYS_PRCTL_H)
CHECK_INCLUDE_FILES(sys/resource.h HAVE_SYS_RESOURCE_H)
CHECK_INCLUDE_FILES(sys/sendfile.h HAVE_SYS_SENDFILE_H)
CHECK_INCLUDE_FILES(sys/select.h HAVE_SYS_SELECT_H)
CHECK_INCLUDE_FILES(sys/syslimits.h HAVE_SYS_SYSLIMITS_H)
CHECK_INCLUDE_FILES(sys/types.h HAVE_SYS_TYPES_H)
CHECK_INCLUDE_FILES(sys/uio.h HAVE_SYS_UIO_H)
CHECK_INCLUDE_FILES(sys/un.h HAVE_SYS_UN_H)
CHECK_INCLUDE_FILES(sys/wait.h HAVE_SYS_WAIT_H)
CHECK_INCLUDE_FILES(sys/time.h HAVE_SYS_TIME_H)
CHECK_INCLUDE_FILES(unistd.h HAVE_UNISTD_H)
CHECK_INCLUDE_FILES(pthread.h HAVE_PTHREAD_H)
CHECK_INCLUDE_FILES(getopt.h HAVE_GETOPT_H)
CHECK_INCLUDE_FILES(inttypes.h HAVE_INTTYPES_H)
CHECK_INCLUDE_FILES(poll.h HAVE_POLL_H)
CHECK_INCLUDE_FILES(pwd.h HAVE_PWD_H)
CHECK_INCLUDE_FILES(stddef.h HAVE_STDDEF_H)
CHECK_INCLUDE_FILES(stdint.h HAVE_STDINT_H)
CHECK_INCLUDE_FILES(syslog.h HAVE_SYSLOG_H)

# check for fastcgi lib, for the tests only
CHECK_INCLUDE_FILES(fastcgi.h HAVE_FASTCGI_H)
CHECK_INCLUDE_FILES(fastcgi/fastcgi.h HAVE_FASTCGI_FASTCGI_H)

CHECK_INCLUDE_FILES(crypt.h HAVE_CRYPT_H)
IF(HAVE_CRYPT_H)
  ## check if we need libcrypt for crypt()
  CHECK_LIBRARY_EXISTS(crypt crypt "" HAVE_LIBCRYPT)
ENDIF(HAVE_CRYPT_H)

CHECK_INCLUDE_FILES(sys/inotify.h HAVE_SYS_INOTIFY_H)
IF(HAVE_SYS_INOTIFY_H)
  CHECK_FUNCTION_EXISTS(inotify_init HAVE_INOTIFY_INIT)
ENDIF(HAVE_SYS_INOTIFY_H)

SET(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
CHECK_TYPE_SIZE(socklen_t HAVE_SOCKLEN_T)
SET(CMAKE_EXTRA_INCLUDE_FILES)

CHECK_TYPE_SIZE(long SIZEOF_LONG)
CHECK_TYPE_SIZE(off_t SIZEOF_OFF_T)

CHECK_FUNCTION_EXISTS(chroot HAVE_CHROOT)
CHECK_FUNCTION_EXISTS(crypt HAVE_CRYPT)
CHECK_FUNCTION_EXISTS(epoll_ctl HAVE_EPOLL_CTL)
CHECK_FUNCTION_EXISTS(fork HAVE_FORK)
CHECK_FUNCTION_EXISTS(getrlimit HAVE_GETRLIMIT)
CHECK_FUNCTION_EXISTS(getuid HAVE_GETUID)
CHECK_FUNCTION_EXISTS(gmtime_r HAVE_GMTIME_R)
CHECK_FUNCTION_EXISTS(inet_ntop HAVE_INET_NTOP)
CHECK_FUNCTION_EXISTS(kqueue HAVE_KQUEUE)
CHECK_FUNCTION_EXISTS(localtime_r HAVE_LOCALTIME_R)
CHECK_FUNCTION_EXISTS(lstat HAVE_LSTAT)
CHECK_FUNCTION_EXISTS(madvise HAVE_MADVISE)
CHECK_FUNCTION_EXISTS(memcpy HAVE_MEMCPY)
CHECK_FUNCTION_EXISTS(memset HAVE_MEMSET)
CHECK_FUNCTION_EXISTS(mmap HAVE_MMAP)
CHECK_FUNCTION_EXISTS(pathconf HAVE_PATHCONF)
CHECK_FUNCTION_EXISTS(poll HAVE_POLL)
CHECK_FUNCTION_EXISTS(port_create HAVE_PORT_CREATE)
CHECK_FUNCTION_EXISTS(prctl HAVE_PRCTL)
CHECK_FUNCTION_EXISTS(pread HAVE_PREAD)
CHECK_FUNCTION_EXISTS(posix_fadvise HAVE_POSIX_FADVISE)
CHECK_FUNCTION_EXISTS(select HAVE_SELECT)
CHECK_FUNCTION_EXISTS(sendfile HAVE_SENDFILE)
CHECK_FUNCTION_EXISTS(send_file HAVE_SEND_FILE)
CHECK_FUNCTION_EXISTS(sendfile64 HAVE_SENDFILE64)
CHECK_FUNCTION_EXISTS(sendfilev HAVE_SENDFILEV)
CHECK_FUNCTION_EXISTS(sigaction HAVE_SIGACTION)
CHECK_FUNCTION_EXISTS(signal HAVE_SIGNAL)
CHECK_FUNCTION_EXISTS(sigtimedwait HAVE_SIGTIMEDWAIT)
CHECK_FUNCTION_EXISTS(strptime HAVE_STRPTIME)
CHECK_FUNCTION_EXISTS(syslog HAVE_SYSLOG)
CHECK_FUNCTION_EXISTS(writev HAVE_WRITEV)
CHECK_FUNCTION_EXISTS(inet_aton HAVE_INET_ATON)
CHECK_C_SOURCE_COMPILES("
	#include <sys/types.h>
	#include <sys/socket.h>
	#include <netinet/in.h>
	
	int main() {
		struct sockaddr_in6 s; struct in6_addr t=in6addr_any; int i=AF_INET6; s; t.s6_addr[0] = 0;
		return 0;
	}" HAVE_IPV6)
CHECK_FUNCTION_EXISTS(issetugid HAVE_ISSETUGID)
CHECK_FUNCTION_EXISTS(inet_pton HAVE_INET_PTON)

## refactor me
MACRO(XCONFIG _package _include_DIR _link_DIR _link_FLAGS _cflags)
# reset the variables at the beginning
  SET(${_include_DIR})
  SET(${_link_DIR})
  SET(${_link_FLAGS})
  SET(${_cflags})

  FIND_PROGRAM(${_package}CONFIG_EXECUTABLE NAMES ${_package} PATHS /usr/local/bin )

  # if pkg-config has been found
  IF(${_package}CONFIG_EXECUTABLE)
    SET(XCONFIG_EXECUTABLE "${${_package}CONFIG_EXECUTABLE}")
    MESSAGE(STATUS "found ${_package}: ${XCONFIG_EXECUTABLE}")

    EXEC_PROGRAM(${XCONFIG_EXECUTABLE} ARGS --libs OUTPUT_VARIABLE __link_FLAGS)
    STRING(REPLACE "\n" "" ${_link_FLAGS} ${__link_FLAGS})
    EXEC_PROGRAM(${XCONFIG_EXECUTABLE} ARGS --cflags OUTPUT_VARIABLE __cflags)
    STRING(REPLACE "\n" "" ${_cflags} ${__cflags})

  ELSE(${_package}CONFIG_EXECUTABLE)
    MESSAGE(STATUS "found ${_package}: no")
  ENDIF(${_package}CONFIG_EXECUTABLE)
ENDMACRO(XCONFIG _package _include_DIR _link_DIR _link_FLAGS _cflags)

IF(WITH_XATTR)
  CHECK_INCLUDE_FILES(attr/attributes.h HAVE_ATTR_ATTRIBUTES_H)
  IF(HAVE_ATTR_ATTRIBUTES_H)
    CHECK_LIBRARY_EXISTS(attr attr_get "" HAVE_XATTR)
  ENDIF(HAVE_ATTR_ATTRIBUTES_H)
ENDIF(WITH_XATTR)

IF(WITH_MYSQL)
  XCONFIG(mysql_config MYSQL_INCDIR MYSQL_LIBDIR MYSQL_LDFLAGS MYSQL_CFLAGS)

  SET(CMAKE_REQUIRED_INCLUDES /usr/include/mysql)
  CHECK_INCLUDE_FILES(mysql.h HAVE_MYSQL_H)
  SET(CMAKE_REQUIRED_INCLUDES)
  IF(HAVE_MYSQL_H)
    CHECK_LIBRARY_EXISTS(mysqlclient mysql_real_connect "" HAVE_MYSQL)
  ENDIF(HAVE_MYSQL_H)
ENDIF(WITH_MYSQL)

IF(WITH_OPENSSL)
  CHECK_INCLUDE_FILES(openssl/ssl.h HAVE_OPENSSL_SSL_H)
  IF(HAVE_OPENSSL_SSL_H)
    CHECK_LIBRARY_EXISTS(crypto BIO_f_base64 "" HAVE_LIBCRYPTO)
    IF(HAVE_LIBCRYPTO)
      SET(OPENSSL_NO_KRB5 1)
      CHECK_LIBRARY_EXISTS(ssl SSL_new "" HAVE_LIBSSL)
    ENDIF(HAVE_LIBCRYPTO)
  ENDIF(HAVE_OPENSSL_SSL_H)
ENDIF(WITH_OPENSSL)

IF(WITH_PCRE)
  ## if we have pcre-config, use it
  XCONFIG(pcre-config PCRE_INCDIR PCRE_LIBDIR PCRE_LDFLAGS PCRE_CFLAGS)
  IF(PCRE_LDFLAGS OR PCRE_CFLAGS)
    MESSAGE(STATUS "found pcre at: LDFLAGS: ${PCRE_LDFLAGS} CFLAGS: ${PCRE_CFLAGS}")

    IF(NOT PCRE_CFLAGS STREQUAL "\n")
      ## if it is empty we'll get newline returned
      SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PCRE_CFLAGS}")
    ENDIF(NOT PCRE_CFLAGS STREQUAL "\n")

    SET(HAVE_PCRE_H 1)
    SET(HAVE_LIBPCRE 1)
  ELSE(PCRE_LDFLAGS OR PCRE_CFLAGS) 
    IF(NOT WIN32)
      CHECK_INCLUDE_FILES(pcre.h HAVE_PCRE_H)
      CHECK_LIBRARY_EXISTS(pcre pcre_exec "" HAVE_LIBPCRE)
      SET(PCRE_LDFLAGS -lpcre)
    ELSE(NOT WIN32)
      FIND_PATH(PCRE_INCLUDE_DIR pcre.h
      /usr/local/include
      /usr/include
      )
  
      SET(PCRE_NAMES pcre)
      FIND_LIBRARY(PCRE_LIBRARY
      NAMES ${PCRE_NAMES}
      PATHS /usr/lib /usr/local/lib
      )
  
      IF(PCRE_INCLUDE_DIR AND PCRE_LIBRARY)
        SET(CMAKE_REQUIRED_INCLUDES ${PCRE_INCLUDE_DIR})
        SET(CMAKE_REQUIRED_LIBRARIES ${PCRE_LIBRARY})
        CHECK_INCLUDE_FILES(pcre.h HAVE_PCRE_H)
        CHECK_LIBRARY_EXISTS(pcre pcre_exec "" HAVE_LIBPCRE)
        SET(CMAKE_REQUIRED_INCLUDES)
        SET(CMAKE_REQUIRED_LIBRARIES)
        INCLUDE_DIRECTORIES(${PCRE_INCLUDE_DIR})
      ENDIF(PCRE_INCLUDE_DIR AND PCRE_LIBRARY)
    ENDIF(NOT WIN32)
  ENDIF(PCRE_LDFLAGS OR PCRE_CFLAGS) 

  IF(NOT HAVE_PCRE_H)
    MESSAGE(FATAL_ERROR "pcre.h couldn't be found")
  ENDIF(NOT HAVE_PCRE_H)
  IF(NOT HAVE_LIBPCRE)
    MESSAGE(FATAL_ERROR "libpcre couldn't be found")
  ENDIF(NOT HAVE_LIBPCRE)

ENDIF(WITH_PCRE)


IF(WITH_XML)
  XCONFIG(xml2-config XML2_INCDIR XML2_LIBDIR XML2_LDFLAGS XML2_CFLAGS)
  IF(XML2_LDFLAGS OR XML2_CFLAGS) 
    MESSAGE(STATUS "found xml2 at: LDFLAGS: ${XML2_LDFLAGS} CFLAGS: ${XML2_CFLAGS}")

    ## if it is empty we'll get newline returned
    SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${XML2_CFLAGS}")

    CHECK_INCLUDE_FILES(libxml/tree.h HAVE_LIBXML_H)

    SET(CMAKE_REQUIRED_FLAGS ${XML2_LDFLAGS})
    CHECK_LIBRARY_EXISTS(xml2 xmlParseChunk "" HAVE_LIBXML)
    SET(CMAKE_REQUIRED_FLAGS)
  ELSE(XML2_LDFLAGS OR XML2_CFLAGS) 
    CHECK_INCLUDE_FILES(libxml.h HAVE_LIBXML_H)
    CHECK_LIBRARY_EXISTS(xml2 xmlParseChunk "" HAVE_LIBXML)
  ENDIF(XML2_LDFLAGS OR XML2_CFLAGS) 

  IF(NOT HAVE_LIBXML_H)
    MESSAGE(FATAL_ERROR "libxml/tree.h couldn't be found")
  ENDIF(NOT HAVE_LIBXML_H)
  IF(NOT HAVE_LIBXML)
    MESSAGE(FATAL_ERROR "libxml2 couldn't be found")
  ENDIF(NOT HAVE_LIBXML)

ENDIF(WITH_XML)

IF(WITH_SQLITE3)
  CHECK_INCLUDE_FILES(sqlite3.h HAVE_SQLITE3_H)
  CHECK_LIBRARY_EXISTS(sqlite3 sqlite3_reset "" HAVE_SQLITE3)
ENDIF(WITH_SQLITE3)

IF(WITH_UUID)
  CHECK_INCLUDE_FILES(uuid/uuid.h HAVE_UUID_UUID_H)
  CHECK_LIBRARY_EXISTS(uuid uuid_generate "" NEED_LIBUUID)
  IF(NOT NEED_LIBUUID)
    CHECK_FUNCTION_EXISTS(uuid_generate HAVE_LIBUUID)
  ELSE(NOT NEED_LIBUUID)
    SET(HAVE_LIBUUID 1)
  ENDIF(NOT NEED_LIBUUID)
ENDIF(WITH_UUID)

IF(WITH_ZLIB)
  IF(NOT WIN32)
    CHECK_INCLUDE_FILES(zlib.h HAVE_ZLIB_H)
    CHECK_LIBRARY_EXISTS(z deflate "" HAVE_LIBZ)
		SET(ZLIB_LIBRARY z)
  ELSE(NOT WIN32)
    FIND_PATH(ZLIB_INCLUDE_DIR zlib.h
    /usr/local/include
    /usr/include
    )
  
    SET(ZLIB_NAMES z zlib zdll)
    FIND_LIBRARY(ZLIB_LIBRARY
    NAMES ${ZLIB_NAMES}
    PATHS /usr/lib /usr/local/lib
    )
  
  
    IF(ZLIB_INCLUDE_DIR AND ZLIB_LIBRARY)
      SET(CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIR})
      SET(CMAKE_REQUIRED_LIBRARIES ${ZLIB_LIBRARY})
      GET_FILENAME_COMPONENT(ZLIB_NAME ${ZLIB_LIBRARY} NAME)
      CHECK_INCLUDE_FILES(zlib.h HAVE_ZLIB_H)
      CHECK_LIBRARY_EXISTS(${ZLIB_NAME} deflate "" HAVE_LIBZ)
      SET(CMAKE_REQUIRED_INCLUDES)
      SET(CMAKE_REQUIRED_LIBRARIES)
      INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR})
  
    ENDIF(ZLIB_INCLUDE_DIR AND ZLIB_LIBRARY)
  ENDIF(NOT WIN32)
ENDIF(WITH_ZLIB)

IF(WITH_BZIP)
  CHECK_INCLUDE_FILES(bzlib.h HAVE_BZLIB_H)
  CHECK_LIBRARY_EXISTS(bz2 BZ2_bzCompress "" HAVE_LIBBZ2)
ENDIF(WITH_BZIP)

IF(WITH_LDAP)
  CHECK_INCLUDE_FILES(ldap.h HAVE_LDAP_H)
  CHECK_LIBRARY_EXISTS(ldap ldap_bind "" HAVE_LIBLDAP)
  CHECK_INCLUDE_FILES(lber.h HAVE_LBER_H)
  CHECK_LIBRARY_EXISTS(lber ber_printf "" HAVE_LIBLBER)
  SET(LDAP_DEPRECATED 1) # Using deprecated ldap api
ENDIF(WITH_LDAP)

IF(WITH_LUA)
  pkg_search_module(LUA REQUIRED lua lua5.1)
  MESSAGE(STATUS "found lua at: INCDIR: ${LUA_INCLUDE_DIRS} LIBDIR: ${LUA_LIBRARY_DIRS} LDFLAGS: ${LUA_LDFLAGS} CFLAGS: ${LUA_CFLAGS}")
  SET(HAVE_LIBLUA 1 "Have liblua")
  SET(HAVE_LUA_H  1 "Have liblua header")
ENDIF(WITH_LUA)

IF(WITH_FAM)
  CHECK_INCLUDE_FILES(fam.h HAVE_FAM_H)
  CHECK_LIBRARY_EXISTS(fam FAMOpen2 "" HAVE_LIBFAM)
  IF(HAVE_LIBFAM)
    SET(CMAKE_REQUIRED_LIBRARIES fam)
    CHECK_FUNCTION_EXISTS(FAMNoExists HAVE_FAMNOEXISTS)
  ENDIF(HAVE_LIBFAM)
ENDIF(WITH_FAM)

IF(WITH_GDBM)
  CHECK_INCLUDE_FILES(gdbm.h HAVE_GDBM_H)
  CHECK_LIBRARY_EXISTS(gdbm gdbm_open "" HAVE_GDBM)
ENDIF(WITH_GDBM)

IF(WITH_MEMCACHE)
  CHECK_INCLUDE_FILES(memcache.h HAVE_MEMCACHE_H)
  CHECK_LIBRARY_EXISTS(memcache mc_new "" HAVE_MEMCACHE)
ENDIF(WITH_MEMCACHE)

IF(NOT BUILD_STATIC)
  CHECK_INCLUDE_FILES(dlfcn.h HAVE_DLFCN_H)
ENDIF(NOT BUILD_STATIC)

IF(HAVE_DLFCN_H)
  CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
ENDIF(HAVE_DLFCN_H)

SET(LIGHTTPD_VERSION_ID 10400)
SET(PACKAGE_NAME "${CMAKE_PROJECT_NAME}")
SET(PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}")
EXEC_PROGRAM(date ARGS "'+%b %d %Y %H:%M:%S UTC'" OUTPUT_VARIABLE PACKAGE_BUILD_DATE)

IF(NOT SBINDIR)
    SET(SBINDIR "sbin")
ENDIF(NOT SBINDIR)

IF(NOT LIGHTTPD_MODULES_DIR)
    SET(LIGHTTPD_MODULES_DIR "lib${LIB_SUFFIX}/lighttpd")
ENDIF(NOT LIGHTTPD_MODULES_DIR)

IF(NOT WIN32)
	SET(LIGHTTPD_LIBRARY_DIR "${CMAKE_INSTALL_PREFIX}/${LIGHTTPD_MODULES_DIR}")
ELSE(NOT WIN32)
	## We use relative path in windows
	SET(LIGHTTPD_LIBRARY_DIR "lib")
ENDIF(NOT WIN32)

## Write out config.h
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)

ADD_DEFINITIONS(-DHAVE_CONFIG_H)

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})

SET(COMMON_SRC
	buffer.c log.c
	keyvalue.c chunk.c
	http_chunk.c stream.c fdevent.c
	stat_cache.c plugin.c joblist.c etag.c array.c
	data_string.c data_count.c data_array.c
	data_integer.c md5.c data_fastcgi.c
	fdevent_select.c fdevent_linux_rtsig.c
	fdevent_poll.c fdevent_linux_sysepoll.c
	fdevent_solaris_devpoll.c fdevent_freebsd_kqueue.c
	data_config.c bitset.c
	inet_ntop_cache.c crc32.c
	connections-glue.c
	configfile-glue.c
	http-header-glue.c
	splaytree.c network_writev.c
	network_write.c network_linux_sendfile.c
	network_freebsd_sendfile.c
	network_solaris_sendfilev.c network_openssl.c
	status_counter.c
)

IF(WIN32)
  MESSAGE(STATUS "Adding local getopt implementation.")
  SET(COMMON_SRC ${COMMON_SRC} xgetopt.c)
ENDIF(WIN32)

ADD_EXECUTABLE(lemon lemon.c)

## Build parsers by using lemon...
LEMON_PARSER(configparser.y)
LEMON_PARSER(mod_ssi_exprparser.y)

SET(L_INSTALL_TARGETS)

ADD_EXECUTABLE(lighttpd-angel lighttpd-angel.c)
SET(L_INSTALL_TARGETS ${L_INSTALL_TARGETS} lighttpd-angel)
ADD_TARGET_PROPERTIES(lighttpd-angel COMPILE_FLAGS "-DSBIN_DIR=\\\\\"${CMAKE_INSTALL_PREFIX}/${SBINDIR}\\\\\"")

ADD_EXECUTABLE(lighttpd
	server.c
	response.c
	connections.c
	network.c
	configfile.c
	configparser.c
	request.c
	proc_open.c
	${COMMON_SRC}
)
SET(L_INSTALL_TARGETS ${L_INSTALL_TARGETS} lighttpd)

ADD_AND_INSTALL_LIBRARY(mod_access mod_access.c)
ADD_AND_INSTALL_LIBRARY(mod_accesslog mod_accesslog.c)
ADD_AND_INSTALL_LIBRARY(mod_alias mod_alias.c)
ADD_AND_INSTALL_LIBRARY(mod_auth "mod_auth.c;http_auth_digest.c;http_auth.c")
IF(NOT WIN32)
ADD_AND_INSTALL_LIBRARY(mod_cgi mod_cgi.c)
ENDIF(NOT WIN32)
ADD_AND_INSTALL_LIBRARY(mod_cml "mod_cml.c;mod_cml_lua.c;mod_cml_funcs.c")
ADD_AND_INSTALL_LIBRARY(mod_compress mod_compress.c)
ADD_AND_INSTALL_LIBRARY(mod_dirlisting mod_dirlisting.c)
ADD_AND_INSTALL_LIBRARY(mod_evasive mod_evasive.c)
ADD_AND_INSTALL_LIBRARY(mod_evhost mod_evhost.c)
ADD_AND_INSTALL_LIBRARY(mod_expire mod_expire.c)
ADD_AND_INSTALL_LIBRARY(mod_extforward mod_extforward.c)
ADD_AND_INSTALL_LIBRARY(mod_fastcgi mod_fastcgi.c)
ADD_AND_INSTALL_LIBRARY(mod_flv_streaming mod_flv_streaming.c)
ADD_AND_INSTALL_LIBRARY(mod_indexfile mod_indexfile.c)
ADD_AND_INSTALL_LIBRARY(mod_magnet "mod_magnet.c;mod_magnet_cache.c")
ADD_AND_INSTALL_LIBRARY(mod_mysql_vhost mod_mysql_vhost.c)
ADD_AND_INSTALL_LIBRARY(mod_proxy mod_proxy.c)
ADD_AND_INSTALL_LIBRARY(mod_redirect mod_redirect.c)
ADD_AND_INSTALL_LIBRARY(mod_rewrite mod_rewrite.c)
ADD_AND_INSTALL_LIBRARY(mod_rrdtool mod_rrdtool.c)
ADD_AND_INSTALL_LIBRARY(mod_scgi mod_scgi.c)
ADD_AND_INSTALL_LIBRARY(mod_secdownload mod_secure_download.c)
ADD_AND_INSTALL_LIBRARY(mod_setenv mod_setenv.c)
ADD_AND_INSTALL_LIBRARY(mod_simple_vhost mod_simple_vhost.c)
ADD_AND_INSTALL_LIBRARY(mod_ssi "mod_ssi_exprparser.c;mod_ssi_expr.c;mod_ssi.c")
ADD_AND_INSTALL_LIBRARY(mod_staticfile mod_staticfile.c)
ADD_AND_INSTALL_LIBRARY(mod_status mod_status.c)
ADD_AND_INSTALL_LIBRARY(mod_trigger_b4_dl mod_trigger_b4_dl.c)
# ADD_AND_INSTALL_LIBRARY(mod_uploadprogress mod_uploadprogress.c)
ADD_AND_INSTALL_LIBRARY(mod_userdir mod_userdir.c)
ADD_AND_INSTALL_LIBRARY(mod_usertrack mod_usertrack.c)
ADD_AND_INSTALL_LIBRARY(mod_webdav mod_webdav.c)

IF(HAVE_PCRE_H)
  ADD_TARGET_PROPERTIES(lighttpd LINK_FLAGS ${PCRE_LDFLAGS})
  ADD_TARGET_PROPERTIES(lighttpd COMPILE_FLAGS ${PCRE_CFLAGS})
  ADD_TARGET_PROPERTIES(mod_rewrite LINK_FLAGS ${PCRE_LDFLAGS})
  ADD_TARGET_PROPERTIES(mod_rewrite COMPILE_FLAGS ${PCRE_CFLAGS})
  ADD_TARGET_PROPERTIES(mod_dirlisting LINK_FLAGS ${PCRE_LDFLAGS})
  ADD_TARGET_PROPERTIES(mod_dirlisting COMPILE_FLAGS ${PCRE_CFLAGS})
  ADD_TARGET_PROPERTIES(mod_redirect LINK_FLAGS ${PCRE_LDFLAGS})
  ADD_TARGET_PROPERTIES(mod_redirect COMPILE_FLAGS ${PCRE_CFLAGS})
  ADD_TARGET_PROPERTIES(mod_ssi LINK_FLAGS ${PCRE_LDFLAGS})
  ADD_TARGET_PROPERTIES(mod_ssi COMPILE_FLAGS ${PCRE_CFLAGS})
  ADD_TARGET_PROPERTIES(mod_trigger_b4_dl LINK_FLAGS ${PCRE_LDFLAGS})
  ADD_TARGET_PROPERTIES(mod_trigger_b4_dl COMPILE_FLAGS ${PCRE_CFLAGS})
ENDIF(HAVE_PCRE_H)

ADD_TARGET_PROPERTIES(mod_magnet LINK_FLAGS ${LUA_LDFLAGS})
ADD_TARGET_PROPERTIES(mod_magnet COMPILE_FLAGS ${LUA_CFLAGS})

ADD_TARGET_PROPERTIES(mod_cml LINK_FLAGS ${LUA_LDFLAGS})
ADD_TARGET_PROPERTIES(mod_cml COMPILE_FLAGS ${LUA_CFLAGS})

IF(HAVE_MYSQL_H AND HAVE_MYSQL)
  TARGET_LINK_LIBRARIES(mod_mysql_vhost mysqlclient)
  INCLUDE_DIRECTORIES(/usr/include/mysql)
ENDIF(HAVE_MYSQL_H AND HAVE_MYSQL)

SET(L_MOD_WEBDAV)
IF(HAVE_SQLITE3_H)
  SET(L_MOD_WEBDAV ${L_MOD_WEBDAV} sqlite3)
ENDIF(HAVE_SQLITE3_H)
IF(HAVE_LIBXML_H)
  SET_TARGET_PROPERTIES(mod_webdav PROPERTIES LINK_FLAGS ${XML2_LDFLAGS})
ENDIF(HAVE_LIBXML_H)
IF(HAVE_UUID_H)
  IF(NEED_LIBUUID)
    SET(L_MOD_WEBDAV ${L_MOD_WEBDAV} uuid)
  ENDIF(NEED_LIBUUID)
ENDIF(HAVE_UUID_H)

TARGET_LINK_LIBRARIES(mod_webdav ${L_MOD_WEBDAV})

SET(L_MOD_AUTH)
IF(HAVE_LIBCRYPT)
  SET(L_MOD_AUTH ${L_MOD_AUTH} crypt)
ENDIF(HAVE_LIBCRYPT)

IF(HAVE_LDAP_H)
  SET(L_MOD_AUTH ${L_MOD_AUTH} ldap lber)
ENDIF(HAVE_LDAP_H)
TARGET_LINK_LIBRARIES(mod_auth ${L_MOD_AUTH})

IF(HAVE_ZLIB_H)
  IF(HAVE_BZLIB_H)
    TARGET_LINK_LIBRARIES(mod_compress ${ZLIB_LIBRARY} bz2)
  ELSE(HAVE_BZLIB_H)
    TARGET_LINK_LIBRARIES(mod_compress ${ZLIB_LIBRARY})
  ENDIF(HAVE_BZLIB_H)
ENDIF(HAVE_ZLIB_H)

IF(HAVE_LIBFAM)
  TARGET_LINK_LIBRARIES(lighttpd fam)
ENDIF(HAVE_LIBFAM)

IF(HAVE_GDBM_H)
  TARGET_LINK_LIBRARIES(mod_trigger_b4_dl gdbm)
ENDIF(HAVE_GDBM_H)

IF(HAVE_MEMCACHE_H)
  TARGET_LINK_LIBRARIES(mod_trigger_b4_dl memcache)
ENDIF(HAVE_MEMCACHE_H)

IF(CMAKE_COMPILER_IS_GNUCC)
  SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wall -g -Wshadow -W -pedantic ${WARN_FLAGS}")
  SET(CMAKE_C_FLAGS_RELEASE        "${CMAKE_C_FLAGS_RELEASE}     -O2")
  SET(CMAKE_C_FLAGS_DEBUG          "${CMAKE_C_FLAGS_DEBUG}       -O0")
  SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_WITHDEBINFO} -O2")
  ADD_DEFINITIONS(-D_GNU_SOURCE)
ENDIF(CMAKE_COMPILER_IS_GNUCC)

SET_TARGET_PROPERTIES(lighttpd PROPERTIES CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})

IF(WIN32)
  SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNVALGRIND")
  ADD_TARGET_PROPERTIES(lighttpd COMPILE_FLAGS "-DLI_DECLARE_EXPORTS")
  TARGET_LINK_LIBRARIES(lighttpd ws2_32)
  TARGET_LINK_LIBRARIES(mod_proxy ws2_32)
  TARGET_LINK_LIBRARIES(mod_fcgi ws2_32)
  TARGET_LINK_LIBRARIES(mod_scgi ws2_32)
  TARGET_LINK_LIBRARIES(mod_ssi ws2_32)

  IF(MINGW)
    TARGET_LINK_LIBRARIES(lighttpd msvcr70)
    ADD_TARGET_PROPERTIES(lighttpd LINK_FLAGS "-Wl,-subsystem,console")
  ENDIF(MINGW)
ENDIF(WIN32)

IF(NOT BUILD_STATIC)
  IF(HAVE_LIBDL)
    TARGET_LINK_LIBRARIES(lighttpd dl)
  ENDIF(HAVE_LIBDL)
ENDIF(NOT BUILD_STATIC)

IF(HAVE_LIBSSL AND HAVE_LIBCRYPTO)
  TARGET_LINK_LIBRARIES(lighttpd ssl)
  TARGET_LINK_LIBRARIES(lighttpd crypto)
ENDIF(HAVE_LIBSSL AND HAVE_LIBCRYPTO)

IF(NOT WIN32)
INSTALL(TARGETS ${L_INSTALL_TARGETS}
	RUNTIME DESTINATION ${SBINDIR}
	LIBRARY DESTINATION ${LIGHTTPD_MODULES_DIR}
	ARCHIVE DESTINATION ${LIGHTTPD_MODULES_DIR}/static)
ELSE(NOT WIN32)
## HACK to make win32 to install our libraries in desired directory..
INSTALL(TARGETS lighttpd
	RUNTIME DESTINATION ${SBINDIR}
	ARCHIVE DESTINATION lib/static)
LIST(REMOVE_ITEM L_INSTALL_TARGETS lighttpd)
INSTALL(TARGETS ${L_INSTALL_TARGETS}
	RUNTIME DESTINATION ${SBINDIR}/lib
	LIBRARY DESTINATION lib
	ARCHIVE DESTINATION lib/static)
ENDIF(NOT WIN32)

{'fraction_non_alphanumeric': 0.08646413383144193, 'fraction_numerical': 0.00704870656234581, 'mean_word_length': 7.470049751243781, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 20}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7442864', 'n_tokens_mistral': 19132, 'n_tokens_neox': 17624, 'n_words': 2512}