summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
blob: ccc7d6d1b9558b5e142acd19b1113b59b0a35de0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# tunable variables - regenerate pound.h for it to take effect
set (VERSION "3.0.2")
set (MAXBUF 8192)
set (MAXHEADERS 128)
set (RESURRECT_CYCLE 60)
set (RESURRECT_TO 15)
set (HASH_FUNCTION HASH_FNV)
set (LOG_FACILITY LOG_DAEMON)
set (H2TABSIZE 4096)
set (H2FRAMESIZE 16384)

# from here on there should be nothing to change
cmake_minimum_required(VERSION 3.0)
project(Pound C)

if (CMAKE_C_COMPILER_ID STREQUAL "Clang" OR CMAKE_C_COMPILER_ID STREQUAL "GCC" OR CMAKE_C_COMPILER_ID STREQUAL "GNU")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-result -Wno-cast-qual -Wno-discarded-qualifiers -D_GNU_SOURCE -O2")
endif()

include_directories(include)

file(GLOB SOURCES "src/*.c")

add_executable(pound ${SOURCES})

set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)

include(CheckIncludeFiles)
CHECK_INCLUDE_FILES("stdio.h;pthread.h;yaml.h;nanomsg/nn.h;nanomsg/inproc.h;nanomsg/pipeline.h;nanomsg/pair.h;nanomsg/reqrep.h;stdlib.h;unistd.h;fcntl.h;ctype.h;getopt.h;string.h;syslog.h;sys/types.h;sys/socket.h;netdb.h;sys/stat.h;time.h;poll.h;semaphore.h;pwd.h;grp.h;signal.h;setjmp.h;mbedtls/config.h;mbedtls/certs.h;mbedtls/oid.h;mbedtls/asn1.h;mbedtls/x509.h;mbedtls/entropy.h;mbedtls/ctr_drbg.h;mbedtls/ssl.h;mbedtls/error.h" HAVE_MANDATORY_INCLUDES LANGUAGE C)
if(NOT HAVE_MANDATORY_INCLUDES)
message(FATAL_ERROR "Missing mandatory header files!")
endif()

CHECK_INCLUDE_FILES(pcre2posix.h HAVE_PCRE2POSIX_H)
CHECK_INCLUDE_FILES(pcre/pcre2posix.h HAVE_PCRE_PCRE2POSIX_H)
CHECK_INCLUDE_FILES(pcreposix.h HAVE_PCREPOSIX_H)
CHECK_INCLUDE_FILES(pcre/pcreposix.h HAVE_PCRE_PCREPOSIX_H)
CHECK_INCLUDE_FILES(regex.h HAVE_REGEX_H)
CHECK_INCLUDE_FILES(stdarg.h HAVE_STDARG_H)

CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/include/pound.h.in ${CMAKE_CURRENT_SOURCE_DIR}/include/pound.h)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/MKDIST.in ${CMAKE_CURRENT_SOURCE_DIR}/MKDIST)

target_link_libraries(pound -lyaml)
target_link_libraries(pound -lnanomsg)
target_link_libraries(pound -lpthread)
target_link_libraries(pound Threads::Threads)

FIND_LIBRARY(TCMALLOC tcmalloc )
if(TCMALLOC)
target_link_libraries(pound -ltcmalloc)
endif()

FIND_LIBRARY(MBEDCRYPTO mbedcrypto)
if(MBEDCRYPTO)
target_link_libraries(pound -lmbedcrypto)
endif()

FIND_LIBRARY(MBEDX509 mbedx509)
if(MBEDX509)
target_link_libraries(pound -lmbedx509)
endif()

FIND_LIBRARY(MBEDTLS mbedtls)
if(MBEDTLS)
target_link_libraries(pound -lmbedtls)
endif()

if(NOT MBEDCRYPTO OR NOT MBEDX509 OR NOT MBEDTLS)
message(FATAL_ERROR "Missing mandatory library MbedTLS!")
endif()

if(HAVE_PCRE2POSIX_H OR HAVE_PCRE_PCRE2POSIX_H)
FIND_LIBRARY(PCRE pcre2-posix)
if(PCRE)
target_link_libraries(pound -lpcre2-posix -lpcre2-8)
else()
message(FATAL_ERROR "pcre2posix.h found but libpcre2-posix is not available!")
endif()
else()
if(HAVE_PCREPOSIX_H OR HAVE_PCRE_PCREPOSIX_H)
FIND_LIBRARY(PCRE pcreposix)
if(PCRE)
target_link_libraries(pound -lpcreposix)
else()
message(FATAL_ERROR "pcreposix.h found but libpcreposix is not available!")
endif()
endif()
endif()