forked from Edgio/is2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
220 lines (220 loc) · 10.4 KB
/
CMakeLists.txt
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# ------------------------------------------------------------------------------
# Project setup
# ------------------------------------------------------------------------------
project(is2)
cmake_minimum_required(VERSION 3.10)
# ------------------------------------------------------------------------------
# Build options
# ------------------------------------------------------------------------------
option(GCC_OPTIONS "Command line options passed to gcc or 'native' to compile for this hardware" OFF)
option(FORTIFY "Fortify Source GCC options" OFF)
option(DEBUG_MODE "Compile in debug mode." OFF)
option(BUILD_SYMBOLS "Build with Symbols" OFF)
option(BUILD_TCMALLOC "Build with tcmalloc" OFF)
option(BUILD_PROFILER "Enable google cpu and heap profiler support" OFF)
option(BUILD_ASAN "Build with Address Sanitizer" OFF)
option(BUILD_UBSAN "Build with Undefined Behavior Sanitizer" OFF)
option(BUILD_UDNS "Build with udns (async dns support)" ON)
option(BUILD_CUSTOM_OPENSSL "Build with custom OpenSSL" OFF)
option(BUILD_H2 "Build with h2 support (w/ nghttp2)" OFF)
option(BUILD_TLS "Build with tls support (w/ openssl)" OFF)
option(BUILD_TESTS "Build the unit tests." ON)
option(BUILD_EXAMPLES "Build the examples." ON)
# ------------------------------------------------------------------------------
# Display the current settings
# ------------------------------------------------------------------------------
message(STATUS "Build Configuration:")
message("")
message(" Build Option Variable Value ")
message(" -----------------------------------------------------------------------------------------")
message(" Install path: " "INSTALL_PREFIX " ${CMAKE_INSTALL_PREFIX})
message(" Fortify Source: " "FORTIFY " ${FORTIFY})
message(" Debug mode: " "DEBUG_MODE " ${DEBUG_MODE})
message(" Build Symbols " "BUILD_SYMBOLS " ${BUILD_SYMBOLS})
message(" Build with tcmalloc: " "BUILD_TCMALLOC " ${BUILD_TCMALLOC})
message(" Enable google cpu/heap profiler support: " "BUILD_PROFILER " ${BUILD_PROFILER})
message(" Build with Address Sanitizer: " "BUILD_ASAN " ${BUILD_ASAN})
message(" Build with Undefined Behavior Sanitizer: " "BUILD_UBSAN " ${BUILD_UBSAN})
message(" Build with udns support: " "BUILD_UDNS " ${BUILD_UDNS})
message(" Build for custom OpenSSL: " "BUILD_CUSTOM_OPENSSL " ${BUILD_CUSTOM_OPENSSL})
message(" Build unit tests: " "BUILD_TESTS " ${BUILD_TESTS})
message(" Build examples: " "BUILD_EXAMPLES " ${BUILD_EXAMPLES})
message(" Build with h2 support (w/ nghttp2): " "BUILD_H2 " ${BUILD_H2})
message(" Build with tls support (w/ openssl): " "BUILD_TLS " ${BUILD_TLS})
message("")
# ------------------------------------------------------------------------------
# build h2
# ------------------------------------------------------------------------------
if(BUILD_H2)
add_definitions(-DBUILD_H2_WITH_NGHTTP2=1)
endif()
# ------------------------------------------------------------------------------
# build tls
# ------------------------------------------------------------------------------
if(BUILD_TLS)
add_definitions(-DBUILD_TLS_WITH_OPENSSL=1)
endif()
# ------------------------------------------------------------------------------
# fortify options
# ------------------------------------------------------------------------------
if (FORTIFY)
add_definitions(-D_FORTIFY_SOURCE=2 -O1 -fstack-protector-all -Wl,-z,relro,-z,now)
endif()
# ------------------------------------------------------------------------------
# fail if not found
# ------------------------------------------------------------------------------
macro(fail_if_not_found_library a_lib)
find_library(${a_lib}_LIBRARY
NAME ${a_lib}
PATH_SUFFIXES ${CMAKE_LIBRARY_ARCHITECTURE})
if(NOT ${a_lib}_LIBRARY)
message(FATAL_ERROR "${a_lib} library not found")
endif()
endmacro(fail_if_not_found_library)
# ------------------------------------------------------------------------------
# ASAN
# ------------------------------------------------------------------------------
if(BUILD_ASAN)
set(DEBUG_LIBRARIES asan ${DEBUG_LIBRARIES})
add_definitions(-g3 -fno-omit-frame-pointer -fsanitize=address)
set(DEBUG_MODE ON)
set(BUILD_PROFILER OFF)
set(BUILD_TCMALLOC OFF)
# ------------------------------------------------------------------------------
# UBSAN
# ------------------------------------------------------------------------------
elseif(BUILD_UBSAN)
set(DEBUG_LIBRARIES asan ${DEBUG_LIBRARIES})
add_definitions(-g3 -fno-omit-frame-pointer -fsanitize=undefined -fno-sanitize-recover)
set(DEBUG_MODE ON)
set(BUILD_PROFILER OFF)
set(BUILD_TCMALLOC OFF)
endif()
# ------------------------------------------------------------------------------
# Optional flags
# ------------------------------------------------------------------------------
if (DEBUG_MODE)
add_definitions(-O0 -g3)
else()
add_definitions(-O2)
endif()
if (BUILD_SYMBOLS)
add_definitions(-g3)
endif()
# ------------------------------------------------------------------------------
# Build UDNS
# ------------------------------------------------------------------------------
if(BUILD_UDNS)
include(ExternalProject)
ExternalProject_Add(ext_udns
# Optional approach -including from external url
#URL http://www.corpit.ru/mjt/udns/udns-0.4.tar.gz
DOWNLOAD_COMMAND ""
SOURCE_DIR ${CMAKE_SOURCE_DIR}/ext/udns-0.4
BINARY_DIR ${CMAKE_SOURCE_DIR}/ext/udns-0.4
CONFIGURE_COMMAND "./configure"
#BUILD_COMMAND $(MAKE) COMMAND $(MAKE)
INSTALL_COMMAND ""
)
add_definitions(-DASYNC_DNS_WITH_UDNS=1)
endif()
# ------------------------------------------------------------------------------
# Build PROFILER
# ------------------------------------------------------------------------------
if (BUILD_PROFILER)
if (BUILD_LINUX)
fail_if_not_found_library(libprofiler.a)
set(LIBRARIES ${LIBRARIES} ${libprofiler.a_LIBRARY})
else()
fail_if_not_found_library(profiler)
set(LIBRARIES ${LIBRARIES} profiler)
endif()
add_definitions(-DENABLE_PROFILER=1)
# profiler requires tcmalloc
set(BUILD_TCMALLOC ON)
endif()
# ------------------------------------------------------------------------------
# Build TCMALLOC
# ------------------------------------------------------------------------------
if (BUILD_TCMALLOC)
if (BUILD_LINUX)
fail_if_not_found_library(libtcmalloc.a)
fail_if_not_found_library(libunwind.a)
fail_if_not_found_library(liblzma.a)
set(LIBRARIES ${LIBRARIES} ${libtcmalloc.a_LIBRARY})
set(LIBRARIES ${LIBRARIES} ${libunwind.a_LIBRARY})
set(LIBRARIES ${LIBRARIES} ${liblzma.a_LIBRARY})
set(LIBRARIES ${LIBRARIES} ${liblzma.a_LIBRARY})
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
fail_if_not_found_library(tcmalloc)
set(LIBRARIES ${LIBRARIES} tcmalloc)
set(LIBRARIES ${LIBRARIES} lzma)
else()
fail_if_not_found_library(tcmalloc)
fail_if_not_found_library(unwind)
set(LIBRARIES ${LIBRARIES} tcmalloc)
set(LIBRARIES ${LIBRARIES} unwind)
set(LIBRARIES ${LIBRARIES} lzma)
endif()
set(LIBRARIES ${LIBRARIES} pthread)
endif()
# ------------------------------------------------------------------------------
# special build case for OPENSSL
# ------------------------------------------------------------------------------
if(BUILD_TLS AND BUILD_CUSTOM_OPENSSL)
INCLUDE_DIRECTORIES("${BUILD_CUSTOM_OPENSSL}/include")
LINK_DIRECTORIES("${BUILD_CUSTOM_OPENSSL}")
LINK_DIRECTORIES("${BUILD_CUSTOM_OPENSSL}/lib")
endif()
# ------------------------------------------------------------------------------
#
# ------------------------------------------------------------------------------
# make the cmake list variables into .deb-compatible strings
string(REPLACE ";" ", " CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS_LIST}")
string(REPLACE ";" ", " CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS "${CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS_LIST}")
# ------------------------------------------------------------------------------
# Version
# ------------------------------------------------------------------------------
EXECUTE_PROCESS(COMMAND git describe --tags OUTPUT_VARIABLE VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
add_definitions(-DIS2_VERSION="${VERSION}")
# ------------------------------------------------------------------------------
# Debian Package Support
# ------------------------------------------------------------------------------
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
SET(DISTRIBUTION "macOS")
else()
EXECUTE_PROCESS(COMMAND lsb_release -cs OUTPUT_VARIABLE DISTRIBUTION OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
SET(CPACK_GENERATOR "DEB")
SET(CPACK_DEBIAN_PACKAGE_VERSION "${VERSION}-${DISTRIBUTION}")
SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
SET(CPACK_PACKAGE_FILE_NAME "is2_${CPACK_DEBIAN_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
SET(CPACK_DEBIAN_PACKAGE_NAME "is2")
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "Reed Morrison")
SET(CPACK_DEBIAN_PACKAGE_DEPENDS "")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "http(s) server library")
SET(CPACK_PACKAGE_DESCRIPTION "http(s) server library")
message(STATUS "Package Configuration:")
message("")
message(" Option Value ")
message(" ---------------------------------------------------------------------")
message(" Package Version: ${CPACK_DEBIAN_PACKAGE_VERSION}")
message("")
INCLUDE(CPack)
# ------------------------------------------------------------------------------
# include source and test directories
# ------------------------------------------------------------------------------
add_subdirectory(src)
if(BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
# ------------------------------------------------------------------------------
# docs
# ------------------------------------------------------------------------------
add_custom_target(docs
COMMAND doxygen ${CMAKE_CURRENT_SOURCE_DIR}/doxygen.conf WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
)