]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | # Use at least CMake 3.3 |
2 | cmake_minimum_required (VERSION 3.3.0) | |
3 | cmake_policy(VERSION 3.2.2) | |
4 | cmake_policy(SET CMP0054 NEW) | |
5 | ||
6 | # Set up the project | |
7 | project (civetweb) | |
8 | ||
9 | # Detect the platform reliably | |
10 | if(ZEPHYR_BASE) | |
11 | if (NOT CONFIG_CIVETWEB) | |
12 | return() | |
13 | endif() | |
14 | SET(ZEPHYR YES) | |
15 | elseif(NOT MACOSX AND ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") | |
16 | SET(DARWIN YES) | |
17 | elseif(NOT BSD AND ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") | |
18 | SET(FREEBSD YES) | |
19 | elseif(NOT LINUX AND ${CMAKE_SYSTEM_NAME} MATCHES "Linux") | |
20 | SET(LINUX YES) | |
21 | endif() | |
22 | ||
23 | # Do not allow in source builds | |
24 | set(CMAKE_DISABLE_SOURCE_CHANGES ON) | |
25 | set(CMAKE_DISABLE_IN_SOURCE_BUILD ON) | |
26 | ||
27 | # Make sure we can import out CMake functions | |
28 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") | |
29 | ||
30 | # Load in the needed CMake modules | |
31 | include(CheckIncludeFiles) | |
32 | include(CheckCCompilerFlag) | |
33 | include(CheckCXXCompilerFlag) | |
34 | include(AddCCompilerFlag) | |
35 | include(AddCXXCompilerFlag) | |
36 | include(DetermineTargetArchitecture) | |
37 | include(CMakeDependentOption) | |
38 | ||
39 | set(CIVETWEB_VERSION "1.15.0" CACHE STRING "The version of the civetweb library") | |
40 | string(REGEX MATCH "([0-9]+)\\.([0-9]+)\\.([0-9]+)" CIVETWEB_VERSION_MATCH "${CIVETWEB_VERSION}") | |
41 | if ("${CIVETWEB_VERSION_MATCH}" STREQUAL "") | |
42 | message(FATAL_ERROR "Must specify a semantic version: major.minor.patch") | |
43 | endif() | |
44 | set(CIVETWEB_VERSION_MAJOR "${CMAKE_MATCH_1}") | |
45 | set(CIVETWEB_VERSION_MINOR "${CMAKE_MATCH_2}") | |
46 | set(CIVETWEB_VERSION_PATCH "${CMAKE_MATCH_3}") | |
47 | determine_target_architecture(CIVETWEB_ARCHITECTURE) | |
48 | include(GNUInstallDirs) | |
49 | ||
50 | # CTest automation | |
51 | option(CIVETWEB_BUILD_TESTING "Enable automated testing of civetweb" ON) | |
52 | message(STATUS "Enabling tests in the build - ${CIVETWEB_BUILD_TESTING}") | |
53 | ||
54 | # C++ wrappers | |
55 | option(CIVETWEB_ENABLE_THIRD_PARTY_OUTPUT "Shows the output of third party dependency processing" OFF) | |
56 | ||
57 | # Thread Stack Size | |
58 | set(CIVETWEB_THREAD_STACK_SIZE 102400 CACHE STRING | |
59 | "The stack size in bytes for each thread created") | |
60 | set_property(CACHE CIVETWEB_THREAD_STACK_SIZE PROPERTY VALUE ${CIVETWEB_THREAD_STACK_SIZE}) | |
61 | message(STATUS "Thread Stack Size - ${CIVETWEB_THREAD_STACK_SIZE}") | |
62 | ||
63 | option(CIVETWEB_ENABLE_SERVER_EXECUTABLE "Enable building of the server executable" ON) | |
64 | message(STATUS "Enabling server executable - ${CIVETWEB_ENABLE_SERVER_EXECUTABLE}") | |
65 | ||
66 | # Serve no files from the web server | |
67 | option(CIVETWEB_SERVE_NO_FILES "Configures the server to serve no static files" OFF) | |
68 | message(STATUS "Serve no static files - ${CIVETWEB_SERVE_NO_FILES}") | |
69 | ||
70 | # Serve no files from the web server | |
71 | option(CIVETWEB_DISABLE_CGI "Disables CGI, so theserver will not execute CGI scripts" OFF) | |
72 | message(STATUS "Disable CGI support - ${CIVETWEB_DISABLE_CGI}") | |
73 | ||
74 | # Disable caching | |
75 | option(CIVETWEB_DISABLE_CACHING "Disables caching, so that no timegm is used." OFF) | |
76 | message(STATUS "Disable caching support - ${CIVETWEB_DISABLE_CACHING}") | |
77 | ||
78 | # C++ wrappers | |
79 | option(CIVETWEB_ENABLE_CXX "Enables the C++ wrapper library" OFF) | |
80 | message(STATUS "C++ wrappers - ${CIVETWEB_ENABLE_CXX}") | |
81 | ||
82 | # IP Version 6 | |
83 | option(CIVETWEB_ENABLE_IPV6 "Enables the IP version 6 support" OFF) | |
84 | message(STATUS "IP Version 6 - ${CIVETWEB_ENABLE_IPV6}") | |
85 | ||
86 | # Websocket support | |
87 | option(CIVETWEB_ENABLE_WEBSOCKETS "Enable websockets connections" OFF) | |
88 | message(STATUS "Websockets support - ${CIVETWEB_ENABLE_WEBSOCKETS}") | |
89 | ||
90 | # Server statistics support | |
91 | option(CIVETWEB_ENABLE_SERVER_STATS "Enable server statistics" OFF) | |
92 | message(STATUS "Server statistics support - ${CIVETWEB_ENABLE_SERVER_STATS}") | |
93 | ||
94 | # Memory debugging | |
95 | option(CIVETWEB_ENABLE_MEMORY_DEBUGGING "Enable the memory debugging features" OFF) | |
96 | message(STATUS "Memory Debugging - ${CIVETWEB_ENABLE_MEMORY_DEBUGGING}") | |
97 | ||
98 | # ASAN in debug mode (-fsanitize=address, etc) | |
99 | option(CIVETWEB_ENABLE_ASAN "Enable ASAN in debug mode" ON) | |
100 | message(STATUS "ASAN in debug mode - ${CIVETWEB_ENABLE_ASAN}") | |
101 | ||
102 | # ARCH flag | |
103 | option(CIVETWEB_ARCH "Force 32/64 bit architecture" OFF) | |
104 | message(STATUS "Force x32 / x64 architecture - ${CIVETWEB_ARCH}") | |
105 | ||
106 | # LUA CGI support | |
107 | option(CIVETWEB_ENABLE_LUA "Enable Lua CGIs" OFF) | |
108 | message(STATUS "Lua CGI support - ${CIVETWEB_ENABLE_LUA}") | |
109 | ||
110 | # zlib compression support | |
111 | option(CIVETWEB_ENABLE_ZLIB "Enables zlib compression support" OFF) | |
112 | message(STATUS "zlib support - ${CIVETWEB_ENABLE_ZLIB}") | |
113 | ||
114 | # Enable installing CivetWeb executables | |
115 | option(CIVETWEB_INSTALL_EXECUTABLE "Enable installing CivetWeb executable" ON) | |
116 | mark_as_advanced(FORCE CIVETWEB_INSTALL_EXECUTABLE) # Advanced users can disable | |
117 | message(STATUS "Executable installation - ${CIVETWEB_INSTALL_EXECUTABLE}") | |
118 | ||
119 | # Allow builds to complete with warnings (do not set -Werror) | |
120 | # CivetWeb Linux support is stable: | |
121 | # Builds for GCC 4.6 and clang 3.4 are free from warnings. | |
122 | # However, GCC introduced a couple of new, partially idiotic warnings, | |
123 | # that can not be disabled using a #pragma directive. | |
124 | # It seems unreasonable to have all GCC versions warning free, but only | |
125 | # some selected ones. | |
126 | option(CIVETWEB_ALLOW_WARNINGS "Do not stop build if there are warnings" ON) | |
127 | message(STATUS "Build if there are warnings - ${CIVETWEB_ALLOW_WARNINGS}") | |
128 | ||
129 | if (NOT CIVETWEB_ALLOW_WARNINGS) | |
130 | if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") | |
131 | message(FATAL_ERROR "Cannot compile with warning as errors, until this GCC bug is solved: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53431") | |
132 | endif() | |
133 | endif() | |
134 | ||
135 | # Link to the shared LUA library | |
136 | cmake_dependent_option( | |
137 | CIVETWEB_ENABLE_LUA_SHARED "Link to the shared LUA system library" OFF | |
138 | CIVETWEB_ENABLE_LUA OFF) | |
139 | if (CIVETWEB_ENABLE_LUA) | |
140 | message(STATUS "Linking shared Lua library - ${CIVETWEB_ENABLE_LUA_SHARED}") | |
141 | endif() | |
142 | ||
143 | # Lua Third Party Settings | |
144 | if (CIVETWEB_ENABLE_LUA) | |
145 | if (NOT CIVETWEB_ENABLE_LUA_SHARED) | |
146 | # Lua Version | |
147 | set(CIVETWEB_LUA_VERSION 5.2.4 CACHE STRING | |
148 | "The version of Lua to build and include statically") | |
149 | set_property(CACHE CIVETWEB_LUA_VERSION PROPERTY VALUE ${CIVETWEB_LUA_VERSION}) | |
150 | message(STATUS "Lua Version - ${CIVETWEB_LUA_VERSION}") | |
151 | mark_as_advanced(CIVETWEB_LUA_VERSION) | |
152 | ||
153 | # Lua Verification Hash | |
154 | set(CIVETWEB_LUA_MD5_HASH 913fdb32207046b273fdb17aad70be13 CACHE STRING | |
155 | "The hash of Lua archive to be downloaded") | |
156 | set_property(CACHE CIVETWEB_LUA_MD5_HASH PROPERTY VALUE ${CIVETWEB_LUA_MD5_HASH}) | |
157 | mark_as_advanced(CIVETWEB_LUA_MD5_HASH) | |
158 | endif() | |
159 | ||
160 | # Lua Filesystem Version | |
161 | set(CIVETWEB_LUA_FILESYSTEM_VERSION 1.6.3 CACHE STRING | |
162 | "The version of Lua Filesystem to build and include statically") | |
163 | set_property(CACHE CIVETWEB_LUA_FILESYSTEM_VERSION PROPERTY VALUE ${CIVETWEB_LUA_FILESYSTEM_VERSION}) | |
164 | message(STATUS "Lua Filesystem Version - ${CIVETWEB_LUA_FILESYSTEM_VERSION}") | |
165 | mark_as_advanced(CIVETWEB_LUA_FILESYSTEM_VERSION) | |
166 | ||
167 | # Lua Filesystem Verification Hash | |
168 | set(CIVETWEB_LUA_FILESYSTEM_MD5_HASH d0552c7e5a082f5bb2865af63fb9dc95 CACHE STRING | |
169 | "The hash of Lua Filesystem archive to be downloaded") | |
170 | set_property(CACHE CIVETWEB_LUA_FILESYSTEM_MD5_HASH PROPERTY VALUE ${CIVETWEB_LUA_FILESYSTEM_MD5_HASH}) | |
171 | mark_as_advanced(CIVETWEB_LUA_FILESYSTEM_MD5_HASH) | |
172 | ||
173 | # Lua SQLite Version | |
174 | set(CIVETWEB_LUA_SQLITE_VERSION 0.9.3 CACHE STRING | |
175 | "The version of Lua SQLite to build and include statically") | |
176 | set_property(CACHE CIVETWEB_LUA_SQLITE_VERSION PROPERTY VALUE ${CIVETWEB_LUA_SQLITE_VERSION}) | |
177 | message(STATUS "Lua SQLite Version - ${CIVETWEB_LUA_SQLITE_VERSION}") | |
178 | mark_as_advanced(CIVETWEB_LUA_SQLITE_VERSION) | |
179 | ||
180 | # Lua SQLite Verification Hash | |
181 | set(CIVETWEB_LUA_SQLITE_MD5_HASH 43234ae08197dfce6da02482ed14ec92 CACHE STRING | |
182 | "The hash of Lua SQLite archive to be downloaded") | |
183 | set_property(CACHE CIVETWEB_LUA_SQLITE_MD5_HASH PROPERTY VALUE ${CIVETWEB_LUA_SQLITE_MD5_HASH}) | |
184 | mark_as_advanced(CIVETWEB_LUA_SQLITE_MD5_HASH) | |
185 | ||
186 | # Lua XML Version | |
187 | set(CIVETWEB_LUA_XML_VERSION 1.8.0 CACHE STRING | |
188 | "The version of Lua XML to build and include statically") | |
189 | set_property(CACHE CIVETWEB_LUA_XML_VERSION PROPERTY VALUE ${CIVETWEB_LUA_XML_VERSION}) | |
190 | message(STATUS "Lua XML Version - ${CIVETWEB_LUA_XML_VERSION}") | |
191 | mark_as_advanced(CIVETWEB_LUA_XML_VERSION) | |
192 | ||
193 | # Lua XML Verification Hash | |
194 | set(CIVETWEB_LUA_XML_MD5_HASH 25e4c276c5d8716af1de0c7853aec2b4 CACHE STRING | |
195 | "The hash of Lua XML archive to be downloaded") | |
196 | set_property(CACHE CIVETWEB_LUA_XML_MD5_HASH PROPERTY VALUE ${CIVETWEB_LUA_XML_MD5_HASH}) | |
197 | mark_as_advanced(CIVETWEB_LUA_XML_MD5_HASH) | |
198 | ||
199 | # SQLite Version | |
200 | set(CIVETWEB_SQLITE_VERSION 3.8.9 CACHE STRING | |
201 | "The version of SQLite to build and include statically") | |
202 | set_property(CACHE CIVETWEB_SQLITE_VERSION PROPERTY VALUE ${CIVETWEB_SQLITE_VERSION}) | |
203 | message(STATUS "SQLite Version - ${CIVETWEB_SQLITE_VERSION}") | |
204 | mark_as_advanced(CIVETWEB_SQLITE_VERSION) | |
205 | ||
206 | # SQLite Verification Hash | |
207 | set(CIVETWEB_SQLITE_MD5_HASH 02e9c3a6daa8b8587cf6bef828c2e33f CACHE STRING | |
208 | "The hash of SQLite archive to be downloaded") | |
209 | set_property(CACHE CIVETWEB_SQLITE_MD5_HASH PROPERTY VALUE ${CIVETWEB_SQLITE_MD5_HASH}) | |
210 | mark_as_advanced(CIVETWEB_SQLITE_MD5_HASH) | |
211 | endif() | |
212 | ||
213 | # Duktape CGI support | |
214 | option(CIVETWEB_ENABLE_DUKTAPE "Enable Duktape CGIs" OFF) | |
215 | message(STATUS "Duktape CGI support - ${CIVETWEB_ENABLE_DUKTAPE}") | |
216 | ||
217 | # SSL support | |
218 | option(CIVETWEB_ENABLE_SSL "Enables the secure socket layer" ON) | |
219 | message(STATUS "SSL support - ${CIVETWEB_ENABLE_SSL}") | |
220 | ||
221 | # OpenSSL 1.0 API | |
222 | option(CIVETWEB_SSL_OPENSSL_API_1_0 "Use the OpenSSL 1.0 API" OFF) | |
223 | message(STATUS "Compile for OpenSSL 1.0 API - ${CIVETWEB_SSL_OPENSSL_API_1_0}") | |
224 | ||
225 | # OpenSSL 1.1 API | |
226 | option(CIVETWEB_SSL_OPENSSL_API_1_1 "Use the OpenSSL 1.1 API" ON) | |
227 | message(STATUS "Compile for OpenSSL 1.1 API - ${CIVETWEB_SSL_OPENSSL_API_1_1}") | |
228 | ||
229 | # Dynamically load or link the SSL libraries | |
230 | cmake_dependent_option( | |
231 | CIVETWEB_ENABLE_SSL_DYNAMIC_LOADING "Dynamically loads the SSL library rather than linking it" ON | |
232 | CIVETWEB_ENABLE_SSL OFF) | |
233 | if (CIVETWEB_ENABLE_SSL) | |
234 | message(STATUS "Dynamically load SSL libraries - ${CIVETWEB_ENABLE_SSL_DYNAMIC_LOADING}") | |
235 | endif() | |
236 | ||
237 | # Link time optimization | |
238 | option(CIVETWEB_ENABLE_LTO "Enable link time optimization" OFF) | |
239 | if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR | |
240 | "${BUILD_SHARED_LIBS}" STREQUAL "SHARED" OR | |
241 | ${CMAKE_CXX_COMPILER_VERSION} GREATER 5) | |
242 | option(CIVETWEB_CXX_ENABLE_LTO "Enable link time optimization for the C++ wrapper library" ON) | |
243 | else() | |
244 | option(CIVETWEB_CXX_ENABLE_LTO "Enable link time optimization for the C++ wrapper library" OFF) | |
245 | endif() | |
246 | ||
247 | # Third Party Download location | |
248 | set(CIVETWEB_THIRD_PARTY_DIR "${CMAKE_BINARY_DIR}/third_party" CACHE STRING | |
249 | "The location that third party code is downloaded, built and installed") | |
250 | set_property(CACHE CIVETWEB_THIRD_PARTY_DIR PROPERTY VALUE ${CIVETWEB_THIRD_PARTY_DIR}) | |
251 | ||
252 | # Unix systems can define the dynamic library names to load | |
253 | if (CIVETWEB_ENABLE_SSL_DYNAMIC_LOADING AND NOT DARWIN AND UNIX) | |
254 | # SSL library name | |
255 | set(CIVETWEB_SSL_SSL_LIB "libssl.so" CACHE STRING | |
256 | "The name of the SSL library to load") | |
257 | set_property(CACHE CIVETWEB_SSL_SSL_LIB PROPERTY VALUE ${CIVETWEB_SSL_SSL_LIB}) | |
258 | message(STATUS "SSL Library Name - ${CIVETWEB_SSL_SSL_LIB}") | |
259 | ||
260 | # Crytography library name | |
261 | set(CIVETWEB_SSL_CRYPTO_LIB "libcrypto.so" CACHE STRING | |
262 | "The name of the SSL Cryptography library to load") | |
263 | set_property(CACHE CIVETWEB_SSL_CRYPTO_LIB PROPERTY VALUE ${CIVETWEB_SSL_CRYPTO_LIB}) | |
264 | message(STATUS "SSL Cryptography Library Name - ${CIVETWEB_SSL_CRYPTO_LIB}") | |
265 | endif() | |
266 | ||
267 | # Allow warnings in 3rd party components | |
268 | if (CIVETWEB_ENABLE_LUA OR CIVETWEB_ENABLE_DUKTAPE) | |
269 | SET(CIVETWEB_ALLOW_WARNINGS YES) | |
270 | endif() | |
271 | ||
272 | # The C and C++ standards to use | |
273 | set(CIVETWEB_C_STANDARD auto CACHE STRING | |
274 | "The C standard to use; auto determines the latest supported by the compiler") | |
275 | set_property(CACHE CIVETWEB_C_STANDARD PROPERTY STRINGS auto c11 c99 c89) | |
276 | set(CIVETWEB_CXX_STANDARD auto CACHE STRING | |
277 | "The C++ standard to use; auto determines the latest supported by the compiler") | |
278 | set_property(CACHE CIVETWEB_CXX_STANDARD PROPERTY STRINGS auto c++14 c++11 c++98) | |
279 | ||
280 | # Configure the linker | |
281 | if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") | |
282 | find_program(GCC_AR gcc-ar) | |
283 | if (GCC_AR) | |
284 | set(CMAKE_AR ${GCC_AR}) | |
285 | endif() | |
286 | find_program(GCC_RANLIB gcc-ranlib) | |
287 | if (GCC_RANLIB) | |
288 | set(CMAKE_RANLIB ${GCC_RANLIB}) | |
289 | endif() | |
290 | endif() | |
291 | ||
292 | # Configure the C compiler | |
293 | message(STATUS "Configuring C Compiler") | |
294 | if ("${CIVETWEB_C_STANDARD}" STREQUAL "auto") | |
295 | add_c_compiler_flag(-std=c11) | |
296 | if (NOT HAVE_C_FLAG_STD_C11) | |
297 | add_c_compiler_flag(-std=c99) | |
298 | if (NOT HAVE_C_FLAG_STD_C99) | |
299 | add_c_compiler_flag(-std=c89) | |
300 | endif() | |
301 | endif() | |
302 | else() | |
303 | add_c_compiler_flag(-std=${CIVETWEB_C_STANDARD}) | |
304 | endif() | |
305 | ||
306 | if (MINGW) | |
307 | add_c_compiler_flag(-Wno-format) | |
308 | endif() | |
309 | if (NOT CIVETWEB_ALLOW_WARNINGS) | |
310 | add_c_compiler_flag(-Werror) | |
311 | add_c_compiler_flag(/WX) | |
312 | endif() | |
313 | if (${CIVETWEB_ENABLE_LTO}) | |
314 | add_c_compiler_flag(-flto RELEASE) | |
315 | endif() | |
316 | if (${CIVETWEB_ENABLE_ASAN}) | |
317 | add_c_compiler_flag(-fsanitize=undefined DEBUG) | |
318 | add_c_compiler_flag(-fsanitize=address DEBUG) | |
319 | if (HAVE_C_FLAG_FSANITIZE_ADDRESS) | |
320 | add_c_compiler_flag(-static-asan DEBUG) | |
321 | endif() | |
322 | endif() | |
323 | if (MINGW) | |
324 | add_c_compiler_flag(-mwindows) | |
325 | endif() | |
326 | ||
327 | # Coverage build type | |
328 | set(CMAKE_C_FLAGS_COVERAGE "${CMAKE_C_FLAGS_DEBUG}" CACHE STRING | |
329 | "Flags used by the C compiler during coverage builds." | |
330 | FORCE) | |
331 | set(CMAKE_EXE_LINKER_FLAGS_COVERAGE | |
332 | "${CMAKE_EXE_LINKER_FLAGS_DEBUG}" CACHE STRING | |
333 | "Flags used for linking binaries during coverage builds." | |
334 | FORCE) | |
335 | set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE | |
336 | "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}" CACHE STRING | |
337 | "Flags used by the shared libraries linker during coverage builds." | |
338 | FORCE) | |
339 | mark_as_advanced( | |
340 | CMAKE_CXX_FLAGS_COVERAGE | |
341 | CMAKE_C_FLAGS_COVERAGE | |
342 | CMAKE_EXE_LINKER_FLAGS_COVERAGE | |
343 | CMAKE_SHARED_LINKER_FLAGS_COVERAGE) | |
344 | set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING | |
345 | "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Coverage." | |
346 | FORCE) | |
347 | add_c_compiler_flag(--coverage COVERAGE) | |
348 | ||
349 | # Configure the C++ compiler | |
350 | if (CIVETWEB_ENABLE_CXX) | |
351 | message(STATUS "Configuring C++ Compiler") | |
352 | if ("${CIVETWEB_CXX_STANDARD}" STREQUAL "auto") | |
353 | add_cxx_compiler_flag(-std=c++14) | |
354 | if (NOT HAVE_CXX_FLAG_STD_CXX14) | |
355 | add_cxx_compiler_flag(-std=c++11) | |
356 | if (NOT HAVE_CXX_FLAG_STD_CXX11) | |
357 | add_cxx_compiler_flag(-std=c++98) | |
358 | endif() | |
359 | endif() | |
360 | else() | |
361 | add_cxx_compiler_flag(-std=${CIVETWEB_CXX_STANDARD}) | |
362 | endif() | |
363 | add_cxx_compiler_flag(-Wall) | |
364 | add_cxx_compiler_flag(-Wextra) | |
365 | add_cxx_compiler_flag(-Wshadow) | |
366 | add_cxx_compiler_flag(-Wmissing-prototypes) | |
367 | add_cxx_compiler_flag(-Weverything) | |
368 | add_cxx_compiler_flag(/W4) | |
369 | add_cxx_compiler_flag(-Wno-padded) | |
370 | add_cxx_compiler_flag(/Wd4820) # padding | |
371 | add_cxx_compiler_flag(-Wno-unused-macros) | |
372 | add_cxx_compiler_flag(-Wno-format-nonliteral) | |
373 | if (MINGW) | |
374 | add_cxx_compiler_flag(-Wno-format) | |
375 | endif() | |
376 | if (NOT CIVETWEB_ALLOW_WARNINGS) | |
377 | add_cxx_compiler_flag(-Werror) | |
378 | add_cxx_compiler_flag(/WX) | |
379 | endif() | |
380 | add_cxx_compiler_flag(-pedantic-errors) | |
381 | add_cxx_compiler_flag(-fvisibility=hidden) | |
382 | add_cxx_compiler_flag(-fstack-protector-strong RELEASE) | |
383 | ||
384 | if (${CIVETWEB_CXX_ENABLE_LTO}) | |
385 | add_cxx_compiler_flag(-flto RELEASE) | |
386 | endif() | |
387 | if (${CIVETWEB_ENABLE_ASAN}) | |
388 | add_cxx_compiler_flag(-fsanitize=undefined DEBUG) | |
389 | add_cxx_compiler_flag(-fsanitize=address DEBUG) | |
390 | if (HAVE_CXX_FLAG_FSANITIZE_ADDRESS) | |
391 | add_cxx_compiler_flag(-static-asan DEBUG) | |
392 | endif() | |
393 | endif() | |
394 | add_cxx_compiler_flag(-fstack-protector-all DEBUG) | |
395 | if (MINGW) | |
396 | add_cxx_compiler_flag(-mwindows) | |
397 | endif() | |
398 | set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING | |
399 | "Flags used by the C++ compiler during coverage builds." | |
400 | FORCE) | |
401 | add_cxx_compiler_flag(--coverage COVERAGE) | |
402 | endif() | |
403 | ||
404 | if (NOT ZEPHYR) | |
405 | #Warnings: enable everything | |
406 | add_c_compiler_flag(-Wall) | |
407 | add_c_compiler_flag(-Wextra) | |
408 | add_c_compiler_flag(-Wshadow) | |
409 | add_c_compiler_flag(-Wconversion) | |
410 | add_c_compiler_flag(-Wmissing-prototypes) | |
411 | add_c_compiler_flag(-Weverything) | |
412 | add_c_compiler_flag(-Wparentheses) | |
413 | add_c_compiler_flag(/W4) # VisualStudio highest warning level | |
414 | ||
415 | #Warnings: Disable some warnings | |
416 | add_c_compiler_flag(-Wno-padded) # padding in structures by compiler | |
417 | add_c_compiler_flag(-Wno-unused-macros) # so what? | |
418 | Check_C_Compiler_Flag( HAVE_NO_RESERVED_ID_MACROS -Wno-reserved-id-macros) | |
419 | if (HAVE_NO_RESERVED_ID_MACROS) | |
420 | add_c_compiler_flag(-Wno-reserved-id-macros) # for system headers | |
421 | endif (HAVE_NO_RESERVED_ID_MACROS) | |
422 | add_c_compiler_flag(-Wno-format-nonliteral) # printf(myFormatStringVar, ...) | |
423 | add_c_compiler_flag(-Wno-cast-qual) # const cast | |
424 | add_c_compiler_flag(/Wd4820) # padding | |
425 | ||
426 | add_c_compiler_flag(-pedantic-errors) | |
427 | add_c_compiler_flag(-fvisibility=hidden) | |
428 | add_c_compiler_flag(-fstack-protector-strong RELEASE) | |
429 | add_c_compiler_flag(-fstack-protector-all DEBUG) | |
430 | else() | |
431 | # This policy is needed to override options with variables | |
432 | cmake_policy(SET CMP0077 NEW) | |
433 | ||
434 | # Configure what you need/support in Zephyr | |
435 | set(CIVETWEB_SERVE_NO_FILES ON) | |
436 | set(CIVETWEB_SERVE_NO_FILESYSTEMS ON) | |
437 | set(CIVETWEB_DISABLE_CGI ON) | |
438 | set(CIVETWEB_DISABLE_CACHING ON) | |
439 | set(CIVETWEB_ENABLE_SSL OFF) | |
440 | set(CIVETWEB_ENABLE_SSL_DYNAMIC_LOADING OFF) | |
441 | ||
442 | set(CIVETWEB_ENABLE_LUA OFF) | |
443 | set(CIVETWEB_ENABLE_DUKTAPE OFF) | |
444 | set(CIVETWEB_ENABLE_MEMORY_DEBUGGING OFF) | |
445 | set(CIVETWEB_ENABLE_SERVER_EXECUTABLE OFF) | |
446 | set(CIVETWEB_ENABLE_ASAN OFF) | |
447 | set(CIVETWEB_INSTALL_EXECUTABLE OFF) | |
448 | ||
449 | set(CIVETWEB_THREAD_STACK_SIZE 0) | |
450 | ||
451 | set(BUILD_SHARED_LIBS OFF) | |
452 | ||
453 | add_definitions(-DMG_EXTERNAL_FUNCTION_mg_cry_internal_impl) | |
454 | add_definitions(-DMG_EXTERNAL_FUNCTION_log_access) | |
455 | ||
456 | add_definitions(-DNO_ALTERNATIVE_QUEUE) | |
457 | add_definitions(-DZEPHYR_VERSION=${KERNEL_VERSION_STRING}) | |
458 | ||
459 | zephyr_interface_library_named(CIVETWEB) | |
460 | ||
461 | target_include_directories(CIVETWEB INTERFACE src) | |
462 | target_include_directories(CIVETWEB INTERFACE include) | |
463 | target_include_directories(CIVETWEB INTERFACE ${CMAKE_SOURCE_DIR}/src) | |
464 | ||
465 | zephyr_include_directories(include) | |
466 | ||
467 | zephyr_library() | |
468 | zephyr_library_sources( | |
469 | src/civetweb.c | |
470 | ) | |
471 | ||
472 | zephyr_library_link_libraries(CIVETWEB) | |
473 | target_link_libraries(CIVETWEB INTERFACE zephyr_interface) | |
474 | endif() | |
475 | ||
476 | ||
477 | # Set up the definitions | |
478 | option(CIVETWEB_ENABLE_DEBUG_TOOLS "For Debug builds enable verbose logging and assertions" ON) | |
479 | if (${CMAKE_BUILD_TYPE} MATCHES "[Dd]ebug") | |
480 | if(CIVETWEB_ENABLE_DEBUG_TOOLS) | |
481 | add_definitions(-DDEBUG) | |
482 | endif() | |
483 | add_definitions(-O0) | |
484 | add_definitions(-g) | |
485 | endif() | |
486 | if (CIVETWEB_ENABLE_IPV6) | |
487 | add_definitions(-DUSE_IPV6) | |
488 | endif() | |
489 | if (CIVETWEB_ENABLE_WEBSOCKETS) | |
490 | add_definitions(-DUSE_WEBSOCKET) | |
491 | endif() | |
492 | if (CIVETWEB_ENABLE_SERVER_STATS) | |
493 | add_definitions(-DUSE_SERVER_STATS) | |
494 | endif() | |
495 | if (CIVETWEB_SERVE_NO_FILES) | |
496 | add_definitions(-DNO_FILES) | |
497 | endif() | |
498 | if (CIVETWEB_SERVE_NO_FILESYSTEMS) | |
499 | add_definitions(-DNO_FILESYSTEMS) | |
500 | endif() | |
501 | if (CIVETWEB_DISABLE_CGI) | |
502 | add_definitions(-DNO_CGI) | |
503 | endif() | |
504 | if (CIVETWEB_DISABLE_CACHING) | |
505 | add_definitions(-DNO_CACHING) | |
506 | endif() | |
507 | if (CIVETWEB_ENABLE_LUA) | |
508 | add_definitions(-DUSE_LUA) | |
509 | endif() | |
510 | if (CIVETWEB_ENABLE_ZLIB) | |
511 | add_definitions(-DUSE_ZLIB) | |
512 | endif() | |
513 | if (CIVETWEB_ENABLE_DUKTAPE) | |
514 | add_definitions(-DUSE_DUKTAPE) | |
515 | endif() | |
516 | if (CIVETWEB_ENABLE_MEMORY_DEBUGGING) | |
517 | add_definitions(-DMEMORY_DEBUGGING) | |
518 | endif() | |
519 | if (NOT CIVETWEB_ENABLE_SSL) | |
520 | add_definitions(-DNO_SSL) | |
521 | elseif (NOT CIVETWEB_ENABLE_SSL_DYNAMIC_LOADING) | |
522 | add_definitions(-DNO_SSL_DL) | |
523 | else() | |
524 | if(CIVETWEB_SSL_SSL_LIB) | |
525 | add_definitions(-DSSL_LIB="${CIVETWEB_SSL_SSL_LIB}") | |
526 | endif() | |
527 | if(CIVETWEB_SSL_CRYPTO_LIB) | |
528 | add_definitions(-DCRYPTO_LIB="${CIVETWEB_SSL_CRYPTO_LIB}") | |
529 | endif() | |
530 | endif() | |
531 | ||
532 | if(CIVETWEB_SSL_OPENSSL_API_1_0) | |
533 | add_definitions(-DOPENSSL_API_1_0) | |
534 | endif() | |
535 | if(CIVETWEB_SSL_OPENSSL_API_1_1) | |
536 | add_definitions(-DOPENSSL_API_1_1) | |
537 | endif() | |
538 | if(CIVETWEB_SSL_OPENSSL_API_1_0 AND CIVETWEB_SSL_OPENSSL_API_1_1) | |
539 | message(FATAL_ERROR "Multiple SSL API versions defined") | |
540 | endif() | |
541 | ||
542 | add_definitions(-DUSE_STACK_SIZE=${CIVETWEB_THREAD_STACK_SIZE}) | |
543 | ||
544 | # Set 32 or 64 bit environment | |
545 | if (${CMAKE_ARCH} MATCHES "[Xx]86") | |
546 | add_c_compiler_flag(-m32) | |
547 | endif() | |
548 | if (${CMAKE_ARCH} MATCHES "[Xx]64") | |
549 | add_c_compiler_flag(-m64) | |
550 | endif() | |
551 | # TODO: add support for -march | |
552 | ||
553 | if (ZEPHYR) | |
554 | return() | |
555 | endif() | |
556 | ||
557 | # Build the targets | |
558 | add_subdirectory(src) | |
559 | ||
560 | # Enable the testing of the library/executable | |
561 | include(CTest) | |
562 | if (CIVETWEB_BUILD_TESTING) | |
563 | # Check unit testing framework Version | |
564 | set(CIVETWEB_CHECK_VERSION 0.11.0 CACHE STRING | |
565 | "The version of Check unit testing framework to build and include statically") | |
566 | set_property(CACHE CIVETWEB_CHECK_VERSION PROPERTY VALUE ${CIVETWEB_CHECK_VERSION}) | |
567 | message(STATUS "Check Unit Testing Framework Version - ${CIVETWEB_CHECK_VERSION}") | |
568 | mark_as_advanced(CIVETWEB_CHECK_VERSION) | |
569 | ||
570 | # Check unit testing framework Verification Hash | |
571 | # Hash for Check 0.10.0: 67a34c40b5bc888737f4e5ae82e9939f | |
572 | # Hash for Check 0.11.0: 1b14ee307dca8e954a8219c34484d7c4 | |
573 | set(CIVETWEB_CHECK_MD5_HASH 1b14ee307dca8e954a8219c34484d7c4 CACHE STRING | |
574 | "The hash of Check unit testing framework archive to be downloaded") | |
575 | set_property(CACHE CIVETWEB_CHECK_MD5_HASH PROPERTY VALUE ${CIVETWEB_CHECK_MD5_HASH}) | |
576 | mark_as_advanced(CIVETWEB_CHECK_MD5_HASH) | |
577 | ||
578 | # Build the testing | |
579 | add_subdirectory(unittest) | |
580 | endif() | |
581 | ||
582 | # cmake config file | |
583 | ||
584 | include(CMakePackageConfigHelpers) | |
585 | ||
586 | install( | |
587 | EXPORT ${PROJECT_NAME}-targets | |
588 | NAMESPACE ${PROJECT_NAME}:: | |
589 | FILE ${PROJECT_NAME}-targets.cmake | |
590 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" | |
591 | COMPONENT civetweb-cmake-config | |
592 | ) | |
593 | ||
594 | configure_package_config_file( | |
595 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PROJECT_NAME}-config.cmake.in" | |
596 | ${PROJECT_NAME}-config.cmake | |
597 | INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" | |
598 | NO_CHECK_REQUIRED_COMPONENTS_MACRO | |
599 | PATH_VARS CMAKE_INSTALL_INCLUDEDIR | |
600 | ) | |
601 | ||
602 | write_basic_package_version_file(${PROJECT_NAME}-config-version.cmake | |
603 | VERSION ${CIVETWEB_VERSION} | |
604 | COMPATIBILITY AnyNewerVersion | |
605 | ) | |
606 | ||
607 | install( | |
608 | FILES | |
609 | "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" | |
610 | "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" | |
611 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindLibDl.cmake" | |
612 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindLibRt.cmake" | |
613 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindWinSock.cmake" | |
614 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" | |
615 | COMPONENT civetweb-cmake-config | |
616 | ) | |
617 | ||
618 | # Set up CPack | |
619 | include(InstallRequiredSystemLibraries) | |
620 | set(CPACK_PACKAGE_VENDOR "civetweb Contributors") | |
621 | set(CPACK_PACKAGE_CONTACT "civetweb@users.noreply.github.com") | |
622 | set(CPACK_PACKAGE_VERSION_MAJOR "${CIVETWEB_VERSION_MAJOR}") | |
623 | set(CPACK_PACKAGE_VERSION_MINOR "${CIVETWEB_VERSION_MINOR}") | |
624 | set(CPACK_PACKAGE_VERSION_PATCH "${CIVETWEB_VERSION_PATCH}") | |
625 | set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A HTTP library and server") | |
626 | set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md") | |
627 | set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.md") | |
628 | set(CPACK_STRIP_FILES TRUE) | |
629 | set(CPACK_PACKAGE_DEPENDS "openssl") | |
630 | if (CIVETWEB_ENABLE_LUA_SHARED) | |
631 | set(CPACK_PACKAGE_DEPENDS "lua, ${CPACK_PACKAGE_DEPENDS}") | |
632 | endif() | |
633 | ||
634 | # RPM Packaging | |
635 | set(CPACK_RPM_PACKAGE_GROUP "Development/Libraries") | |
636 | set(CPACK_RPM_PACKAGE_LICENSE "MIT") | |
637 | set(CPACK_RPM_PACKAGE_ARCHITECTURE "${CIVETWEB_ARCHITECTURE}") | |
638 | set(CPACK_RPM_PACKAGE_REQUIRES "${CPACK_PACKAGE_DEPENDS}") | |
639 | ||
640 | # Debian Packaging | |
641 | set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "${CIVETWEB_ARCHITECTURE}") | |
642 | set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/civetweb/civetweb") | |
643 | set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_PACKAGE_DEPENDS}") | |
644 | ||
645 | # WiX Packaging | |
646 | # TODO: www.cmake.org/cmake/help/v3.0/module/CPackWIX.html | |
647 | ||
648 | # Finalize CPack settings | |
649 | include(CPack) | |
650 |