]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | # Determines what CMake APIs we can rely on |
2 | cmake_minimum_required (VERSION 2.8.11) | |
3 | if (${CMAKE_VERSION} VERSION_GREATER 3.2.2) | |
4 | cmake_policy(VERSION 3.2.2) | |
5 | endif() | |
6 | if (${CMAKE_VERSION} VERSION_GREATER 3.1 OR | |
7 | ${CMAKE_VERSION} VERSION_EQUAL 3.1) | |
8 | cmake_policy(SET CMP0054 NEW) | |
9 | endif() | |
10 | ||
11 | # Do not allow in source builds | |
12 | set(CMAKE_DISABLE_SOURCE_CHANGES ON) | |
13 | set(CMAKE_DISABLE_IN_SOURCE_BUILD ON) | |
14 | ||
15 | # Make sure we can import out CMake functions | |
16 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") | |
17 | ||
18 | # Load in the needed CMake modules | |
19 | include(CheckIncludeFiles) | |
20 | include(CheckCCompilerFlag) | |
21 | include(CheckCXXCompilerFlag) | |
22 | include(AddCCompilerFlag) | |
23 | include(AddCXXCompilerFlag) | |
24 | include(DetermineTargetArchitecture) | |
25 | include(CMakeDependentOption) | |
26 | ||
27 | # Set up the project | |
28 | project (civetweb) | |
11fdf7f2 | 29 | set(CIVETWEB_VERSION "1.10.0" CACHE STRING "The version of the civetweb library") |
7c673cae FG |
30 | string(REGEX MATCH "([0-9]+)\\.([0-9]+)\\.([0-9]+)" CIVETWEB_VERSION_MATCH "${CIVETWEB_VERSION}") |
31 | if ("${CIVETWEB_VERSION_MATCH}" STREQUAL "") | |
32 | message(FATAL_ERROR "Must specify a semantic version: major.minor.patch") | |
33 | endif() | |
34 | set(CIVETWEB_VERSION_MAJOR "${CMAKE_MATCH_1}") | |
35 | set(CIVETWEB_VERSION_MINOR "${CMAKE_MATCH_2}") | |
36 | set(CIVETWEB_VERSION_PATCH "${CMAKE_MATCH_3}") | |
37 | determine_target_architecture(CIVETWEB_ARCHITECTURE) | |
38 | ||
39 | # Detect the platform reliably | |
40 | if(NOT MACOSX AND ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") | |
41 | SET(DARWIN YES) | |
42 | elseif(NOT BSD AND ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") | |
43 | SET(FREEBSD YES) | |
44 | elseif(NOT LINUX AND ${CMAKE_SYSTEM_NAME} MATCHES "Linux") | |
45 | SET(LINUX YES) | |
46 | endif() | |
47 | ||
48 | # C++ wrappers | |
49 | option(CIVETWEB_ENABLE_THIRD_PARTY_OUTPUT "Shows the output of third party dependency processing" OFF) | |
50 | ||
7c673cae FG |
51 | # Thread Stack Size |
52 | set(CIVETWEB_THREAD_STACK_SIZE 102400 CACHE STRING | |
53 | "The stack size in bytes for each thread created") | |
54 | set_property(CACHE CIVETWEB_THREAD_STACK_SIZE PROPERTY VALUE ${CIVETWEB_THREAD_STACK_SIZE}) | |
55 | message(STATUS "Thread Stack Size - ${CIVETWEB_THREAD_STACK_SIZE}") | |
56 | ||
57 | # Serve no files from the web server | |
58 | option(CIVETWEB_SERVE_NO_FILES "Configures the server to serve no static files" OFF) | |
59 | message(STATUS "Serve no static files - ${CIVETWEB_SERVE_NO_FILES}") | |
60 | ||
61 | # Serve no files from the web server | |
62 | option(CIVETWEB_DISABLE_CGI "Disables CGI, so theserver will not execute CGI scripts" OFF) | |
63 | message(STATUS "Disable CGI support - ${CIVETWEB_DISABLE_CGI}") | |
64 | ||
65 | # Disable caching | |
66 | option(CIVETWEB_DISABLE_CACHING "Disables caching, so that no timegm is used." OFF) | |
67 | message(STATUS "Disable caching support - ${CIVETWEB_DISABLE_CACHING}") | |
68 | ||
69 | # C++ wrappers | |
70 | option(CIVETWEB_ENABLE_CXX "Enables the C++ wrapper library" OFF) | |
71 | message(STATUS "C++ wrappers - ${CIVETWEB_ENABLE_CXX}") | |
72 | ||
73 | # IP Version 6 | |
74 | option(CIVETWEB_ENABLE_IPV6 "Enables the IP version 6 support" OFF) | |
75 | message(STATUS "IP Version 6 - ${CIVETWEB_ENABLE_IPV6}") | |
76 | ||
77 | # Websocket support | |
78 | option(CIVETWEB_ENABLE_WEBSOCKETS "Enable websockets connections" OFF) | |
79 | message(STATUS "Websockets support - ${CIVETWEB_ENABLE_WEBSOCKETS}") | |
80 | ||
11fdf7f2 TL |
81 | # Server statistics support |
82 | option(CIVETWEB_ENABLE_SERVER_STATS "Enable server statistics" OFF) | |
83 | message(STATUS "Server statistics support - ${CIVETWEB_ENABLE_SERVER_STATS}") | |
84 | ||
7c673cae FG |
85 | # Memory debugging |
86 | option(CIVETWEB_ENABLE_MEMORY_DEBUGGING "Enable the memory debugging features" OFF) | |
87 | message(STATUS "Memory Debugging - ${CIVETWEB_ENABLE_MEMORY_DEBUGGING}") | |
88 | ||
11fdf7f2 TL |
89 | # ASAN in debug mode (-fsanitize=address, etc) |
90 | option(CIVETWEB_ENABLE_ASAN "Enable ASAN in debug mode" ON) | |
91 | message(STATUS "ASAN in debug mode - ${CIVETWEB_ENABLE_ASAN}") | |
92 | ||
93 | # ARCH flag | |
94 | option(CIVETWEB_ARCH "Force 32/64 bit architecture" OFF) | |
95 | message(STATUS "Force x32 / x64 architecture - ${CIVETWEB_ARCH}") | |
96 | ||
7c673cae FG |
97 | # LUA CGI support |
98 | option(CIVETWEB_ENABLE_LUA "Enable Lua CGIs" OFF) | |
99 | message(STATUS "Lua CGI support - ${CIVETWEB_ENABLE_LUA}") | |
100 | ||
11fdf7f2 TL |
101 | # Enable installing CivetWeb executables |
102 | option(CIVETWEB_INSTALL_EXECUTABLE "Enable installing CivetWeb executable" ON) | |
103 | mark_as_advanced(FORCE CIVETWEB_INSTALL_EXECUTABLE) # Advanced users can disable | |
104 | message(STATUS "Executable installation - ${CIVETWEB_INSTALL_EXECUTABLE}") | |
105 | ||
7c673cae | 106 | # Allow builds to complete with warnings (do not set -Werror) |
11fdf7f2 TL |
107 | # CivetWeb Linux support is stable: |
108 | # Builds for GCC 4.6 and clang 3.4 are free from warnings. | |
109 | # However, GCC introduced a couple of new, partially idiotic warnings, | |
110 | # that can not be disabled using a #pragma directive. | |
111 | # It seems unreasonable to have all GCC versions warning free, but only | |
112 | # some selected ones. | |
113 | option(CIVETWEB_ALLOW_WARNINGS "Do not stop build if there are warnings" ON) | |
7c673cae FG |
114 | message(STATUS "Build if there are warnings - ${CIVETWEB_ALLOW_WARNINGS}") |
115 | ||
116 | # Link to the shared LUA library | |
117 | cmake_dependent_option( | |
118 | CIVETWEB_ENABLE_LUA_SHARED "Link to the shared LUA system library" OFF | |
119 | CIVETWEB_ENABLE_LUA OFF) | |
120 | if (CIVETWEB_ENABLE_LUA) | |
121 | message(STATUS "Linking shared Lua library - ${CIVETWEB_ENABLE_LUA_SHARED}") | |
122 | endif() | |
123 | ||
124 | # Lua Third Party Settings | |
125 | if (CIVETWEB_ENABLE_LUA) | |
126 | if (NOT CIVETWEB_ENABLE_LUA_SHARED) | |
127 | # Lua Version | |
128 | set(CIVETWEB_LUA_VERSION 5.2.4 CACHE STRING | |
129 | "The version of Lua to build and include statically") | |
130 | set_property(CACHE CIVETWEB_LUA_VERSION PROPERTY VALUE ${CIVETWEB_LUA_VERSION}) | |
131 | message(STATUS "Lua Version - ${CIVETWEB_LUA_VERSION}") | |
132 | mark_as_advanced(CIVETWEB_LUA_VERSION) | |
133 | ||
134 | # Lua Verification Hash | |
135 | set(CIVETWEB_LUA_MD5_HASH 913fdb32207046b273fdb17aad70be13 CACHE STRING | |
136 | "The hash of Lua archive to be downloaded") | |
137 | set_property(CACHE CIVETWEB_LUA_MD5_HASH PROPERTY VALUE ${CIVETWEB_LUA_MD5_HASH}) | |
138 | mark_as_advanced(CIVETWEB_LUA_MD5_HASH) | |
139 | endif() | |
140 | ||
141 | # Lua Filesystem Version | |
142 | set(CIVETWEB_LUA_FILESYSTEM_VERSION 1.6.3 CACHE STRING | |
143 | "The version of Lua Filesystem to build and include statically") | |
144 | set_property(CACHE CIVETWEB_LUA_FILESYSTEM_VERSION PROPERTY VALUE ${CIVETWEB_LUA_FILESYSTEM_VERSION}) | |
145 | message(STATUS "Lua Filesystem Version - ${CIVETWEB_LUA_FILESYSTEM_VERSION}") | |
146 | mark_as_advanced(CIVETWEB_LUA_FILESYSTEM_VERSION) | |
147 | ||
148 | # Lua Filesystem Verification Hash | |
149 | set(CIVETWEB_LUA_FILESYSTEM_MD5_HASH d0552c7e5a082f5bb2865af63fb9dc95 CACHE STRING | |
150 | "The hash of Lua Filesystem archive to be downloaded") | |
151 | set_property(CACHE CIVETWEB_LUA_FILESYSTEM_MD5_HASH PROPERTY VALUE ${CIVETWEB_LUA_FILESYSTEM_MD5_HASH}) | |
152 | mark_as_advanced(CIVETWEB_LUA_FILESYSTEM_MD5_HASH) | |
153 | ||
154 | # Lua SQLite Version | |
155 | set(CIVETWEB_LUA_SQLITE_VERSION 0.9.3 CACHE STRING | |
156 | "The version of Lua SQLite to build and include statically") | |
157 | set_property(CACHE CIVETWEB_LUA_SQLITE_VERSION PROPERTY VALUE ${CIVETWEB_LUA_SQLITE_VERSION}) | |
158 | message(STATUS "Lua SQLite Version - ${CIVETWEB_LUA_SQLITE_VERSION}") | |
159 | mark_as_advanced(CIVETWEB_LUA_SQLITE_VERSION) | |
160 | ||
161 | # Lua SQLite Verification Hash | |
162 | set(CIVETWEB_LUA_SQLITE_MD5_HASH 43234ae08197dfce6da02482ed14ec92 CACHE STRING | |
163 | "The hash of Lua SQLite archive to be downloaded") | |
164 | set_property(CACHE CIVETWEB_LUA_SQLITE_MD5_HASH PROPERTY VALUE ${CIVETWEB_LUA_SQLITE_MD5_HASH}) | |
165 | mark_as_advanced(CIVETWEB_LUA_SQLITE_MD5_HASH) | |
166 | ||
167 | # Lua XML Version | |
168 | set(CIVETWEB_LUA_XML_VERSION 1.8.0 CACHE STRING | |
169 | "The version of Lua XML to build and include statically") | |
170 | set_property(CACHE CIVETWEB_LUA_XML_VERSION PROPERTY VALUE ${CIVETWEB_LUA_XML_VERSION}) | |
171 | message(STATUS "Lua XML Version - ${CIVETWEB_LUA_XML_VERSION}") | |
172 | mark_as_advanced(CIVETWEB_LUA_XML_VERSION) | |
173 | ||
174 | # Lua XML Verification Hash | |
175 | set(CIVETWEB_LUA_XML_MD5_HASH 25e4c276c5d8716af1de0c7853aec2b4 CACHE STRING | |
176 | "The hash of Lua XML archive to be downloaded") | |
177 | set_property(CACHE CIVETWEB_LUA_XML_MD5_HASH PROPERTY VALUE ${CIVETWEB_LUA_XML_MD5_HASH}) | |
178 | mark_as_advanced(CIVETWEB_LUA_XML_MD5_HASH) | |
179 | ||
180 | # SQLite Version | |
181 | set(CIVETWEB_SQLITE_VERSION 3.8.9 CACHE STRING | |
182 | "The version of SQLite to build and include statically") | |
183 | set_property(CACHE CIVETWEB_SQLITE_VERSION PROPERTY VALUE ${CIVETWEB_SQLITE_VERSION}) | |
184 | message(STATUS "SQLite Version - ${CIVETWEB_SQLITE_VERSION}") | |
185 | mark_as_advanced(CIVETWEB_SQLITE_VERSION) | |
186 | ||
187 | # SQLite Verification Hash | |
188 | set(CIVETWEB_SQLITE_MD5_HASH 02e9c3a6daa8b8587cf6bef828c2e33f CACHE STRING | |
189 | "The hash of SQLite archive to be downloaded") | |
190 | set_property(CACHE CIVETWEB_SQLITE_MD5_HASH PROPERTY VALUE ${CIVETWEB_SQLITE_MD5_HASH}) | |
191 | mark_as_advanced(CIVETWEB_SQLITE_MD5_HASH) | |
192 | endif() | |
193 | ||
194 | # Duktape CGI support | |
195 | option(CIVETWEB_ENABLE_DUKTAPE "Enable Duktape CGIs" OFF) | |
196 | message(STATUS "Duktape CGI support - ${CIVETWEB_ENABLE_DUKTAPE}") | |
197 | ||
198 | # SSL support | |
199 | option(CIVETWEB_ENABLE_SSL "Enables the secure socket layer" ON) | |
200 | message(STATUS "SSL support - ${CIVETWEB_ENABLE_SSL}") | |
201 | ||
11fdf7f2 TL |
202 | # OpenSSL 1.1 API |
203 | option(CIVETWEB_SSL_OPENSSL_API_1_1 "Use the OpenSSL 1.1 API" OFF) | |
204 | message(STATUS "Compile for OpenSSL 1.1 API - ${CIVETWEB_SSL_OPENSSL_API_1_1}") | |
205 | ||
7c673cae FG |
206 | # Dynamically load or link the SSL libraries |
207 | cmake_dependent_option( | |
208 | CIVETWEB_ENABLE_SSL_DYNAMIC_LOADING "Dynamically loads the SSL library rather than linking it" ON | |
209 | CIVETWEB_ENABLE_SSL OFF) | |
210 | if (CIVETWEB_ENABLE_SSL) | |
211 | message(STATUS "Dynamically load SSL libraries - ${CIVETWEB_ENABLE_SSL_DYNAMIC_LOADING}") | |
212 | endif() | |
213 | ||
214 | # Third Party Download location | |
215 | set(CIVETWEB_THIRD_PARTY_DIR "${CMAKE_BINARY_DIR}/third_party" CACHE STRING | |
216 | "The location that third party code is downloaded, built and installed") | |
217 | set_property(CACHE CIVETWEB_THIRD_PARTY_DIR PROPERTY VALUE ${CIVETWEB_THIRD_PARTY_DIR}) | |
218 | ||
219 | # Unix systems can define the dynamic library names to load | |
220 | if (CIVETWEB_ENABLE_SSL_DYNAMIC_LOADING AND NOT DARWIN AND UNIX) | |
221 | # SSL library name | |
222 | set(CIVETWEB_SSL_SSL_LIB "libssl.so" CACHE STRING | |
223 | "The name of the SSL library to load") | |
224 | set_property(CACHE CIVETWEB_SSL_SSL_LIB PROPERTY VALUE ${CIVETWEB_SSL_SSL_LIB}) | |
225 | message(STATUS "SSL Library Name - ${CIVETWEB_SSL_SSL_LIB}") | |
226 | ||
227 | # Crytography library name | |
228 | set(CIVETWEB_SSL_CRYPTO_LIB "libcrypto.so" CACHE STRING | |
229 | "The name of the SSL Cryptography library to load") | |
230 | set_property(CACHE CIVETWEB_SSL_CRYPTO_LIB PROPERTY VALUE ${CIVETWEB_SSL_CRYPTO_LIB}) | |
231 | message(STATUS "SSL Cryptography Library Name - ${CIVETWEB_SSL_CRYPTO_LIB}") | |
232 | endif() | |
233 | ||
234 | # Allow warnings in 3rd party components | |
235 | if (CIVETWEB_ENABLE_LUA OR CIVETWEB_ENABLE_DUKTAPE) | |
236 | SET(CIVETWEB_ALLOW_WARNINGS YES) | |
237 | endif() | |
238 | ||
239 | # The C and C++ standards to use | |
240 | set(CIVETWEB_C_STANDARD auto CACHE STRING | |
241 | "The C standard to use; auto determines the latest supported by the compiler") | |
242 | set_property(CACHE CIVETWEB_C_STANDARD PROPERTY STRINGS auto c11 c99 c89) | |
243 | set(CIVETWEB_CXX_STANDARD auto CACHE STRING | |
244 | "The C++ standard to use; auto determines the latest supported by the compiler") | |
245 | set_property(CACHE CIVETWEB_CXX_STANDARD PROPERTY STRINGS auto c++14 c++11 c++98) | |
246 | ||
247 | # Configure the linker | |
248 | if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") | |
249 | find_program(GCC_AR gcc-ar) | |
250 | if (GCC_AR) | |
251 | set(CMAKE_AR ${GCC_AR}) | |
252 | endif() | |
253 | find_program(GCC_RANLIB gcc-ranlib) | |
254 | if (GCC_RANLIB) | |
255 | set(CMAKE_RANLIB ${GCC_RANLIB}) | |
256 | endif() | |
257 | endif() | |
258 | ||
259 | # Configure the C compiler | |
260 | message(STATUS "Configuring C Compiler") | |
261 | if ("${CIVETWEB_C_STANDARD}" STREQUAL "auto") | |
262 | add_c_compiler_flag(-std=c11) | |
263 | if (NOT HAVE_C_FLAG_STD_C11) | |
264 | add_c_compiler_flag(-std=c99) | |
265 | if (NOT HAVE_C_FLAG_STD_C99) | |
266 | add_c_compiler_flag(-std=c89) | |
267 | endif() | |
268 | endif() | |
269 | else() | |
270 | add_c_compiler_flag(-std=${CIVETWEB_C_STANDARD}) | |
271 | endif() | |
11fdf7f2 TL |
272 | |
273 | #Warnings: enable everything | |
7c673cae FG |
274 | add_c_compiler_flag(-Wall) |
275 | add_c_compiler_flag(-Wextra) | |
276 | add_c_compiler_flag(-Wshadow) | |
11fdf7f2 | 277 | add_c_compiler_flag(-Wconversion) |
7c673cae FG |
278 | add_c_compiler_flag(-Wmissing-prototypes) |
279 | add_c_compiler_flag(-Weverything) | |
11fdf7f2 TL |
280 | add_c_compiler_flag(-Wparentheses) |
281 | add_c_compiler_flag(/W4) # VisualStudio highest warning level | |
282 | ||
283 | #Warnings: Disable some warnings | |
284 | add_c_compiler_flag(-Wno-padded) # padding in structures by compiler | |
285 | add_c_compiler_flag(-Wno-unused-macros) # so what? | |
286 | add_c_compiler_flag(-Wno-reserved-id-macros) # for system headers | |
287 | add_c_compiler_flag(-Wno-format-nonliteral) # printf(myFormatStringVar, ...) | |
288 | add_c_compiler_flag(-Wno-date-time) # using __DATE__ once | |
289 | add_c_compiler_flag(-Wno-cast-qual) # const cast | |
7c673cae | 290 | add_c_compiler_flag(/Wd4820) # padding |
11fdf7f2 | 291 | |
7c673cae FG |
292 | if (MINGW) |
293 | add_c_compiler_flag(-Wno-format) | |
294 | endif() | |
295 | if (NOT CIVETWEB_ALLOW_WARNINGS) | |
296 | add_c_compiler_flag(-Werror) | |
297 | endif() | |
298 | add_c_compiler_flag(/WX) | |
299 | add_c_compiler_flag(-pedantic-errors) | |
300 | add_c_compiler_flag(-fvisibility=hidden) | |
301 | add_c_compiler_flag(-fstack-protector-strong RELEASE) | |
302 | add_c_compiler_flag(-flto RELEASE) | |
11fdf7f2 | 303 | if (${CIVETWEB_ENABLE_ASAN}) |
7c673cae FG |
304 | add_c_compiler_flag(-fsanitize=undefined DEBUG) |
305 | add_c_compiler_flag(-fsanitize=address DEBUG) | |
306 | if (HAVE_C_FLAG_FSANITIZE_ADDRESS) | |
307 | add_c_compiler_flag(-static-asan DEBUG) | |
308 | endif() | |
11fdf7f2 | 309 | endif() |
7c673cae FG |
310 | add_c_compiler_flag(-fstack-protector-all DEBUG) |
311 | if (MINGW) | |
312 | add_c_compiler_flag(-mwindows) | |
313 | endif() | |
314 | ||
315 | # Coverage build type | |
316 | set(CMAKE_C_FLAGS_COVERAGE "${CMAKE_C_FLAGS_DEBUG}" CACHE STRING | |
317 | "Flags used by the C compiler during coverage builds." | |
318 | FORCE) | |
319 | set(CMAKE_EXE_LINKER_FLAGS_COVERAGE | |
320 | "${CMAKE_EXE_LINKER_FLAGS_DEBUG}" CACHE STRING | |
321 | "Flags used for linking binaries during coverage builds." | |
322 | FORCE) | |
323 | set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE | |
324 | "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}" CACHE STRING | |
325 | "Flags used by the shared libraries linker during coverage builds." | |
326 | FORCE) | |
327 | mark_as_advanced( | |
328 | CMAKE_CXX_FLAGS_COVERAGE | |
329 | CMAKE_C_FLAGS_COVERAGE | |
330 | CMAKE_EXE_LINKER_FLAGS_COVERAGE | |
331 | CMAKE_SHARED_LINKER_FLAGS_COVERAGE) | |
332 | set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING | |
333 | "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Coverage." | |
334 | FORCE) | |
335 | add_c_compiler_flag(--coverage COVERAGE) | |
336 | ||
337 | # Configure the C++ compiler | |
338 | if (CIVETWEB_ENABLE_CXX) | |
339 | message(STATUS "Configuring C++ Compiler") | |
340 | if ("${CIVETWEB_CXX_STANDARD}" STREQUAL "auto") | |
341 | add_cxx_compiler_flag(-std=c++14) | |
342 | if (NOT HAVE_CXX_FLAG_STD_CXX14) | |
343 | add_cxx_compiler_flag(-std=c++11) | |
344 | if (NOT HAVE_CXX_FLAG_STD_CXX11) | |
345 | add_cxx_compiler_flag(-std=c++98) | |
346 | endif() | |
347 | endif() | |
348 | else() | |
349 | add_cxx_compiler_flag(-std=${CIVETWEB_CXX_STANDARD}) | |
350 | endif() | |
351 | add_cxx_compiler_flag(-Wall) | |
352 | add_cxx_compiler_flag(-Wextra) | |
353 | add_cxx_compiler_flag(-Wshadow) | |
354 | add_cxx_compiler_flag(-Wmissing-prototypes) | |
355 | add_cxx_compiler_flag(-Weverything) | |
356 | add_cxx_compiler_flag(/W4) | |
357 | add_cxx_compiler_flag(-Wno-padded) | |
358 | add_cxx_compiler_flag(/Wd4820) # padding | |
359 | add_cxx_compiler_flag(-Wno-unused-macros) | |
360 | add_cxx_compiler_flag(-Wno-format-nonliteral) | |
361 | if (MINGW) | |
362 | add_cxx_compiler_flag(-Wno-format) | |
363 | endif() | |
364 | if (NOT CIVETWEB_ALLOW_WARNINGS) | |
365 | add_cxx_compiler_flag(-Werror) | |
366 | endif() | |
367 | add_cxx_compiler_flag(/WX) | |
368 | add_cxx_compiler_flag(-pedantic-errors) | |
369 | add_cxx_compiler_flag(-fvisibility=hidden) | |
370 | add_cxx_compiler_flag(-fstack-protector-strong RELEASE) | |
371 | add_cxx_compiler_flag(-flto RELEASE) | |
11fdf7f2 | 372 | if (${CIVETWEB_ENABLE_ASAN}) |
7c673cae FG |
373 | add_cxx_compiler_flag(-fsanitize=undefined DEBUG) |
374 | add_cxx_compiler_flag(-fsanitize=address DEBUG) | |
375 | if (HAVE_CXX_FLAG_FSANITIZE_ADDRESS) | |
376 | add_cxx_compiler_flag(-static-asan DEBUG) | |
377 | endif() | |
11fdf7f2 | 378 | endif() |
7c673cae FG |
379 | add_cxx_compiler_flag(-fstack-protector-all DEBUG) |
380 | if (MINGW) | |
381 | add_cxx_compiler_flag(-mwindows) | |
382 | endif() | |
383 | set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING | |
384 | "Flags used by the C++ compiler during coverage builds." | |
385 | FORCE) | |
386 | add_cxx_compiler_flag(--coverage COVERAGE) | |
387 | endif() | |
388 | ||
7c673cae FG |
389 | # Set up the definitions |
390 | if (${CMAKE_BUILD_TYPE} MATCHES "[Dd]ebug") | |
391 | add_definitions(-DDEBUG) | |
392 | endif() | |
7c673cae FG |
393 | if (CIVETWEB_ENABLE_IPV6) |
394 | add_definitions(-DUSE_IPV6) | |
395 | endif() | |
396 | if (CIVETWEB_ENABLE_WEBSOCKETS) | |
397 | add_definitions(-DUSE_WEBSOCKET) | |
398 | endif() | |
11fdf7f2 TL |
399 | if (CIVETWEB_ENABLE_SERVER_STATS) |
400 | add_definitions(-DUSE_SERVER_STATS) | |
401 | endif() | |
7c673cae FG |
402 | if (CIVETWEB_SERVE_NO_FILES) |
403 | add_definitions(-DNO_FILES) | |
404 | endif() | |
405 | if (CIVETWEB_DISABLE_CGI) | |
406 | add_definitions(-DNO_CGI) | |
407 | endif() | |
408 | if (CIVETWEB_DISABLE_CACHING) | |
409 | add_definitions(-DNO_CACHING) | |
410 | endif() | |
411 | if (CIVETWEB_ENABLE_LUA) | |
412 | add_definitions(-DUSE_LUA) | |
413 | endif() | |
414 | if (CIVETWEB_ENABLE_DUKTAPE) | |
415 | add_definitions(-DUSE_DUKTAPE) | |
416 | endif() | |
417 | if (CIVETWEB_ENABLE_MEMORY_DEBUGGING) | |
418 | add_definitions(-DMEMORY_DEBUGGING) | |
419 | endif() | |
420 | if (NOT CIVETWEB_ENABLE_SSL) | |
421 | add_definitions(-DNO_SSL) | |
422 | elseif (NOT CIVETWEB_ENABLE_SSL_DYNAMIC_LOADING) | |
423 | add_definitions(-DNO_SSL_DL) | |
424 | else() | |
425 | if(CIVETWEB_SSL_SSL_LIB) | |
426 | add_definitions(-DSSL_LIB="${CIVETWEB_SSL_SSL_LIB}") | |
427 | endif() | |
428 | if(CIVETWEB_SSL_CRYPTO_LIB) | |
429 | add_definitions(-DCRYPTO_LIB="${CIVETWEB_SSL_CRYPTO_LIB}") | |
430 | endif() | |
431 | endif() | |
11fdf7f2 TL |
432 | if(CIVETWEB_SSL_OPENSSL_API_1_1) |
433 | add_definitions(-DOPENSSL_API_1_1) | |
434 | endif() | |
7c673cae | 435 | add_definitions(-DUSE_STACK_SIZE=${CIVETWEB_THREAD_STACK_SIZE}) |
11fdf7f2 TL |
436 | |
437 | # Set 32 or 64 bit environment | |
438 | if (${CMAKE_ARCH} MATCHES "[Xx]86") | |
439 | add_c_compiler_flag(-m32) | |
440 | endif() | |
441 | if (${CMAKE_ARCH} MATCHES "[Xx]64") | |
442 | add_c_compiler_flag(-m64) | |
443 | endif() | |
444 | # TODO: add support for -march | |
7c673cae FG |
445 | |
446 | # Build the targets | |
447 | add_subdirectory(src) | |
448 | ||
449 | # Enable the testing of the library/executable | |
450 | include(CTest) | |
451 | if (BUILD_TESTING) | |
452 | # Check unit testing framework Version | |
11fdf7f2 | 453 | set(CIVETWEB_CHECK_VERSION 0.11.0 CACHE STRING |
7c673cae FG |
454 | "The version of Check unit testing framework to build and include statically") |
455 | set_property(CACHE CIVETWEB_CHECK_VERSION PROPERTY VALUE ${CIVETWEB_CHECK_VERSION}) | |
456 | message(STATUS "Check Unit Testing Framework Version - ${CIVETWEB_CHECK_VERSION}") | |
457 | mark_as_advanced(CIVETWEB_CHECK_VERSION) | |
458 | ||
459 | # Check unit testing framework Verification Hash | |
11fdf7f2 TL |
460 | # Hash for Check 0.10.0: 67a34c40b5bc888737f4e5ae82e9939f |
461 | # Hash for Check 0.11.0: 1b14ee307dca8e954a8219c34484d7c4 | |
462 | set(CIVETWEB_CHECK_MD5_HASH 1b14ee307dca8e954a8219c34484d7c4 CACHE STRING | |
7c673cae FG |
463 | "The hash of Check unit testing framework archive to be downloaded") |
464 | set_property(CACHE CIVETWEB_CHECK_MD5_HASH PROPERTY VALUE ${CIVETWEB_CHECK_MD5_HASH}) | |
465 | mark_as_advanced(CIVETWEB_CHECK_MD5_HASH) | |
466 | ||
467 | # Build the testing | |
468 | add_subdirectory(test) | |
469 | endif() | |
470 | ||
471 | # Set up CPack | |
472 | include(InstallRequiredSystemLibraries) | |
473 | set(CPACK_PACKAGE_VENDOR "civetweb Contributors") | |
474 | set(CPACK_PACKAGE_CONTACT "civetweb@github.com") | |
475 | set(CPACK_PACKAGE_VERSION_MAJOR "${CIVETWEB_VERSION_MAJOR}") | |
476 | set(CPACK_PACKAGE_VERSION_MINOR "${CIVETWEB_VERSION_MINOR}") | |
477 | set(CPACK_PACKAGE_VERSION_PATCH "${CIVETWEB_VERSION_PATCH}") | |
478 | set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A HTTP library and server") | |
479 | set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md") | |
480 | set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.md") | |
481 | set(CPACK_STRIP_FILES TRUE) | |
482 | set(CPACK_PACKAGE_DEPENDS "openssl") | |
483 | if (CIVETWEB_ENABLE_LUA_SHARED) | |
484 | set(CPACK_PACKAGE_DEPENDS "lua, ${CPACK_PACKAGE_DEPENDS}") | |
485 | endif() | |
486 | ||
487 | # RPM Packaging | |
488 | set(CPACK_RPM_PACKAGE_GROUP "Development/Libraries") | |
489 | set(CPACK_RPM_PACKAGE_LICENSE "MIT") | |
490 | set(CPACK_RPM_PACKAGE_ARCHITECTURE "${CIVETWEB_ARCHITECTURE}") | |
491 | set(CPACK_RPM_PACKAGE_REQUIRES "${CPACK_PACKAGE_DEPENDS}") | |
492 | ||
493 | # Debian Packaging | |
494 | set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "${CIVETWEB_ARCHITECTURE}") | |
495 | set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/civetweb/civetweb") | |
496 | set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_PACKAGE_DEPENDS}") | |
497 | ||
498 | # WiX Packaging | |
499 | # TODO: www.cmake.org/cmake/help/v3.0/module/CPackWIX.html | |
500 | ||
501 | # Finalize CPack settings | |
502 | include(CPack) |