-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathCMakeLists.txt
330 lines (329 loc) · 15.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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# ------------------------------------------------------------------------------
# Project setup
# ------------------------------------------------------------------------------
project(waflz)
cmake_minimum_required(VERSION 3.5)
# ------------------------------------------------------------------------------
# Build options
# ------------------------------------------------------------------------------
option(GCC_OPTIONS "Command line options passed to gcc or 'native' to compile for this hardware" OFF)
option(DEBUG_MODE "Compile in debug mode." OFF)
option(FORTIFY "Fortify source." 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_TESTS "Build the unit tests." ON)
option(BUILD_APPS "Build the apps." OFF)
option(BUILD_REDIS "Build support for redis" OFF)
option(BUILD_UBUNTU "Build for Ubuntu" OFF)
option(BUILD_CUSTOM_OPENSSL "Build for openssl" OFF)
option(BUILD_REDHAT "Build for Red Hat" OFF)
option(BUILD_CUSTOM_CAPLENMAX "Build with custom CAP_LEN maximum" OFF)
# ------------------------------------------------------------------------------
# Add the corrent -std flag, whatever it is
# ------------------------------------------------------------------------------
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG(-Wno-error=misleading-indentation COMPILER_SUPPORTS_MISIDENT)
CHECK_CXX_COMPILER_FLAG(-Wno-error=nonnull-compare COMPILER_SUPPORTS_NONNULL)
CHECK_CXX_COMPILER_FLAG(-std=c++14 COMPILER_SUPPORTS_CXX14)
CHECK_CXX_COMPILER_FLAG(-std=c++11 COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG(-std=c++0x COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
elseif(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0x)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
endif()
if(COMPILER_SUPPORTS_CXX14)
if(COMPILER_SUPPORTS_MISIDENT)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=misleading-indentation")
endif()
if(COMPILER_SUPPORTS_NONNULL)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=nonnull-compare")
endif()
endif()
# ------------------------------------------------------------------------------
# find protobuf package
# ------------------------------------------------------------------------------
find_package(Protobuf REQUIRED)
# ------------------------------------------------------------------------------
# Display the current settings
# ------------------------------------------------------------------------------
message(STATUS "Build Configuration:")
message("")
message(" Build Option Variable Value ")
message(" -----------------------------------------------------------------------------------------")
message(" Debug mode: " "DEBUG_MODE " ${DEBUG_MODE})
message(" Fortify Source: " "FORTIFY " ${FORTIFY})
message(" Install path: " "INSTALL_PREFIX " ${CMAKE_INSTALL_PREFIX})
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 unit tests: " "BUILD_TESTS " ${BUILD_TESTS})
message(" Build applications: " "BUILD_APPS " ${BUILD_APPS})
message(" Build support for redis: " "BUILD_REDIS " ${BUILD_REDIS})
message(" Build for Ubuntu (adds package help): " "BUILD_UBUNTU " ${BUILD_UBUNTU})
message(" Build for custom OpenSSL: " "BUILD_CUSTOM_OPENSSL " ${BUILD_CUSTOM_OPENSSL})
message(" Build for Red Hat: " "BUILD_REDHAT " ${BUILD_REDHAT})
message(" Build with custom CAP_LEN maximum: " "BUILD_CUSTOM_CAPLENMAX " ${BUILD_CUSTOM_CAPLENMAX})
message("")
# ------------------------------------------------------------------------------
# Fortify Options
# ------------------------------------------------------------------------------
if(FORTIFY)
add_definitions(-D_FORTIFY_SOURCE=2 -O1 -Wl,-z,relro,-z,now)
endif()
# ------------------------------------------------------------------------------
# redis
# ------------------------------------------------------------------------------
if(BUILD_REDIS)
add_definitions(-DWAFLZ_KV_DB_REDIS)
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()
set(LIBRARIES ${LIBRARIES} ${a_lib})
endmacro(fail_if_not_found_library)
# ------------------------------------------------------------------------------
# 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()
if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(LIBRARIES ${LIBRARIES} pthread ssl crypto pcre protobuf xml2)
endif()
if(BUILD_REDHAT)
set(LIBRARIES ${LIBRARIES} ssl crypto pcre protobuf xml2)
add_definitions(-DWAFLZ_PCRE_INFO_FLAGS_MISSING)
endif()
# ------------------------------------------------------------------------------
# special build case for CUSTOM_CAPLENMAX
# ------------------------------------------------------------------------------
if(BUILD_CUSTOM_CAPLENMAX)
add_definitions(-DWAFLZ_CUSTOM_CAPLENMAX=${BUILD_CUSTOM_CAPLENMAX})
else()
add_definitions(-DWAFLZ_CUSTOM_CAPLENMAX=1024)
endif()
# ------------------------------------------------------------------------------
# Mac OS X
# ------------------------------------------------------------------------------
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# --------------------------------------------------------
# Mac OS X specific code
# --------------------------------------------------------
SET(OperatingSystem "Mac OS X")
# --------------------------------------------------------
# Add MacPorts
# --------------------------------------------------------
INCLUDE_DIRECTORIES(/usr/local/opt/openssl/include)
INCLUDE_DIRECTORIES(/usr/local/opt/protobuf/include)
INCLUDE_DIRECTORIES(/usr/local/opt/pcre/include)
INCLUDE_DIRECTORIES(/usr/local/opt/libxml2/include)
INCLUDE_DIRECTORIES(/usr/local/opt/rapidjson/include)
# --------------------------------------------------------
# link dirs
# --------------------------------------------------------
LINK_DIRECTORIES(/usr/local/opt/openssl/lib)
LINK_DIRECTORIES(/usr/local/opt/protobuf/lib)
LINK_DIRECTORIES(/usr/local/opt/pcre/lib)
LINK_DIRECTORIES(/usr/local/opt/libxml2/lib)
# --------------------------------------------------------
# if redis
# --------------------------------------------------------
if(BUILD_REDIS)
INCLUDE_DIRECTORIES(/usr/local/opt/hiredis/include)
LINK_DIRECTORIES(/usr/local/opt/hiredis/lib)
LIST(APPEND LIBRARIES hiredis)
endif()
# --------------------------------------------------------
# cc flags
# --------------------------------------------------------
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# ------------------------------------------------------------------------------
# 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 ubsan ${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()
# ------------------------------------------------------------------------------
# Build PROFILER
# ------------------------------------------------------------------------------
if(BUILD_PROFILER)
add_definitions(-DENABLE_PROFILER=1)
if(BUILD_UBUNTU)
fail_if_not_found_library(libprofiler.a)
set(LIBRARIES ${LIBRARIES} unwind)
else()
set(LIBRARIES ${LIBRARIES} tcmalloc profiler)
endif()
endif()
# ------------------------------------------------------------------------------
# Build TCMALLOC
# ------------------------------------------------------------------------------
if(BUILD_TCMALLOC)
if(BUILD_UBUNTU)
fail_if_not_found_library(libtcmalloc.a)
fail_if_not_found_library(libunwind.a)
LIST(APPEND LIBRARIES pthread)
endif()
endif()
# ------------------------------------------------------------------------------
# Build UBUNTU
# ------------------------------------------------------------------------------
if(BUILD_UBUNTU)
if(BUILD_APPS)
fail_if_not_found_library(libssl.a)
endif()
fail_if_not_found_library(libcrypto.a)
fail_if_not_found_library(libpcre.a)
fail_if_not_found_library(libprotobuf.a)
# --------------------------------------------------------
# if rate-limiting check for kv db libs
# --------------------------------------------------------
if(BUILD_REDIS)
fail_if_not_found_library(libhiredis.a)
endif()
# --------------------------------------------------------
# xml2 -brings in a lot...
# --------------------------------------------------------
fail_if_not_found_library(libxml2.a)
fail_if_not_found_library(libz.a)
fail_if_not_found_library(liblzma.a)
fail_if_not_found_library(libicuuc.a)
fail_if_not_found_library(libicudata.a)
fail_if_not_found_library(libicui18n.a)
endif()
# ------------------------------------------------------------------------------
#
# ------------------------------------------------------------------------------
if(FAILED_PACKAGES)
LIST(REMOVE_DUPLICATES MISSING_UBUNTU_PACKAGES)
string(REPLACE ";" " " MISSING_UBUNTU_PACKAGES_STR "${MISSING_UBUNTU_PACKAGES}")
message(FATAL_ERROR " Please install suggested packages: sudo apt-get install ${MISSING_UBUNTU_PACKAGES_STR} and try again.")
endif()
# ------------------------------------------------------------------------------
#
# ------------------------------------------------------------------------------
set(LIBRARIES ${LIBRARIES} dl)
set(LIBRARIES ${LIBRARIES} pthread)
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(LIBRARIES ${LIBRARIES} rt)
endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(LIBRARIES ${LIBRARIES} m)
message(STATUS "Libraries: ${LIBRARIES}")
# ------------------------------------------------------------------------------
# Optional flags
# ------------------------------------------------------------------------------
if(DEBUG_MODE)
add_definitions(-O0 -g3)
else()
add_definitions(-O2)
endif()
if(BUILD_SYMBOLS)
add_definitions(-g3)
endif()
# ------------------------------------------------------------------------------
# Build is2
# ------------------------------------------------------------------------------
include(ExternalProject)
if(BUILD_APPS)
ExternalProject_Add(submodule_is2
CMAKE_ARGS -DBUILD_TLS=ON
SOURCE_DIR ${CMAKE_SOURCE_DIR}/sub/is2
INSTALL_COMMAND ""
)
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 -C ${CMAKE_SOURCE_DIR} describe --tags OUTPUT_VARIABLE VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
add_definitions(-DWAFLZ_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")
if(BUILD_ASAN)
SET(CPACK_PACKAGE_FILE_NAME "waflz_${CPACK_DEBIAN_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}-debug")
else()
SET(CPACK_PACKAGE_FILE_NAME "waflz_${CPACK_DEBIAN_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
endif()
SET(CPACK_DEBIAN_PACKAGE_NAME "waflz")
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "Reed Morrison, Devender Singh, Revathi Sabanayagam, Raymond Mintz, Thomas Ahn")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Waflz Libraries and tools")
SET(CPACK_PACKAGE_DESCRIPTION "Waflz Libraries and tools")
message(STATUS "Package Configuration:")
message("")
message(" Option Value ")
message(" ---------------------------------------------------------------------")
message(" Package Version: ${CPACK_DEBIAN_PACKAGE_VERSION}")
message("")
INCLUDE(CPack)
# ------------------------------------------------------------------------------
# include source/test directories
# ------------------------------------------------------------------------------
add_subdirectory(proto)
add_subdirectory(src)
if(BUILD_APPS)
add_subdirectory(util)
endif()
if(BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
# ------------------------------------------------------------------------------
# release target
# NOTE deb has to exist in order to create tar.gz
# ------------------------------------------------------------------------------
if(BUILD_ASAN)
SET(RELEASE_PACKAGE_FILE_NAME "waflz_${CPACK_DEBIAN_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}-debug.deb")
else()
SET(RELEASE_PACKAGE_FILE_NAME "waflz_${CPACK_DEBIAN_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}.deb")
endif()
# ------------------------------------------------------------------------------
# docs
# ------------------------------------------------------------------------------
add_custom_target(docs
COMMAND doxygen ${CMAKE_CURRENT_SOURCE_DIR}/doxygen.conf WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
)