1include(CheckCSourceCompiles) 2include(CheckIncludeFiles) 3include(CheckFunctionExists) 4include(CheckSymbolExists) 5include(CheckVariableExists) 6include(CheckTypeSize) 7include(CheckLibraryExists) 8include(CMakeDetermineCCompiler) 9find_package(PkgConfig) 10 11include(LighttpdMacros) 12 13add_definitions(-D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGE_FILES -D_DEFAULT_SOURCE) 14 15# default to ON 16set(CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "Default value for ``POSITION_INDEPENDENT_CODE`` of targets.") 17 18option(WITH_XATTR "with xattr-support for the stat-cache [default: off]") 19option(WITH_MYSQL "with mysql-support for mod_vhostdb_mysql [default: off]") 20option(WITH_PGSQL "with postgres-support for mod_vhostdb_pgsql [default: off]") 21option(WITH_DBI "with dbi-support for mod_vhostdb_dbi [default: off]") 22option(WITH_GNUTLS "with GnuTLS-support [default: off]") 23option(WITH_MBEDTLS "with mbedTLS-support [default: off]") 24option(WITH_NSS "with NSS-crypto-support [default: off]") 25option(WITH_OPENSSL "with openssl-support [default: off]") 26option(WITH_WOLFSSL "with wolfSSL-support [default: off]") 27option(WITH_NETTLE "with Nettle-support [default: off]") 28option(WITH_PCRE2 "with regex support [default: on]" ON) 29option(WITH_PCRE "with regex support [default: off]") 30option(WITH_WEBDAV_PROPS "with property-support for mod_webdav [default: off]") 31option(WITH_WEBDAV_LOCKS "locks in webdav [default: off]") 32option(WITH_BROTLI "with brotli-support for mod_deflate [default: off]") 33option(WITH_BZIP "with bzip2-support for mod_deflate [default: off]") 34option(WITH_ZLIB "with deflate-support for mod_deflate [default: on]" ON) 35option(WITH_ZSTD "with zstd-support for mod_deflate [default: off]") 36option(WITH_KRB5 "with Kerberos5-support for mod_auth [default: off]") 37option(WITH_LDAP "with LDAP-support for mod_auth mod_vhostdb_ldap [default: off]") 38option(WITH_PAM "with PAM-support for mod_auth [default: off]") 39option(WITH_LUA "with lua for mod_magnet [default: off]") 40option(WITH_LUA_VERSION "specify lua version for mod_magnet") 41# option(WITH_VALGRIND "with internal support for valgrind [default: off]") 42option(WITH_FAM "fam/gamin for reducing number of stat() calls [default: off]") 43option(WITH_LIBDEFLATE "with libdeflate-support for mod_deflate [default: off]") 44option(WITH_LIBEV "libev support for fdevent handlers [default: off]") 45option(WITH_LIBUNWIND "with libunwind to print backtraces in asserts [default: off]") 46option(WITH_MAXMINDDB "with MaxMind GeoIP2-support mod_maxminddb [default: off]") 47option(WITH_SASL "with SASL-support for mod_authn_sasl [default: off]") 48option(WITH_XXHASH "with system-provided xxhash [default: off]") 49 50if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang") 51 option(BUILD_EXTRA_WARNINGS "extra warnings") 52 option(BUILD_SANITIZE_ADDRESS "Enable address sanitizer" OFF) 53 option(BUILD_SANITIZE_UNDEFINED "Enable undefined sanitizer" OFF) 54 55 if(BUILD_EXTRA_WARNINGS) 56 set(WARN_CFLAGS "-g -g2 -Wall -Wmissing-declarations -Wcast-align -Wsign-compare -Wnested-externs -Wpointer-arith -D_FORTIFY_SOURCE=2 -fstack-protector-strong --param=ssp-buffer-size=4 -Wformat -Werror=format-security") 57 set(WARN_LDFLAGS "") 58 # -Werror -Wbad-function-cast -Wmissing-prototypes 59 if(NOT BUILD_SANITIZE_ADDRESS) 60 # with asan we need to link all libraries we might need later 61 # so asan can initialize intercepts properly 62 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103930 63 set(WARN_LDFLAGS "${WARN_LDFLAGS} -Wl,--as-needed") 64 endif() 65 endif() 66 67 set(SANITIZE_FLAGS "") 68 69 if(BUILD_SANITIZE_ADDRESS) 70 set(SANITIZE_FLAGS "${SANITIZE_FLAGS} -fsanitize=address") 71 endif() 72 73 if(BUILD_SANITIZE_UNDEFINED) 74 set(SANITIZE_FLAGS "${SANITIZE_FLAGS} -fsanitize=undefined") 75 endif() 76 77 if(SANITIZE_FLAGS) 78 set(WARN_CFLAGS "${SANITIZE_FLAGS} -fno-omit-frame-pointer ${WARN_CFLAGS}") 79 endif() 80endif() 81 82option(BUILD_STATIC "build a static lighttpd with all modules added") 83 84if(BUILD_STATIC) 85 set(LIGHTTPD_STATIC 1) 86elseif(APPLE) 87 set(CMAKE_SHARED_MODULE_PREFIX "") 88else() 89 set(CMAKE_SHARED_LIBRARY_PREFIX "") 90endif() 91 92if(WITH_LIBUNWIND) 93 pkg_check_modules(LIBUNWIND REQUIRED libunwind) 94 set(HAVE_LIBUNWIND 1) 95endif() 96 97if(WITH_WEBDAV_PROPS) 98 set(WITH_XML 1) 99 set(WITH_SQLITE3 1) 100endif() 101 102if(WITH_WEBDAV_LOCKS) 103 set(WITH_UUID 1) 104endif() 105 106check_include_files(sys/inotify.h HAVE_SYS_INOTIFY_H) 107set(CMAKE_REQUIRED_FLAGS "-include sys/time.h") 108check_include_files(sys/loadavg.h HAVE_SYS_LOADAVG_H) 109set(CMAKE_REQUIRED_FLAGS) 110check_include_files(sys/poll.h HAVE_SYS_POLL_H) 111check_include_files(sys/prctl.h HAVE_SYS_PRCTL_H) 112check_include_files(sys/procctl.h HAVE_SYS_PROCCTL_H) 113check_include_files(sys/sendfile.h HAVE_SYS_SENDFILE_H) 114check_include_files(sys/un.h HAVE_SYS_UN_H) 115check_include_files(sys/wait.h HAVE_SYS_WAIT_H) 116check_include_files(sys/time.h HAVE_SYS_TIME_H) 117check_include_files(unistd.h HAVE_UNISTD_H) 118check_include_files(getopt.h HAVE_GETOPT_H) 119check_include_files(inttypes.h HAVE_INTTYPES_H) 120check_include_files(poll.h HAVE_POLL_H) 121check_include_files(pwd.h HAVE_PWD_H) 122check_include_files(stdint.h HAVE_STDINT_H) 123check_include_files(stdlib.h HAVE_STDLIB_H) 124check_include_files(strings.h HAVE_STRINGS_H) 125check_include_files(syslog.h HAVE_SYSLOG_H) 126 127# will be needed for auth 128check_include_files(crypt.h HAVE_CRYPT_H) 129# check if we need libcrypt for crypt_r() 130check_library_exists(crypt crypt_r "" HAVE_LIBCRYPT_CRYPT_R) 131if(HAVE_LIBCRYPT_CRYPT_R) 132 set(HAVE_CRYPT_R 1) 133 set(HAVE_LIBCRYPT 1) 134else() 135 check_library_exists(crypt crypt "" HAVE_LIBCRYPT_CRYPT) 136 if(HAVE_LIBCRYPT_CRYPT) 137 set(HAVE_CRYPT 1) 138 set(HAVE_LIBCRYPT 1) 139 endif() 140endif() 141check_function_exists(crypt_r HAVE_CRYPT_R) 142check_function_exists(crypt HAVE_CRYPT) 143 144set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h) 145check_type_size(socklen_t HAVE_SOCKLEN_T) 146set(CMAKE_EXTRA_INCLUDE_FILES) 147 148check_include_files(malloc.h HAVE_MALLOC_H) 149if(HAVE_MALLOC_H) 150check_function_exists(malloc_trim HAVE_MALLOC_TRIM) 151check_function_exists(mallopt HAVE_MALLOPT) 152endif() 153 154check_include_files(signal.h HAVE_SIGNAL_H) 155if(HAVE_SIGNAL_H) 156check_function_exists(sigaction HAVE_SIGACTION) 157check_function_exists(signal HAVE_SIGNAL) 158endif() 159 160check_include_files(sys/epoll.h HAVE_SYS_EPOLL_H) 161if(HAVE_SYS_EPOLL_H) 162check_function_exists(epoll_ctl HAVE_EPOLL_CTL) 163endif() 164 165set(CMAKE_REQUIRED_FLAGS "-include sys/types.h") 166check_include_files(sys/event.h HAVE_SYS_EVENT_H) 167set(CMAKE_REQUIRED_FLAGS) 168if(HAVE_SYS_EVENT_H) 169check_function_exists(kqueue HAVE_KQUEUE) 170endif() 171 172check_include_files(sys/mman.h HAVE_SYS_MMAN_H) 173if(HAVE_SYS_MMAN_H) 174check_function_exists(mmap HAVE_MMAP) 175endif() 176 177check_include_files(sys/random.h HAVE_SYS_RANDOM_H) 178if(HAVE_SYS_RANDOM_H) 179set(CMAKE_EXTRA_INCLUDE_FILES sys/random.h) 180check_function_exists(getentropy HAVE_GETENTROPY) 181set(CMAKE_EXTRA_INCLUDE_FILES) 182endif() 183 184check_include_files(linux/random.h HAVE_LINUX_RANDOM_H) 185if(HAVE_LINUX_RANDOM_H) 186set(CMAKE_EXTRA_INCLUDE_FILES linux/random.h) 187check_function_exists(getrandom HAVE_GETRANDOM) 188set(CMAKE_EXTRA_INCLUDE_FILES) 189endif() 190 191check_include_files(sys/resource.h HAVE_SYS_RESOURCE_H) 192if(HAVE_SYS_RESOURCE_H) 193check_function_exists(getrlimit HAVE_GETRLIMIT) 194endif() 195 196check_include_files(sys/uio.h HAVE_SYS_UIO_H) 197if(HAVE_SYS_UIO_H) 198check_function_exists(preadv HAVE_PREADV) 199check_function_exists(pwritev HAVE_PWRITEV) 200check_function_exists(writev HAVE_WRITEV) 201endif() 202 203check_function_exists(poll HAVE_POLL) 204if(NOT HAVE_POLL) 205check_include_files(sys/select.h HAVE_SYS_SELECT_H) 206check_function_exists(select HAVE_SELECT) 207endif() 208 209set(CMAKE_EXTRA_INCLUDE_FILES time.h) 210check_function_exists(timegm HAVE_TIMEGM) 211set(CMAKE_EXTRA_INCLUDE_FILES) 212 213if(CMAKE_SYSTEM_NAME MATCHES "SunOS") 214check_include_files(port.h HAVE_PORT_H) 215check_include_files(priv.h HAVE_PRIV_H) 216check_include_files(sys/devpoll.h HAVE_SYS_DEVPOLL_H) 217check_include_files(sys/filio.h HAVE_SYS_FILIO_H) 218check_function_exists(port_create HAVE_PORT_CREATE) 219check_function_exists(sendfilev HAVE_SENDFILEV) 220check_function_exists(setpflags HAVE_SETPFLAGS) 221endif() 222 223check_type_size(long SIZEOF_LONG) 224check_type_size(off_t SIZEOF_OFF_T) 225 226check_function_exists(arc4random_buf HAVE_ARC4RANDOM_BUF) 227check_function_exists(chroot HAVE_CHROOT) 228check_function_exists(copy_file_range HAVE_COPY_FILE_RANGE) 229check_function_exists(fork HAVE_FORK) 230check_function_exists(getloadavg HAVE_GETLOADAVG) 231check_function_exists(getuid HAVE_GETUID) 232check_function_exists(gmtime_r HAVE_GMTIME_R) 233check_function_exists(jrand48 HAVE_JRAND48) 234check_function_exists(localtime_r HAVE_LOCALTIME_R) 235check_function_exists(lstat HAVE_LSTAT) 236check_function_exists(madvise HAVE_MADVISE) 237check_function_exists(mempcpy HAVE_MEMPCPY) 238check_function_exists(mkostemp HAVE_MKOSTEMP) 239check_function_exists(pipe2 HAVE_PIPE2) 240check_function_exists(pread HAVE_PREAD) 241check_function_exists(pwrite HAVE_PWRITE) 242check_function_exists(sendfile HAVE_SENDFILE) 243check_function_exists(sendfile64 HAVE_SENDFILE64) 244check_function_exists(splice HAVE_SPLICE) 245check_function_exists(srandom HAVE_SRANDOM) 246check_function_exists(strerror_r HAVE_STRERROR_R) 247check_function_exists(issetugid HAVE_ISSETUGID) 248check_function_exists(memset_s HAVE_MEMSET_S) 249check_function_exists(explicit_bzero HAVE_EXPLICIT_BZERO) 250check_function_exists(explicit_memset HAVE_EXPLICIT_MEMSET) 251check_symbol_exists(clock_gettime "time.h" HAVE_CLOCK_GETTIME) 252if (NOT HAVE_CLOCK_GETTIME) 253 check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME) 254endif() 255check_library_exists(elftc elftc_copyfile "libelftc.h" HAVE_ELFTC_COPYFILE) 256if(CMAKE_SYSTEM_NAME MATCHES "SunOS") 257set(CMAKE_REQUIRED_LIBRARIES "socket;nsl") 258elseif(CMAKE_SYSTEM_NAME MATCHES "Haiku") 259set(CMAKE_REQUIRED_LIBRARIES "network") 260elseif(WIN32) 261set(CMAKE_REQUIRED_LIBRARIES "ws2_32") 262endif() 263check_function_exists(inet_aton HAVE_INET_ATON) 264check_function_exists(inet_pton HAVE_INET_PTON) 265check_c_source_compiles(" 266 #include <sys/types.h> 267 #include <sys/socket.h> 268 #include <netinet/in.h> 269 270 int main() { 271 struct sockaddr_in6 s; struct in6_addr t=in6addr_any; int i=AF_INET6; s; t.s6_addr[0] = 0; 272 return 0; 273 }" HAVE_IPV6) 274if(CMAKE_SYSTEM_NAME MATCHES "SunOS") 275set(CMAKE_REQUIRED_LIBRARIES) 276endif() 277check_c_source_compiles(" 278 __attribute__((weak)) void __dummy(void *x) { } 279 int main() { 280 void *x; 281 __dummy(x); 282 } 283 " HAVE_WEAK_SYMBOLS) 284check_c_source_compiles(" 285 #include <time.h> 286 int main(void) { 287 struct tm t; 288 t.tm_gmtoff = 0; 289 return 0; 290 } 291 " HAVE_STRUCT_TM_GMTOFF) 292 293## refactor me 294macro(XCONFIG _package _link_FLAGS _cflags) 295# reset the variables at the beginning 296 set(${_link_FLAGS}) 297 set(${_cflags}) 298 299 find_program(${_package}CONFIG_EXECUTABLE NAMES ${_package}) 300 301 # if pkg-config has been found 302 if(${_package}CONFIG_EXECUTABLE) 303 set(XCONFIG_EXECUTABLE "${${_package}CONFIG_EXECUTABLE}") 304 message(STATUS "found ${_package}: ${XCONFIG_EXECUTABLE}") 305 306 if(${_package} STREQUAL "pcre2-config") 307 exec_program(${XCONFIG_EXECUTABLE} ARGS --libs8 OUTPUT_VARIABLE __link_FLAGS) 308 else() 309 exec_program(${XCONFIG_EXECUTABLE} ARGS --libs OUTPUT_VARIABLE __link_FLAGS) 310 endif() 311 string(REPLACE "\n" "" ${_link_FLAGS} ${__link_FLAGS}) 312 exec_program(${XCONFIG_EXECUTABLE} ARGS --cflags OUTPUT_VARIABLE __cflags) 313 string(REPLACE "\n" "" ${_cflags} ${__cflags}) 314 else() 315 message(STATUS "found ${_package}: no") 316 endif() 317endmacro() 318 319if(WITH_XATTR) 320 check_include_files("sys/types.h;sys/xattr.h" HAVE_SYS_XATTR_H) 321 check_function_exists(getxattr HAVE_XATTR) 322 check_include_files("sys/types.h;sys/extattr.h" HAVE_SYS_EXTATTR_H) 323 check_function_exists(extattr_get_file HAVE_EXTATTR) 324 if(NOT HAVE_XATTR AND NOT HAVE_EXTATTR) 325 check_include_files("sys/types.h;attr/attributes.h" HAVE_ATTR_ATTRIBUTES_H) 326 if(HAVE_ATTR_ATTRIBUTES_H) 327 check_library_exists(attr attr_get "" HAVE_XATTR) 328 endif() 329 endif() 330else() 331 unset(HAVE_ATTR_ATTRIBUTES_H) 332 unset(HAVE_XATTR) 333endif() 334 335if(WITH_MYSQL) 336 xconfig(mysql_config MYSQL_LDFLAGS MYSQL_CFLAGS) 337 if(MYSQL_LDFLAGS) 338 set(HAVE_MYSQL TRUE) 339 endif() 340else() 341 unset(HAVE_MYSQL) 342endif() 343 344if(WITH_PGSQL) 345 if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.14) 346 find_package(PostgreSQL) 347 if(PostgreSQL_FOUND) 348 set(PGSQL_LIBRARY PostgreSQL::PostgreSQL) 349 set(HAVE_PGSQL TRUE) 350 endif() 351 else() 352 find_path(POSTGRESQL_INCLUDE_DIR 353 NAMES libpq-fe.h 354 PATH_SUFFIXES pgsql postgresql) 355 356 if(POSTGRESQL_INCLUDE_DIR) 357 check_library_exists(pq PQsetdbLogin "" HAVE_PGSQL) 358 if(HAVE_PGSQL) 359 set(PGSQL_LIBRARY pq) 360 endif() 361 include_directories(${POSTGRESQL_INCLUDE_DIR}) 362 else() 363 set(HAVE_PGSQL FALSE) 364 endif() 365 endif() 366else() 367 unset(HAVE_PGSQL) 368endif() 369 370if(WITH_DBI) 371 check_include_files(dbi/dbi.h HAVE_DBI_H) 372 if(HAVE_DBI_H) 373 check_library_exists(dbi dbi_conn_connect "" HAVE_DBI) 374 endif() 375else() 376 unset(HAVE_DBI_H) 377 unset(HAVE_DBI) 378endif() 379 380set(CRYPTO_LIBRARY "") 381 382if(WITH_OPENSSL) 383 find_package(OpenSSL) 384 if(OPENSSL_FOUND) 385 set(HAVE_OPENSSL_SSL_H 1) 386 set(HAVE_LIBSSL 1) 387 set(CRYPTO_LIBRARY OpenSSL::Crypto) 388 else() 389 unset(HAVE_OPENSSL_SSL_H) 390 unset(HAVE_LIBSSL) 391 endif() 392else() 393 unset(HAVE_OPENSSL_SSL_H) 394 unset(HAVE_LIBSSL) 395endif() 396 397if(WITH_WOLFSSL) 398 pkg_check_modules(WOLFSSL QUIET wolfssl) 399 400 if(WOLFSSL_FOUND) 401 set(WOLFSSL_INCLUDE_DIR ${WOLFSSL_INCLUDE_DIRS}) 402 if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12) 403 set(WOLFSSL_LIBRARY ${WOLFSSL_LINK_LIBRARIES}) 404 else() 405 set(WOLFSSL_LIBRARY ${WOLFSSL_LIBRARIES}) 406 endif() 407 else() 408 find_path(WOLFSSL_INCLUDE_DIR NAMES wolfssl/ssl.h PATHS ${WITH_WOLFSSL}) 409 find_library(WOLFSSL_LIBRARY 410 NAMES wolfssl 411 PATHS ${WITH_WOLFSSL} 412 ) 413 endif() 414 415 if(WOLFSSL_INCLUDE_DIR AND WOLFSSL_LIBRARY) 416 set(CMAKE_REQUIRED_INCLUDES ${WOLFSSL_INCLUDE_DIR}) 417 check_include_files(wolfssl/ssl.h HAVE_WOLFSSL_SSL_H) 418 419 check_c_source_compiles(" 420 #include <wolfssl/options.h> 421 #if !defined(HAVE_LIGHTY) && !defined(OPENSSL_EXTRA) 422 #error HAVE_LIGHTY macro not defined 423 #endif 424 int main() { return 0; } 425 " CHECK_HAVE_LIGHTY) 426 if (NOT CHECK_HAVE_LIGHTY) 427 message(FATAL_ERROR "wolfssl must be built with ./configure --enable-lighty") 428 endif() 429 unset(CHECK_HAVE_LIGHTY) 430 431 set(CMAKE_REQUIRED_LIBRARIES ${WOLFSSL_LIBRARY}) 432 check_library_exists(${WOLFSSL_LIBRARY} wolfSSL_Init "" HAVE_LIBWOLFSSL) 433 if(HAVE_LIBWOLFSSL) 434 set(CRYPTO_LIBRARY ${WOLFSSL_LIBRARY}) 435 set(HAVE_WOLFSSL 1) 436 endif() 437 set(CMAKE_REQUIRED_INCLUDES) 438 set(CMAKE_REQUIRED_LIBRARIES) 439 include_directories(${WOLFSSL_INCLUDE_DIR}) 440 endif() 441 unset(WOLFSSL_LIBRARY) 442 unset(WOLFSSL_INCLUDE_DIR) 443else() 444 unset(HAVE_WOLFSSL_SSL_H) 445endif() 446 447if(WITH_MBEDTLS) 448 check_include_files(mbedtls/ssl.h HAVE_MBEDTLS_SSL_H) 449 if(HAVE_MBEDTLS_SSL_H) 450 check_library_exists(mbedcrypto mbedtls_base64_encode "" HAVE_LIBMBEDCRYPTO) 451 if(HAVE_LIBMBEDCRYPTO) 452 set(CRYPTO_LIBRARY mbedcrypto) 453 check_library_exists(mbedtls mbedtls_ssl_init "" HAVE_LIBMBEDTLS) 454 if(HAVE_LIBMBEDTLS) 455 check_library_exists(mbedx509 mbedtls_x509_get_name "" HAVE_LIBMBEDX509) 456 endif() 457 endif() 458 endif() 459else() 460 unset(HAVE_MBEDTLS_SSL_H) 461 unset(HAVE_LIBMBEDCRYPTO) 462 unset(HAVE_LIBMBEDTLS) 463 unset(HAVE_LIBMEDX509) 464endif() 465 466if(WITH_NSS) 467 check_include_files(nss/nss.h HAVE_NSS_NSS_H) 468 check_include_files(nss3/nss.h HAVE_NSS3_NSS_H) 469 if(HAVE_NSS3_NSS_H OR HAVE_NSS_NSS_H) 470 check_library_exists(ssl3 NSSSSL_GetVersion "" HAVE_LIBSSL3) 471 if(HAVE_LIBSSL3) 472 check_library_exists(smime3 NSSSMIME_GetVersion "" HAVE_LIBSMIME3) 473 if(HAVE_LIBSMIME3) 474 check_library_exists(nss3 NSS_GetVersion "" HAVE_LIBNSS3) 475 if(HAVE_LIBNSS3) 476 check_library_exists(nssutil3 NSSUTIL_GetVersion "" HAVE_LIBNSSUTIL3) 477 endif() 478 endif() 479 endif() 480 endif() 481else() 482 unset(HAVE_NSS_NSS_H) 483 unset(HAVE_NSS3_NSS_H) 484 unset(HAVE_LIBSSL3) 485 unset(HAVE_LIBSMIME3) 486 unset(HAVE_LIBNSS3) 487 unset(HAVE_LIBNSSUTIL3) 488endif() 489 490if(WITH_NETTLE) 491 if(APPLE) 492 set(CMAKE_REQUIRED_INCLUDES /opt/local/include) 493 endif() 494 check_include_files(nettle/nettle-types.h HAVE_NETTLE_NETTLE_TYPES_H) 495 if(APPLE) 496 set(CMAKE_REQUIRED_INCLUDES) 497 endif() 498 if(HAVE_NETTLE_NETTLE_TYPES_H) 499 check_library_exists(nettle nettle_md5_init "" HAVE_LIBNETTLE) 500 if(HAVE_LIBNETTLE) 501 set(CRYPTO_LIBRARY nettle) 502 endif() 503 endif() 504else() 505 unset(HAVE_NETTLE_NETTLE_TYPES_H) 506endif() 507 508if(WITH_GNUTLS) 509 pkg_check_modules(GNUTLS REQUIRED gnutls) 510 set(HAVE_GNUTLS_CRYPTO_H 1) 511 set(HAVE_GNUTLS 1) 512 if(NOT WITH_OPENSSL AND NOT WITH_WOLFSSL AND NOT WITH_MBEDTLS AND NOT WITH_NETTLE) 513 set(CRYPTO_LIBRARY gnutls) 514 endif() 515endif() 516 517if(WITH_PCRE2) 518 pkg_check_modules(PCRE2 libpcre2-8) 519 if(PCRE2_FOUND) 520 set(PCRE_LDFLAGS "${PCRE2_LDFLAGS}") 521 set(PCRE_CFLAGS "${PCRE2_CFLAGS}") 522 else() 523 ## if we have pcre2-config, use it 524 xconfig(pcre2-config PCRE_LDFLAGS PCRE_CFLAGS) 525 endif() 526 if(PCRE_LDFLAGS OR PCRE_CFLAGS) 527 message(STATUS "found pcre2 at: LDFLAGS: ${PCRE_LDFLAGS} CFLAGS: ${PCRE_CFLAGS}") 528 529 if(NOT PCRE_CFLAGS STREQUAL "\n") 530 ## if it is empty we'll get newline returned 531 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PCRE_CFLAGS}") 532 endif() 533 534 set(HAVE_PCRE2_H 1) 535 set(HAVE_PCRE 1) 536 else() 537 if(NOT WIN32) 538 check_include_files(pcre2.h HAVE_PCRE_H) 539 check_library_exists(pcre2-8 pcre_match "" HAVE_PCRE) 540 set(PCRE_LDFLAGS -lpcre2-8) 541 else() 542 find_path(PCRE_INCLUDE_DIR pcre2.h) 543 544 set(PCRE_NAMES pcre2-8) 545 find_library(PCRE_LIBRARY 546 NAMES ${PCRE_NAMES} 547 ) 548 549 if(PCRE_INCLUDE_DIR AND PCRE_LIBRARY) 550 set(CMAKE_REQUIRED_INCLUDES ${PCRE_INCLUDE_DIR}) 551 set(CMAKE_REQUIRED_LIBRARIES ${PCRE_LIBRARY}) 552 check_include_files(pcre2.h HAVE_PCRE2_H) 553 check_library_exists(pcre2-8 pcre_match "" HAVE_PCRE) 554 set(CMAKE_REQUIRED_INCLUDES) 555 set(CMAKE_REQUIRED_LIBRARIES) 556 include_directories(${PCRE_INCLUDE_DIR}) 557 endif() 558 endif() 559 endif() 560 561 if(NOT HAVE_PCRE2_H) 562 message(FATAL_ERROR "pcre2.h couldn't be found") 563 endif() 564 if(NOT HAVE_PCRE) 565 message(FATAL_ERROR "libpcre2-8 couldn't be found") 566 endif() 567elseif(WITH_PCRE) 568 pkg_check_modules(PCRE libpcre) 569 if(NOT PCRE_FOUND) 570 ## if we have pcre-config, use it 571 xconfig(pcre-config PCRE_LDFLAGS PCRE_CFLAGS) 572 endif() 573 if(PCRE_LDFLAGS OR PCRE_CFLAGS) 574 message(STATUS "found pcre at: LDFLAGS: ${PCRE_LDFLAGS} CFLAGS: ${PCRE_CFLAGS}") 575 576 if(NOT PCRE_CFLAGS STREQUAL "\n") 577 ## if it is empty we'll get newline returned 578 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PCRE_CFLAGS}") 579 endif() 580 581 set(HAVE_PCRE_H 1) 582 set(HAVE_PCRE 1) 583 else() 584 if(NOT WIN32) 585 check_include_files(pcre.h HAVE_PCRE_H) 586 check_library_exists(pcre pcre_exec "" HAVE_PCRE) 587 set(PCRE_LDFLAGS -lpcre) 588 else() 589 find_path(PCRE_INCLUDE_DIR pcre.h) 590 591 set(PCRE_NAMES pcre) 592 find_library(PCRE_LIBRARY 593 NAMES ${PCRE_NAMES} 594 ) 595 596 if(PCRE_INCLUDE_DIR AND PCRE_LIBRARY) 597 set(CMAKE_REQUIRED_INCLUDES ${PCRE_INCLUDE_DIR}) 598 set(CMAKE_REQUIRED_LIBRARIES ${PCRE_LIBRARY}) 599 check_include_files(pcre.h HAVE_PCRE_H) 600 check_library_exists(pcre pcre_exec "" HAVE_PCRE) 601 set(CMAKE_REQUIRED_INCLUDES) 602 set(CMAKE_REQUIRED_LIBRARIES) 603 include_directories(${PCRE_INCLUDE_DIR}) 604 endif() 605 endif() 606 endif() 607 608 if(NOT HAVE_PCRE_H) 609 message(FATAL_ERROR "pcre.h couldn't be found") 610 endif() 611 if(NOT HAVE_PCRE) 612 message(FATAL_ERROR "libpcre couldn't be found") 613 endif() 614else() 615 unset(HAVE_PCRE_H) 616 unset(HAVE_PCRE) 617endif() 618 619if(WITH_SASL) 620 check_include_files(sasl/sasl.h HAVE_SASL_SASL_H) 621 if(HAVE_SASL_SASL_H) 622 check_library_exists(sasl2 sasl_server_init "" HAVE_SASL) 623 endif() 624else() 625 unset(HAVE_SASL_SASL_H) 626 unset(HAVE_SASL) 627endif() 628 629 630if(WITH_XML) 631 xconfig(xml2-config XML2_LDFLAGS XML2_CFLAGS) 632 if(XML2_LDFLAGS OR XML2_CFLAGS) 633 message(STATUS "found xml2 at: LDFLAGS: ${XML2_LDFLAGS} CFLAGS: ${XML2_CFLAGS}") 634 635 ## if it is empty we'll get newline returned 636 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${XML2_CFLAGS}") 637 638 check_include_files(libxml/tree.h HAVE_LIBXML_H) 639 640 set(CMAKE_REQUIRED_FLAGS ${XML2_LDFLAGS}) 641 check_library_exists(xml2 xmlParseChunk "" HAVE_LIBXML2) 642 set(CMAKE_REQUIRED_FLAGS) 643 else() 644 check_include_files(libxml.h HAVE_LIBXML_H) 645 check_library_exists(xml2 xmlParseChunk "" HAVE_LIBXML2) 646 endif() 647 648 if(NOT HAVE_LIBXML_H) 649 message(FATAL_ERROR "libxml/tree.h couldn't be found") 650 endif() 651 if(NOT HAVE_LIBXML2) 652 message(FATAL_ERROR "libxml2 couldn't be found") 653 endif() 654else() 655 unset(HAVE_LIBXML_H) 656 unset(HAVE_LIBXML2) 657endif() 658 659if(WITH_SQLITE3) 660 check_include_files(sqlite3.h HAVE_SQLITE3_H) 661 check_library_exists(sqlite3 sqlite3_reset "" HAVE_SQLITE3) 662else() 663 unset(HAVE_SQLITE3_H) 664 unset(HAVE_SQLITE3) 665endif() 666 667if(WITH_UUID) 668 check_include_files(uuid/uuid.h HAVE_UUID_UUID_H) 669 check_library_exists(uuid uuid_generate "" NEED_LIBUUID) 670 if(NOT NEED_LIBUUID) 671 check_function_exists(uuid_generate HAVE_LIBUUID) 672 else() 673 set(HAVE_LIBUUID 1) 674 endif() 675else() 676 unset(HAVE_UUID_UUID_H) 677 unset(NEED_LIBUUID) 678 unset(HAVE_LIBUUID) 679endif() 680 681if(WITH_XXHASH) 682 check_include_files(xxhash.h HAVE_XXHASH_H) 683 check_library_exists(xxhash XXH_versionNumber "" HAVE_XXHASH) 684else() 685 unset(HAVE_XXHASH_H) 686 unset(HAVE_XXHASH) 687endif() 688 689if(WITH_ZLIB) 690 find_package(ZLIB) 691 if(ZLIB_FOUND) 692 set(ZLIB_LIBRARY ZLIB::ZLIB) 693 set(HAVE_ZLIB_H TRUE) 694 set(HAVE_LIBZ TRUE) 695 endif() 696else() 697 unset(HAVE_ZLIB_H) 698 unset(HAVE_LIBZ) 699 unset(ZLIB_LIBRARY) 700endif() 701 702if(WITH_ZSTD) 703 check_include_files(zstd.h HAVE_ZSTD_H) 704 check_library_exists(zstd ZSTD_versionNumber "" HAVE_ZSTD) 705else() 706 unset(HAVE_ZSTD_H) 707 unset(HAVE_ZSTD) 708endif() 709 710if(WITH_BZIP) 711 find_package(BZip2) 712 if(BZIP2_FOUND) 713 if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12) 714 set(BZIP_LIBRARY BZip2::BZip2) 715 else() 716 set(BZIP_LIBRARY ${BZIP2_LIBRARIES}) 717 endif() 718 set(HAVE_BZLIB_H TRUE) 719 set(HAVE_LIBBZ2 TRUE) 720 endif() 721else() 722 unset(HAVE_BZLIB_H) 723 unset(HAVE_LIBBZ2) 724endif() 725 726if(WITH_BROTLI) 727 pkg_check_modules(LIBBROTLI REQUIRED libbrotlienc) 728 set(HAVE_BROTLI_ENCODE_H 1) 729 set(HAVE_BROTLI 1) 730else() 731 unset(HAVE_BROTLI) 732endif() 733 734if(WITH_LDAP) 735 check_include_files(ldap.h HAVE_LDAP_H) 736 check_library_exists(ldap ldap_bind "" HAVE_LIBLDAP) 737 check_include_files(lber.h HAVE_LBER_H) 738 check_library_exists(lber ber_printf "" HAVE_LIBLBER) 739else() 740 unset(HAVE_LDAP_H) 741 unset(HAVE_LIBLDAP) 742 unset(HAVE_LBER_H) 743 unset(HAVE_LIBLBER) 744endif() 745 746if(WITH_LIBDEFLATE) 747 check_include_files(libdeflate.h HAVE_LIBDEFLATE_H) 748 check_library_exists(deflate libdeflate_alloc_compressor "" HAVE_LIBDEFLATE) 749else() 750 unset(HAVE_LIBDEFLATE_H) 751 unset(HAVE_LIBDEFLATE) 752endif() 753 754if(WITH_PAM) 755 check_include_files(security/pam_appl.h HAVE_SECURITY_PAM_APPL_H) 756 check_library_exists(pam pam_start "" HAVE_PAM) 757else() 758 unset(HAVE_SECURITY_PAM_APPL_H) 759 unset(HAVE_PAM) 760endif() 761 762if(WITH_LUA) 763 if(WITH_LUA_VERSION) 764 pkg_search_module(LUA REQUIRED ${WITH_LUA_VERSION}) 765 else() 766 pkg_search_module(LUA REQUIRED lua5.4 lua-5.4 lua5.3 lua-5.3 lua5.2 lua-5.2 lua5.1 lua-5.1 lua) 767 endif() 768 message(STATUS "found lua at: INCDIR: ${LUA_INCLUDE_DIRS} LIBDIR: ${LUA_LIBRARY_DIRS} LDFLAGS: ${LUA_LDFLAGS} CFLAGS: ${LUA_CFLAGS}") 769 set(HAVE_LUA_H 1 "Have liblua header") 770else() 771 unset(HAVE_LUA_H) 772endif() 773 774if(WITH_FAM AND NOT HAVE_SYS_INOTIFY_H AND NOT HAVE_KQUEUE) 775 check_include_files(fam.h HAVE_FAM_H) 776 check_library_exists(fam FAMOpen2 "" HAVE_LIBFAM) 777 if(HAVE_LIBFAM) 778 set(CMAKE_REQUIRED_LIBRARIES fam) 779 check_function_exists(FAMNoExists HAVE_FAMNOEXISTS) 780 set(CMAKE_REQUIRED_LIBRARIES) 781 endif() 782else() 783 unset(HAVE_FAM_H) 784 unset(HAVE_LIBFAM) 785 unset(HAVE_FAMNOEXISTS) 786endif() 787 788if(WITH_MAXMINDDB) 789 check_library_exists(maxminddb MMDB_open "" HAVE_MAXMINDDB) 790endif() 791 792if(NOT BUILD_STATIC) 793 check_include_files(dlfcn.h HAVE_DLFCN_H) 794else() 795 unset(HAVE_DLFCN_H) 796endif() 797 798if(HAVE_DLFCN_H) 799 check_library_exists(dl dlopen "" HAVE_LIBDL) 800else() 801 unset(HAVE_LIBDL) 802endif() 803 804set(LIGHTTPD_VERSION_ID 0x104${PROJECT_VERSION_PATCH}) 805set(PACKAGE_NAME "${CMAKE_PROJECT_NAME}") 806set(PACKAGE_VERSION "${PROJECT_VERSION}") 807 808if(NOT WIN32) 809 if(NOT LIGHTTPD_MODULES_DIR) 810 set(LIGHTTPD_MODULES_DIR "${CMAKE_INSTALL_LIBDIR}/lighttpd") 811 endif() 812 set(LIGHTTPD_LIBRARY_DIR "${CMAKE_INSTALL_PREFIX}/${LIGHTTPD_MODULES_DIR}") 813else() 814 ## We use relative path in windows 815 set(LIGHTTPD_LIBRARY_DIR "lib") 816endif() 817 818## Write out config.h 819configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h) 820 821add_definitions(-DHAVE_CONFIG_H) 822 823include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) 824 825set(COMMON_SRC 826 base64.c buffer.c burl.c log.c 827 http_header.c http_kv.c keyvalue.c chunk.c 828 http_chunk.c fdevent.c fdevent_fdnode.c gw_backend.c 829 stat_cache.c http_etag.c array.c 830 algo_md5.c algo_sha1.c algo_splaytree.c 831 configfile-glue.c 832 http-header-glue.c 833 http_cgi.c 834 http_date.c 835 request.c 836 sock_addr.c 837 rand.c 838 fdlog_maint.c 839 fdlog.c 840 sys-setjmp.c 841 ck.c 842) 843 844 set(BUILTIN_MODS 845 mod_rewrite.c 846 mod_redirect.c 847 mod_access.c 848 mod_alias.c 849 mod_indexfile.c 850 mod_staticfile.c 851 mod_setenv.c 852 mod_expire.c 853 mod_simple_vhost.c 854 mod_evhost.c 855 mod_fastcgi.c 856 mod_scgi.c 857 ) 858 859if(CMAKE_CROSSCOMPILING) 860 # custom compile lemon using native compiler 861 add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lemon 862 COMMAND cc 863 ARGS ${CMAKE_CURRENT_SOURCE_DIR}/lemon.c -o ${CMAKE_CURRENT_BINARY_DIR}/lemon 864 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/lemon.c 865 COMMENT "Generating lemon from lemon.c using native compiler" 866 ) 867else() 868 add_executable(lemon lemon.c) 869endif() 870 871## Build parsers by using lemon... 872lemon_parser(configparser.y) 873 874set(L_INSTALL_TARGETS) 875 876add_executable(lighttpd-angel lighttpd-angel.c) 877set(L_INSTALL_TARGETS ${L_INSTALL_TARGETS} lighttpd-angel) 878add_target_properties(lighttpd-angel COMPILE_FLAGS "-DSBIN_DIR=\\\\\"${CMAKE_INSTALL_FULL_SBINDIR}\\\\\"") 879 880set(SERVER_SRC 881 server.c 882 response.c 883 connections.c 884 h2.c 885 reqpool.c 886 plugin.c 887 sock_addr_cache.c 888 ls-hpack/lshpack.c 889 algo_xxhash.c 890 fdevent_impl.c 891 http_range.c 892 network.c 893 network_write.c 894 data_config.c 895 configfile.c 896 configparser.c 897) 898 899add_executable(lighttpd ${SERVER_SRC} ${COMMON_SRC} ${BUILTIN_MODS}) 900set(L_INSTALL_TARGETS ${L_INSTALL_TARGETS} lighttpd) 901 902add_and_install_library(mod_accesslog mod_accesslog.c) 903add_and_install_library(mod_ajp13 mod_ajp13.c) 904add_and_install_library(mod_auth "mod_auth.c;mod_auth_api.c") 905add_and_install_library(mod_authn_file "mod_authn_file.c") 906if(NOT WIN32) 907 add_and_install_library(mod_cgi mod_cgi.c) 908endif() 909add_and_install_library(mod_deflate mod_deflate.c) 910add_and_install_library(mod_dirlisting mod_dirlisting.c) 911add_and_install_library(mod_extforward mod_extforward.c) 912add_and_install_library(mod_proxy mod_proxy.c) 913add_and_install_library(mod_rrdtool mod_rrdtool.c) 914add_and_install_library(mod_sockproxy mod_sockproxy.c) 915add_and_install_library(mod_ssi mod_ssi.c) 916add_and_install_library(mod_status mod_status.c) 917add_and_install_library(mod_userdir mod_userdir.c) 918add_and_install_library(mod_vhostdb "mod_vhostdb.c;mod_vhostdb_api.c") 919add_and_install_library(mod_webdav mod_webdav.c) 920add_and_install_library(mod_wstunnel mod_wstunnel.c) 921 922add_executable(test_configfile 923 t/test_configfile.c 924 buffer.c 925 array.c 926 data_config.c 927 http_header.c 928 http_kv.c 929 log.c 930 fdlog.c 931 sock_addr.c 932 ck.c 933) 934add_test(NAME test_configfile COMMAND test_configfile) 935 936add_executable(test_mod 937 ${COMMON_SRC} 938 t/test_mod.c 939 t/test_mod_access.c 940 t/test_mod_alias.c 941 t/test_mod_evhost.c 942 t/test_mod_indexfile.c 943 t/test_mod_simple_vhost.c 944 t/test_mod_ssi.c 945 t/test_mod_staticfile.c 946 t/test_mod_userdir.c 947) 948add_test(NAME test_mod COMMAND test_mod) 949 950add_executable(test_common 951 t/test_common.c 952 t/test_array.c 953 t/test_base64.c 954 t/test_buffer.c 955 t/test_burl.c 956 t/test_http_header.c 957 t/test_http_kv.c 958 t/test_keyvalue.c 959 t/test_request.c 960 log.c 961 fdlog.c 962 sock_addr.c 963 ck.c 964) 965add_test(NAME test_common COMMAND test_common) 966 967if(HAVE_PCRE) 968 target_link_libraries(lighttpd ${PCRE_LDFLAGS}) 969 add_target_properties(lighttpd COMPILE_FLAGS ${PCRE_CFLAGS}) 970 target_link_libraries(test_common ${PCRE_LDFLAGS}) 971 add_target_properties(test_common COMPILE_FLAGS ${PCRE_CFLAGS}) 972 target_link_libraries(test_configfile ${PCRE_LDFLAGS}) 973 add_target_properties(test_configfile COMPILE_FLAGS ${PCRE_CFLAGS}) 974 target_link_libraries(test_mod ${PCRE_LDFLAGS}) 975 add_target_properties(test_mod COMPILE_FLAGS ${PCRE_CFLAGS}) 976endif() 977 978if(WITH_LUA) 979 add_and_install_library(mod_magnet "mod_magnet.c;mod_magnet_cache.c;algo_hmac.c") 980 target_link_libraries(mod_magnet ${LUA_LDFLAGS} ${CRYPTO_LIBRARY}) 981 add_target_properties(mod_magnet COMPILE_FLAGS ${LUA_CFLAGS}) 982endif() 983 984if(WITH_MAXMINDDB) 985 add_and_install_library(mod_maxminddb mod_maxminddb.c) 986 target_link_libraries(mod_maxminddb maxminddb) 987endif() 988 989if(HAVE_MYSQL) 990 add_and_install_library(mod_vhostdb_mysql "mod_vhostdb_mysql.c") 991 target_link_libraries(mod_vhostdb_mysql ${MYSQL_LDFLAGS}) 992 add_target_properties(mod_vhostdb_mysql COMPILE_FLAGS ${MYSQL_CFLAGS}) 993endif() 994 995if(HAVE_PGSQL) 996 add_and_install_library(mod_vhostdb_pgsql "mod_vhostdb_pgsql.c") 997 target_link_libraries(mod_vhostdb_pgsql ${PGSQL_LIBRARY}) 998endif() 999 1000if(HAVE_DBI_H AND HAVE_DBI) 1001 add_and_install_library(mod_vhostdb_dbi "mod_vhostdb_dbi.c") 1002 target_link_libraries(mod_vhostdb_dbi dbi) 1003 1004 add_and_install_library(mod_authn_dbi "mod_authn_dbi.c") 1005 set(L_MOD_AUTHN_DBI ${CRYPTO_LIBRARY}) 1006 if(HAVE_LIBCRYPT) 1007 set(L_MOD_AUTHN_DBI ${L_MOD_AUTHN_DBI} crypt) 1008 endif() 1009 target_link_libraries(mod_authn_dbi ${L_MOD_AUTHN_DBI} dbi) 1010endif() 1011 1012set(L_MOD_WEBDAV) 1013if(HAVE_SQLITE3_H) 1014 set(L_MOD_WEBDAV ${L_MOD_WEBDAV} sqlite3) 1015endif() 1016if(HAVE_LIBXML_H) 1017 target_link_libraries(mod_webdav ${XML2_LDFLAGS}) 1018endif() 1019if(HAVE_UUID_UUID_H) 1020 if(NEED_LIBUUID) 1021 set(L_MOD_WEBDAV ${L_MOD_WEBDAV} uuid) 1022 endif() 1023endif() 1024 1025target_link_libraries(mod_webdav ${L_MOD_WEBDAV}) 1026 1027set(L_MOD_AUTHN_FILE) 1028if(HAVE_LIBCRYPT) 1029 set(L_MOD_AUTHN_FILE ${L_MOD_AUTHN_FILE} crypt) 1030endif() 1031target_link_libraries(mod_authn_file ${L_MOD_AUTHN_FILE}) 1032 1033if(BUILD_SANITIZE_ADDRESS AND HAVE_LIBCRYPT) 1034 # libasan initializes intercepts early (before lighty loads plugins); 1035 # if libcrypt isn't loaded at that time calling crypt later ends up 1036 # calling a nullptr. 1037 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103930 1038 target_link_libraries(lighttpd crypt) 1039endif() 1040 1041if(WITH_KRB5) 1042 check_library_exists(krb5 krb5_init_context "" HAVE_KRB5) 1043 add_and_install_library(mod_authn_gssapi "mod_authn_gssapi.c") 1044 set(L_MOD_AUTHN_GSSAPI ${L_MOD_AUTHN_GSSAPI} krb5 gssapi_krb5) 1045 target_link_libraries(mod_authn_gssapi ${L_MOD_AUTHN_GSSAPI}) 1046endif() 1047 1048if(WITH_LDAP) 1049 set(L_MOD_AUTHN_LDAP ${L_MOD_AUTHN_LDAP} ldap lber) 1050 add_and_install_library(mod_authn_ldap "mod_authn_ldap.c") 1051 target_link_libraries(mod_authn_ldap ${L_MOD_AUTHN_LDAP}) 1052 add_and_install_library(mod_vhostdb_ldap "mod_vhostdb_ldap.c") 1053 target_link_libraries(mod_vhostdb_ldap ${L_MOD_AUTHN_LDAP}) 1054endif() 1055 1056if(WITH_PAM) 1057 add_and_install_library(mod_authn_pam "mod_authn_pam.c") 1058 set(L_MOD_AUTHN_PAM ${L_MOD_AUTHN_PAM} pam) 1059 target_link_libraries(mod_authn_pam ${L_MOD_AUTHN_PAM}) 1060endif() 1061 1062if(WITH_SASL) 1063 add_and_install_library(mod_authn_sasl "mod_authn_sasl.c") 1064 set(L_MOD_AUTHN_SASL ${L_MOD_AUTHN_SASL} sasl2) 1065 target_link_libraries(mod_authn_sasl ${L_MOD_AUTHN_SASL}) 1066endif() 1067 1068if(HAVE_ZLIB_H OR HAVE_ZSTD_H OR HAVE_BZLIB_H OR HAVE_BROTLI OR HAVE_LIBDEFLATE) 1069 if(HAVE_ZLIB_H) 1070 set(L_MOD_DEFLATE ${L_MOD_DEFLATE} ${ZLIB_LIBRARY}) 1071 endif() 1072 if(HAVE_ZSTD_H) 1073 set(L_MOD_DEFLATE ${L_MOD_DEFLATE} zstd) 1074 endif() 1075 if(HAVE_BZLIB_H) 1076 set(L_MOD_DEFLATE ${L_MOD_DEFLATE} ${BZIP_LIBRARY}) 1077 endif() 1078 if(HAVE_BROTLI) 1079 set(L_MOD_DEFLATE ${L_MOD_DEFLATE} brotlienc) 1080 endif() 1081 if(HAVE_LIBDEFLATE) 1082 set(L_MOD_DEFLATE ${L_MOD_DEFLATE} deflate) 1083 endif() 1084 target_link_libraries(mod_deflate ${L_MOD_DEFLATE}) 1085endif() 1086 1087if(HAVE_LIBFAM) 1088 target_link_libraries(lighttpd fam) 1089 target_link_libraries(test_mod fam) 1090endif() 1091 1092if(HAVE_XATTR) 1093 target_link_libraries(lighttpd attr) 1094 target_link_libraries(test_mod attr) 1095endif() 1096 1097if(HAVE_XXHASH) 1098 target_link_libraries(lighttpd xxhash) 1099 target_link_libraries(test_mod xxhash) 1100endif() 1101 1102if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang") 1103 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pipe -Wall -g -Wshadow -W -pedantic ${WARN_CFLAGS}") 1104 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2") 1105 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0") 1106 set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_WITHDEBINFO} -O2") 1107 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${WARN_LDFLAGS}") 1108 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${WARN_LDFLAGS}") 1109 if((NOT APPLE) AND (NOT CMAKE_SYSTEM_NAME MATCHES "SunOS")) 1110 add_target_properties(lighttpd LINK_FLAGS "-Wl,-export-dynamic") 1111 endif() 1112endif() 1113 1114set_target_properties(lighttpd PROPERTIES CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}) 1115 1116if(WIN32) 1117 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNVALGRIND") 1118 add_target_properties(lighttpd COMPILE_FLAGS "-DLI_DECLARE_EXPORTS") 1119 target_link_libraries(mod_proxy ws2_32) 1120 target_link_libraries(mod_ssi ws2_32) 1121 1122 if(MINGW) 1123 target_link_libraries(lighttpd msvcr70) 1124 add_target_properties(lighttpd LINK_FLAGS "-Wl,-subsystem,console") 1125 endif() 1126endif() 1127 1128if(NOT BUILD_STATIC) 1129 if(HAVE_LIBDL) 1130 target_link_libraries(lighttpd dl) 1131 target_link_libraries(test_mod dl) 1132 endif() 1133endif() 1134 1135if(NOT ${CRYPTO_LIBRARY} EQUAL "") 1136 target_link_libraries(lighttpd ${CRYPTO_LIBRARY}) 1137 target_link_libraries(mod_auth ${CRYPTO_LIBRARY}) 1138 set(L_MOD_AUTHN_FILE ${L_MOD_AUTHN_FILE} ${CRYPTO_LIBRARY}) 1139 target_link_libraries(mod_authn_file ${L_MOD_AUTHN_FILE}) 1140 target_link_libraries(mod_wstunnel ${CRYPTO_LIBRARY}) 1141 target_link_libraries(test_mod ${CRYPTO_LIBRARY}) 1142endif() 1143 1144if(OPENSSL_FOUND) 1145 add_and_install_library(mod_openssl "mod_openssl.c") 1146 set(L_MOD_OPENSSL ${L_MOD_OPENSSL} ssl crypto) 1147 target_link_libraries(mod_openssl ${L_MOD_OPENSSL}) 1148endif() 1149 1150if(HAVE_WOLFSSL) 1151 add_and_install_library(mod_wolfssl "mod_wolfssl.c") 1152 target_link_libraries(mod_wolfssl wolfssl) 1153endif() 1154 1155if(HAVE_GNUTLS) 1156 add_and_install_library(mod_gnutls "mod_gnutls.c") 1157 target_link_libraries(mod_gnutls gnutls) 1158endif() 1159 1160if(HAVE_LIBMBEDTLS AND HAVE_LIBMEDCRYPTO AND HAVE_LIBMEDX509) 1161 add_and_install_library(mod_mbedtls "mod_mbedtls.c") 1162 set(L_MOD_MBEDTLS ${L_MOD_MBEDTLS} mbedtls mbedcrypto mbedx509) 1163 target_link_libraries(mod_mbedtls ${L_MOD_MBEDTLS}) 1164endif() 1165 1166if(HAVE_LIBSSL3 AND HAVE_LIBSMIME3 AND HAVE_LIBNSS3 AND HAVE_LIBNSSUTIL3) 1167 add_and_install_library(mod_nss "mod_nss.c") 1168 set(L_MOD_NSS ${L_MOD_NSS} ssl3 smime3 nss3 nssutil3) 1169 target_link_libraries(mod_nss ${L_MOD_NSS}) 1170endif() 1171 1172if(WITH_LIBUNWIND) 1173 target_link_libraries(lighttpd ${LIBUNWIND_LDFLAGS}) 1174 add_target_properties(lighttpd COMPILE_FLAGS ${LIBUNWIND_CFLAGS}) 1175 1176 target_link_libraries(test_common ${LIBUNWIND_LDFLAGS}) 1177 add_target_properties(test_common COMPILE_FLAGS ${LIBUNWIND_CFLAGS}) 1178 target_link_libraries(test_configfile ${PCRE_LDFLAGS} ${LIBUNWIND_LDFLAGS}) 1179 add_target_properties(test_configfile COMPILE_FLAGS ${PCRE_CFLAGS} ${LIBUNWIND_CFLAGS}) 1180 target_link_libraries(test_mod ${LIBUNWIND_LDFLAGS}) 1181 add_target_properties(test_mod COMPILE_FLAGS ${LIBUNWIND_CFLAGS}) 1182endif() 1183 1184if(WIN32) 1185 set(SOCKLIBS ws2_32) 1186endif() 1187if(CMAKE_SYSTEM_NAME MATCHES "SunOS") 1188 set(SOCKLIBS socket nsl) 1189elseif(CMAKE_SYSTEM_NAME MATCHES "Haiku") 1190 set(SOCKLIBS network) 1191endif() 1192if(SOCKLIBS) 1193 target_link_libraries(lighttpd ${SOCKLIBS}) 1194 target_link_libraries(test_common ${SOCKLIBS}) 1195 target_link_libraries(test_configfile ${SOCKLIBS}) 1196 target_link_libraries(test_mod ${SOCKLIBS}) 1197endif() 1198 1199if(NOT WIN32) 1200install(TARGETS ${L_INSTALL_TARGETS} 1201 RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR} 1202 LIBRARY DESTINATION ${LIGHTTPD_LIBRARY_DIR} 1203 ARCHIVE DESTINATION ${LIGHTTPD_LIBRARY_DIR}/static) 1204else() 1205## HACK to make win32 to install our libraries in desired directory.. 1206install(TARGETS lighttpd 1207 RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR} 1208 ARCHIVE DESTINATION lib/static) 1209list(REMOVE_ITEM L_INSTALL_TARGETS lighttpd) 1210install(TARGETS ${L_INSTALL_TARGETS} 1211 RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR}/lib 1212 LIBRARY DESTINATION lib 1213 ARCHIVE DESTINATION lib/static) 1214endif() 1215