forked from Edgio/hurl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
224 lines (224 loc) · 10.6 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
221
222
223
224
# ------------------------------------------------------------------------------
# Project setup
# ------------------------------------------------------------------------------
project(hurl)
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_CUSTOM_OPENSSL "Build with custom OpenSSL" OFF)
option(BUILD_TESTS "Build the unit tests." OFF)
option(BUILD_LINUX "Build for Linux" OFF)
option(BUILD_KTLS_SUPPORT "Build with KTLS support - requires OpenSSL to be built with KTLS support as well" OFF)
# ------------------------------------------------------------------------------
# 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 for custom OpenSSL: " "BUILD_CUSTOM_OPENSSL " ${BUILD_CUSTOM_OPENSSL})
message(" Build unit tests: " "BUILD_TESTS " ${BUILD_TESTS})
message(" Build for Linux (adds package help): " "BUILD_LINUX " ${BUILD_LINUX})
message(" Build with KTLS support: " "BUILD_KTLS_SUPPORT " ${BUILD_KTLS_SUPPORT})
message("")
# ------------------------------------------------------------------------------
# OS X specific code
# ------------------------------------------------------------------------------
IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
SET(OperatingSystem "Mac OS X")
INCLUDE_DIRECTORIES(/usr/local/opt/rapidjson/include)
# Add MacPorts
if(BUILD_TLS)
INCLUDE_DIRECTORIES(/usr/local/opt/openssl/include)
LINK_DIRECTORIES(/usr/local/opt/openssl/lib)
endif()
if(BUILD_TCMALLOC OR BUILD_PROFILER)
INCLUDE_DIRECTORIES(/usr/local/opt/gperftools/include)
LINK_DIRECTORIES(/usr/local/opt/gperftools/lib)
endif()
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# ------------------------------------------------------------------------------
# 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(-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(-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)
elseif (BUILD_SYMBOLS)
add_definitions(-g3)
else()
add_definitions(-O2)
endif()
# Less strict/faster parsing
add_definitions(-DHTTP_PARSER_STRICT=0)
# ------------------------------------------------------------------------------
# add ssl libraries
# ------------------------------------------------------------------------------
set(LIBRARIES crypto ssl pthread)
# ------------------------------------------------------------------------------
# KTLS SUPPORT
# ------------------------------------------------------------------------------
if (BUILD_KTLS_SUPPORT)
add_definitions(-DKTLS_SUPPORT)
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})
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()
endif()
# ------------------------------------------------------------------------------
# special build case for OPENSSL
# ------------------------------------------------------------------------------
if(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
set(CPACK_DEBIAN_PACKAGE_DEPENDS_LIST
"libssl-dev"
)
string(REPLACE ";" ", " CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS_LIST}")
set(CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS_LIST
"libssl-dev"
)
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(-DHURL_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 "hurl_${CPACK_DEBIAN_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
SET(CPACK_DEBIAN_PACKAGE_NAME "hurl")
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "Reed Morrison")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "HTTP Server Utils.")
SET(CPACK_PACKAGE_DESCRIPTION "HTTP Server Utils for Edgio Inc.")
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(ext/nghttp2/src)
add_subdirectory(src)
if(BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
# ------------------------------------------------------------------------------
# add uninstall target
# ------------------------------------------------------------------------------
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
# ------------------------------------------------------------------------------
# docs
# ------------------------------------------------------------------------------
add_custom_target(docs
COMMAND doxygen ${CMAKE_CURRENT_SOURCE_DIR}/doxygen.conf WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
)