forked from civetweb/civetweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
630 lines (545 loc) · 22.2 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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
# Determines what CMake APIs we can rely on
cmake_minimum_required (VERSION 2.8.11)
if (${CMAKE_VERSION} VERSION_GREATER 3.2.2)
cmake_policy(VERSION 3.2.2)
endif()
if (${CMAKE_VERSION} VERSION_GREATER 3.1 OR
${CMAKE_VERSION} VERSION_EQUAL 3.1)
cmake_policy(SET CMP0054 NEW)
endif()
# Set up the project
project (civetweb)
# Detect the platform reliably
if(ZEPHYR_BASE)
if (NOT CONFIG_CIVETWEB)
return()
endif()
SET(ZEPHYR YES)
elseif(NOT MACOSX AND ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
SET(DARWIN YES)
elseif(NOT BSD AND ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
SET(FREEBSD YES)
elseif(NOT LINUX AND ${CMAKE_SYSTEM_NAME} MATCHES "Linux")
SET(LINUX YES)
endif()
# Do not allow in source builds
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
# Make sure we can import out CMake functions
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
# Load in the needed CMake modules
include(CheckIncludeFiles)
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
include(AddCCompilerFlag)
include(AddCXXCompilerFlag)
include(DetermineTargetArchitecture)
include(CMakeDependentOption)
set(CIVETWEB_VERSION "1.11.0" CACHE STRING "The version of the civetweb library")
string(REGEX MATCH "([0-9]+)\\.([0-9]+)\\.([0-9]+)" CIVETWEB_VERSION_MATCH "${CIVETWEB_VERSION}")
if ("${CIVETWEB_VERSION_MATCH}" STREQUAL "")
message(FATAL_ERROR "Must specify a semantic version: major.minor.patch")
endif()
set(CIVETWEB_VERSION_MAJOR "${CMAKE_MATCH_1}")
set(CIVETWEB_VERSION_MINOR "${CMAKE_MATCH_2}")
set(CIVETWEB_VERSION_PATCH "${CMAKE_MATCH_3}")
determine_target_architecture(CIVETWEB_ARCHITECTURE)
include(GNUInstallDirs)
# CTest automation
option(CIVETWEB_BUILD_TESTING "Enable automated testing of civetweb" ON)
message(STATUS "Enabling tests in the build - ${CIVETWEB_BUILD_TESTING}")
# C++ wrappers
option(CIVETWEB_ENABLE_THIRD_PARTY_OUTPUT "Shows the output of third party dependency processing" OFF)
# Thread Stack Size
set(CIVETWEB_THREAD_STACK_SIZE 102400 CACHE STRING
"The stack size in bytes for each thread created")
set_property(CACHE CIVETWEB_THREAD_STACK_SIZE PROPERTY VALUE ${CIVETWEB_THREAD_STACK_SIZE})
message(STATUS "Thread Stack Size - ${CIVETWEB_THREAD_STACK_SIZE}")
option(CIVETWEB_ENABLE_SERVER_EXECUTABLE "Enable building of the server executable" ON)
message(STATUS "Enabling server executable - ${CIVETWEB_ENABLE_SERVER_EXECUTABLE}")
# Serve no files from the web server
option(CIVETWEB_SERVE_NO_FILES "Configures the server to serve no static files" OFF)
message(STATUS "Serve no static files - ${CIVETWEB_SERVE_NO_FILES}")
# Serve no files from the web server
option(CIVETWEB_DISABLE_CGI "Disables CGI, so theserver will not execute CGI scripts" OFF)
message(STATUS "Disable CGI support - ${CIVETWEB_DISABLE_CGI}")
# Disable caching
option(CIVETWEB_DISABLE_CACHING "Disables caching, so that no timegm is used." OFF)
message(STATUS "Disable caching support - ${CIVETWEB_DISABLE_CACHING}")
# C++ wrappers
option(CIVETWEB_ENABLE_CXX "Enables the C++ wrapper library" OFF)
message(STATUS "C++ wrappers - ${CIVETWEB_ENABLE_CXX}")
# IP Version 6
option(CIVETWEB_ENABLE_IPV6 "Enables the IP version 6 support" OFF)
message(STATUS "IP Version 6 - ${CIVETWEB_ENABLE_IPV6}")
# Websocket support
option(CIVETWEB_ENABLE_WEBSOCKETS "Enable websockets connections" OFF)
message(STATUS "Websockets support - ${CIVETWEB_ENABLE_WEBSOCKETS}")
# Server statistics support
option(CIVETWEB_ENABLE_SERVER_STATS "Enable server statistics" OFF)
message(STATUS "Server statistics support - ${CIVETWEB_ENABLE_SERVER_STATS}")
# Memory debugging
option(CIVETWEB_ENABLE_MEMORY_DEBUGGING "Enable the memory debugging features" OFF)
message(STATUS "Memory Debugging - ${CIVETWEB_ENABLE_MEMORY_DEBUGGING}")
# ASAN in debug mode (-fsanitize=address, etc)
option(CIVETWEB_ENABLE_ASAN "Enable ASAN in debug mode" ON)
message(STATUS "ASAN in debug mode - ${CIVETWEB_ENABLE_ASAN}")
# ARCH flag
option(CIVETWEB_ARCH "Force 32/64 bit architecture" OFF)
message(STATUS "Force x32 / x64 architecture - ${CIVETWEB_ARCH}")
# LUA CGI support
option(CIVETWEB_ENABLE_LUA "Enable Lua CGIs" OFF)
message(STATUS "Lua CGI support - ${CIVETWEB_ENABLE_LUA}")
# Enable installing CivetWeb executables
option(CIVETWEB_INSTALL_EXECUTABLE "Enable installing CivetWeb executable" ON)
mark_as_advanced(FORCE CIVETWEB_INSTALL_EXECUTABLE) # Advanced users can disable
message(STATUS "Executable installation - ${CIVETWEB_INSTALL_EXECUTABLE}")
# Allow builds to complete with warnings (do not set -Werror)
# CivetWeb Linux support is stable:
# Builds for GCC 4.6 and clang 3.4 are free from warnings.
# However, GCC introduced a couple of new, partially idiotic warnings,
# that can not be disabled using a #pragma directive.
# It seems unreasonable to have all GCC versions warning free, but only
# some selected ones.
option(CIVETWEB_ALLOW_WARNINGS "Do not stop build if there are warnings" ON)
message(STATUS "Build if there are warnings - ${CIVETWEB_ALLOW_WARNINGS}")
if (NOT CIVETWEB_ALLOW_WARNINGS)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
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")
endif()
endif()
# Link to the shared LUA library
cmake_dependent_option(
CIVETWEB_ENABLE_LUA_SHARED "Link to the shared LUA system library" OFF
CIVETWEB_ENABLE_LUA OFF)
if (CIVETWEB_ENABLE_LUA)
message(STATUS "Linking shared Lua library - ${CIVETWEB_ENABLE_LUA_SHARED}")
endif()
# Lua Third Party Settings
if (CIVETWEB_ENABLE_LUA)
if (NOT CIVETWEB_ENABLE_LUA_SHARED)
# Lua Version
set(CIVETWEB_LUA_VERSION 5.2.4 CACHE STRING
"The version of Lua to build and include statically")
set_property(CACHE CIVETWEB_LUA_VERSION PROPERTY VALUE ${CIVETWEB_LUA_VERSION})
message(STATUS "Lua Version - ${CIVETWEB_LUA_VERSION}")
mark_as_advanced(CIVETWEB_LUA_VERSION)
# Lua Verification Hash
set(CIVETWEB_LUA_MD5_HASH 913fdb32207046b273fdb17aad70be13 CACHE STRING
"The hash of Lua archive to be downloaded")
set_property(CACHE CIVETWEB_LUA_MD5_HASH PROPERTY VALUE ${CIVETWEB_LUA_MD5_HASH})
mark_as_advanced(CIVETWEB_LUA_MD5_HASH)
endif()
# Lua Filesystem Version
set(CIVETWEB_LUA_FILESYSTEM_VERSION 1.6.3 CACHE STRING
"The version of Lua Filesystem to build and include statically")
set_property(CACHE CIVETWEB_LUA_FILESYSTEM_VERSION PROPERTY VALUE ${CIVETWEB_LUA_FILESYSTEM_VERSION})
message(STATUS "Lua Filesystem Version - ${CIVETWEB_LUA_FILESYSTEM_VERSION}")
mark_as_advanced(CIVETWEB_LUA_FILESYSTEM_VERSION)
# Lua Filesystem Verification Hash
set(CIVETWEB_LUA_FILESYSTEM_MD5_HASH d0552c7e5a082f5bb2865af63fb9dc95 CACHE STRING
"The hash of Lua Filesystem archive to be downloaded")
set_property(CACHE CIVETWEB_LUA_FILESYSTEM_MD5_HASH PROPERTY VALUE ${CIVETWEB_LUA_FILESYSTEM_MD5_HASH})
mark_as_advanced(CIVETWEB_LUA_FILESYSTEM_MD5_HASH)
# Lua SQLite Version
set(CIVETWEB_LUA_SQLITE_VERSION 0.9.3 CACHE STRING
"The version of Lua SQLite to build and include statically")
set_property(CACHE CIVETWEB_LUA_SQLITE_VERSION PROPERTY VALUE ${CIVETWEB_LUA_SQLITE_VERSION})
message(STATUS "Lua SQLite Version - ${CIVETWEB_LUA_SQLITE_VERSION}")
mark_as_advanced(CIVETWEB_LUA_SQLITE_VERSION)
# Lua SQLite Verification Hash
set(CIVETWEB_LUA_SQLITE_MD5_HASH 43234ae08197dfce6da02482ed14ec92 CACHE STRING
"The hash of Lua SQLite archive to be downloaded")
set_property(CACHE CIVETWEB_LUA_SQLITE_MD5_HASH PROPERTY VALUE ${CIVETWEB_LUA_SQLITE_MD5_HASH})
mark_as_advanced(CIVETWEB_LUA_SQLITE_MD5_HASH)
# Lua XML Version
set(CIVETWEB_LUA_XML_VERSION 1.8.0 CACHE STRING
"The version of Lua XML to build and include statically")
set_property(CACHE CIVETWEB_LUA_XML_VERSION PROPERTY VALUE ${CIVETWEB_LUA_XML_VERSION})
message(STATUS "Lua XML Version - ${CIVETWEB_LUA_XML_VERSION}")
mark_as_advanced(CIVETWEB_LUA_XML_VERSION)
# Lua XML Verification Hash
set(CIVETWEB_LUA_XML_MD5_HASH 25e4c276c5d8716af1de0c7853aec2b4 CACHE STRING
"The hash of Lua XML archive to be downloaded")
set_property(CACHE CIVETWEB_LUA_XML_MD5_HASH PROPERTY VALUE ${CIVETWEB_LUA_XML_MD5_HASH})
mark_as_advanced(CIVETWEB_LUA_XML_MD5_HASH)
# SQLite Version
set(CIVETWEB_SQLITE_VERSION 3.8.9 CACHE STRING
"The version of SQLite to build and include statically")
set_property(CACHE CIVETWEB_SQLITE_VERSION PROPERTY VALUE ${CIVETWEB_SQLITE_VERSION})
message(STATUS "SQLite Version - ${CIVETWEB_SQLITE_VERSION}")
mark_as_advanced(CIVETWEB_SQLITE_VERSION)
# SQLite Verification Hash
set(CIVETWEB_SQLITE_MD5_HASH 02e9c3a6daa8b8587cf6bef828c2e33f CACHE STRING
"The hash of SQLite archive to be downloaded")
set_property(CACHE CIVETWEB_SQLITE_MD5_HASH PROPERTY VALUE ${CIVETWEB_SQLITE_MD5_HASH})
mark_as_advanced(CIVETWEB_SQLITE_MD5_HASH)
endif()
# Duktape CGI support
option(CIVETWEB_ENABLE_DUKTAPE "Enable Duktape CGIs" OFF)
message(STATUS "Duktape CGI support - ${CIVETWEB_ENABLE_DUKTAPE}")
# SSL support
option(CIVETWEB_ENABLE_SSL "Enables the secure socket layer" ON)
message(STATUS "SSL support - ${CIVETWEB_ENABLE_SSL}")
# OpenSSL 1.1 API
option(CIVETWEB_SSL_OPENSSL_API_1_1 "Use the OpenSSL 1.1 API" OFF)
message(STATUS "Compile for OpenSSL 1.1 API - ${CIVETWEB_SSL_OPENSSL_API_1_1}")
# Dynamically load or link the SSL libraries
cmake_dependent_option(
CIVETWEB_ENABLE_SSL_DYNAMIC_LOADING "Dynamically loads the SSL library rather than linking it" ON
CIVETWEB_ENABLE_SSL OFF)
if (CIVETWEB_ENABLE_SSL)
message(STATUS "Dynamically load SSL libraries - ${CIVETWEB_ENABLE_SSL_DYNAMIC_LOADING}")
endif()
# Link time optimization
option(CIVETWEB_ENABLE_LTO "Enable link time optimization" OFF)
if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
"${BUILD_SHARED_LIBS}" STREQUAL "SHARED" OR
${CMAKE_CXX_COMPILER_VERSION} GREATER 5)
option(CIVETWEB_CXX_ENABLE_LTO "Enable link time optimization for the C++ wrapper library" ON)
else()
option(CIVETWEB_CXX_ENABLE_LTO "Enable link time optimization for the C++ wrapper library" OFF)
endif()
# Third Party Download location
set(CIVETWEB_THIRD_PARTY_DIR "${CMAKE_BINARY_DIR}/third_party" CACHE STRING
"The location that third party code is downloaded, built and installed")
set_property(CACHE CIVETWEB_THIRD_PARTY_DIR PROPERTY VALUE ${CIVETWEB_THIRD_PARTY_DIR})
# Unix systems can define the dynamic library names to load
if (CIVETWEB_ENABLE_SSL_DYNAMIC_LOADING AND NOT DARWIN AND UNIX)
# SSL library name
set(CIVETWEB_SSL_SSL_LIB "libssl.so" CACHE STRING
"The name of the SSL library to load")
set_property(CACHE CIVETWEB_SSL_SSL_LIB PROPERTY VALUE ${CIVETWEB_SSL_SSL_LIB})
message(STATUS "SSL Library Name - ${CIVETWEB_SSL_SSL_LIB}")
# Crytography library name
set(CIVETWEB_SSL_CRYPTO_LIB "libcrypto.so" CACHE STRING
"The name of the SSL Cryptography library to load")
set_property(CACHE CIVETWEB_SSL_CRYPTO_LIB PROPERTY VALUE ${CIVETWEB_SSL_CRYPTO_LIB})
message(STATUS "SSL Cryptography Library Name - ${CIVETWEB_SSL_CRYPTO_LIB}")
endif()
# Allow warnings in 3rd party components
if (CIVETWEB_ENABLE_LUA OR CIVETWEB_ENABLE_DUKTAPE)
SET(CIVETWEB_ALLOW_WARNINGS YES)
endif()
# The C and C++ standards to use
set(CIVETWEB_C_STANDARD auto CACHE STRING
"The C standard to use; auto determines the latest supported by the compiler")
set_property(CACHE CIVETWEB_C_STANDARD PROPERTY STRINGS auto c11 c99 c89)
set(CIVETWEB_CXX_STANDARD auto CACHE STRING
"The C++ standard to use; auto determines the latest supported by the compiler")
set_property(CACHE CIVETWEB_CXX_STANDARD PROPERTY STRINGS auto c++14 c++11 c++98)
# Configure the linker
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
find_program(GCC_AR gcc-ar)
if (GCC_AR)
set(CMAKE_AR ${GCC_AR})
endif()
find_program(GCC_RANLIB gcc-ranlib)
if (GCC_RANLIB)
set(CMAKE_RANLIB ${GCC_RANLIB})
endif()
endif()
# Configure the C compiler
message(STATUS "Configuring C Compiler")
if ("${CIVETWEB_C_STANDARD}" STREQUAL "auto")
add_c_compiler_flag(-std=c11)
if (NOT HAVE_C_FLAG_STD_C11)
add_c_compiler_flag(-std=c99)
if (NOT HAVE_C_FLAG_STD_C99)
add_c_compiler_flag(-std=c89)
endif()
endif()
else()
add_c_compiler_flag(-std=${CIVETWEB_C_STANDARD})
endif()
if (MINGW)
add_c_compiler_flag(-Wno-format)
endif()
if (NOT CIVETWEB_ALLOW_WARNINGS)
add_c_compiler_flag(-Werror)
add_c_compiler_flag(/WX)
endif()
if (${CIVETWEB_ENABLE_LTO})
add_c_compiler_flag(-flto RELEASE)
endif()
if (${CIVETWEB_ENABLE_ASAN})
add_c_compiler_flag(-fsanitize=undefined DEBUG)
add_c_compiler_flag(-fsanitize=address DEBUG)
if (HAVE_C_FLAG_FSANITIZE_ADDRESS)
add_c_compiler_flag(-static-asan DEBUG)
endif()
endif()
if (MINGW)
add_c_compiler_flag(-mwindows)
endif()
# Coverage build type
set(CMAKE_C_FLAGS_COVERAGE "${CMAKE_C_FLAGS_DEBUG}" CACHE STRING
"Flags used by the C compiler during coverage builds."
FORCE)
set(CMAKE_EXE_LINKER_FLAGS_COVERAGE
"${CMAKE_EXE_LINKER_FLAGS_DEBUG}" CACHE STRING
"Flags used for linking binaries during coverage builds."
FORCE)
set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG}" CACHE STRING
"Flags used by the shared libraries linker during coverage builds."
FORCE)
mark_as_advanced(
CMAKE_CXX_FLAGS_COVERAGE
CMAKE_C_FLAGS_COVERAGE
CMAKE_EXE_LINKER_FLAGS_COVERAGE
CMAKE_SHARED_LINKER_FLAGS_COVERAGE)
set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Coverage."
FORCE)
add_c_compiler_flag(--coverage COVERAGE)
# Configure the C++ compiler
if (CIVETWEB_ENABLE_CXX)
message(STATUS "Configuring C++ Compiler")
if ("${CIVETWEB_CXX_STANDARD}" STREQUAL "auto")
add_cxx_compiler_flag(-std=c++14)
if (NOT HAVE_CXX_FLAG_STD_CXX14)
add_cxx_compiler_flag(-std=c++11)
if (NOT HAVE_CXX_FLAG_STD_CXX11)
add_cxx_compiler_flag(-std=c++98)
endif()
endif()
else()
add_cxx_compiler_flag(-std=${CIVETWEB_CXX_STANDARD})
endif()
add_cxx_compiler_flag(-Wall)
add_cxx_compiler_flag(-Wextra)
add_cxx_compiler_flag(-Wshadow)
add_cxx_compiler_flag(-Wmissing-prototypes)
add_cxx_compiler_flag(-Weverything)
add_cxx_compiler_flag(/W4)
add_cxx_compiler_flag(-Wno-padded)
add_cxx_compiler_flag(/Wd4820) # padding
add_cxx_compiler_flag(-Wno-unused-macros)
add_cxx_compiler_flag(-Wno-format-nonliteral)
if (MINGW)
add_cxx_compiler_flag(-Wno-format)
endif()
if (NOT CIVETWEB_ALLOW_WARNINGS)
add_cxx_compiler_flag(-Werror)
add_cxx_compiler_flag(/WX)
endif()
add_cxx_compiler_flag(-pedantic-errors)
add_cxx_compiler_flag(-fvisibility=hidden)
add_cxx_compiler_flag(-fstack-protector-strong RELEASE)
if (${CIVETWEB_CXX_ENABLE_LTO})
add_cxx_compiler_flag(-flto RELEASE)
endif()
if (${CIVETWEB_ENABLE_ASAN})
add_cxx_compiler_flag(-fsanitize=undefined DEBUG)
add_cxx_compiler_flag(-fsanitize=address DEBUG)
if (HAVE_CXX_FLAG_FSANITIZE_ADDRESS)
add_cxx_compiler_flag(-static-asan DEBUG)
endif()
endif()
add_cxx_compiler_flag(-fstack-protector-all DEBUG)
if (MINGW)
add_cxx_compiler_flag(-mwindows)
endif()
set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING
"Flags used by the C++ compiler during coverage builds."
FORCE)
add_cxx_compiler_flag(--coverage COVERAGE)
endif()
if (NOT ZEPHYR)
#Warnings: enable everything
add_c_compiler_flag(-Wall)
add_c_compiler_flag(-Wextra)
add_c_compiler_flag(-Wshadow)
add_c_compiler_flag(-Wconversion)
add_c_compiler_flag(-Wmissing-prototypes)
add_c_compiler_flag(-Weverything)
add_c_compiler_flag(-Wparentheses)
add_c_compiler_flag(/W4) # VisualStudio highest warning level
#Warnings: Disable some warnings
add_c_compiler_flag(-Wno-padded) # padding in structures by compiler
add_c_compiler_flag(-Wno-unused-macros) # so what?
Check_C_Compiler_Flag( HAVE_NO_RESERVED_ID_MACROS -Wno-reserved-id-macros)
if (HAVE_NO_RESERVED_ID_MACROS)
add_c_compiler_flag(-Wno-reserved-id-macros) # for system headers
endif (HAVE_NO_RESERVED_ID_MACROS)
add_c_compiler_flag(-Wno-format-nonliteral) # printf(myFormatStringVar, ...)
add_c_compiler_flag(-Wno-cast-qual) # const cast
add_c_compiler_flag(/Wd4820) # padding
add_c_compiler_flag(-pedantic-errors)
add_c_compiler_flag(-fvisibility=hidden)
add_c_compiler_flag(-fstack-protector-strong RELEASE)
add_c_compiler_flag(-fstack-protector-all DEBUG)
else()
# This policy is needed to override options with variables
cmake_policy(SET CMP0077 NEW)
# Configure what you need/support in Zephyr
set(CIVETWEB_SERVE_NO_FILES ON)
set(CIVETWEB_SERVE_NO_FILESYSTEMS ON)
set(CIVETWEB_DISABLE_CGI ON)
set(CIVETWEB_DISABLE_CACHING ON)
set(CIVETWEB_ENABLE_SSL OFF)
set(CIVETWEB_ENABLE_SSL_DYNAMIC_LOADING OFF)
set(CIVETWEB_ENABLE_LUA OFF)
set(CIVETWEB_ENABLE_DUKTAPE OFF)
set(CIVETWEB_ENABLE_MEMORY_DEBUGGING OFF)
set(CIVETWEB_ENABLE_SERVER_EXECUTABLE OFF)
set(CIVETWEB_ENABLE_ASAN OFF)
set(CIVETWEB_INSTALL_EXECUTABLE OFF)
set(CIVETWEB_THREAD_STACK_SIZE 0)
set(BUILD_SHARED_LIBS OFF)
add_definitions(-DMG_EXTERNAL_FUNCTION_mg_cry_internal_impl)
add_definitions(-DMG_EXTERNAL_FUNCTION_log_access)
add_definitions(-DNO_ALTERNATIVE_QUEUE)
add_definitions(-DZEPHYR_VERSION=${KERNEL_VERSION_STRING})
zephyr_interface_library_named(CIVETWEB)
target_include_directories(CIVETWEB INTERFACE src)
target_include_directories(CIVETWEB INTERFACE include)
target_include_directories(CIVETWEB INTERFACE ${CMAKE_SOURCE_DIR}/src)
zephyr_include_directories(include)
zephyr_library()
zephyr_library_sources(
src/civetweb.c
)
zephyr_library_link_libraries(CIVETWEB)
target_link_libraries(CIVETWEB INTERFACE zephyr_interface)
endif()
# Set up the definitions
if (${CMAKE_BUILD_TYPE} MATCHES "[Dd]ebug")
add_definitions(-DDEBUG)
add_definitions(-O0)
add_definitions(-g)
endif()
if (CIVETWEB_ENABLE_IPV6)
add_definitions(-DUSE_IPV6)
endif()
if (CIVETWEB_ENABLE_WEBSOCKETS)
add_definitions(-DUSE_WEBSOCKET)
endif()
if (CIVETWEB_ENABLE_SERVER_STATS)
add_definitions(-DUSE_SERVER_STATS)
endif()
if (CIVETWEB_SERVE_NO_FILES)
add_definitions(-DNO_FILES)
endif()
if (CIVETWEB_SERVE_NO_FILESYSTEMS)
add_definitions(-DNO_FILESYSTEMS)
endif()
if (CIVETWEB_DISABLE_CGI)
add_definitions(-DNO_CGI)
endif()
if (CIVETWEB_DISABLE_CACHING)
add_definitions(-DNO_CACHING)
endif()
if (CIVETWEB_ENABLE_LUA)
add_definitions(-DUSE_LUA)
endif()
if (CIVETWEB_ENABLE_DUKTAPE)
add_definitions(-DUSE_DUKTAPE)
endif()
if (CIVETWEB_ENABLE_MEMORY_DEBUGGING)
add_definitions(-DMEMORY_DEBUGGING)
endif()
if (NOT CIVETWEB_ENABLE_SSL)
add_definitions(-DNO_SSL)
elseif (NOT CIVETWEB_ENABLE_SSL_DYNAMIC_LOADING)
add_definitions(-DNO_SSL_DL)
else()
if(CIVETWEB_SSL_SSL_LIB)
add_definitions(-DSSL_LIB="${CIVETWEB_SSL_SSL_LIB}")
endif()
if(CIVETWEB_SSL_CRYPTO_LIB)
add_definitions(-DCRYPTO_LIB="${CIVETWEB_SSL_CRYPTO_LIB}")
endif()
endif()
if(CIVETWEB_SSL_OPENSSL_API_1_1)
add_definitions(-DOPENSSL_API_1_1)
endif()
add_definitions(-DUSE_STACK_SIZE=${CIVETWEB_THREAD_STACK_SIZE})
# Set 32 or 64 bit environment
if (${CMAKE_ARCH} MATCHES "[Xx]86")
add_c_compiler_flag(-m32)
endif()
if (${CMAKE_ARCH} MATCHES "[Xx]64")
add_c_compiler_flag(-m64)
endif()
# TODO: add support for -march
if (ZEPHYR)
return()
endif()
# Build the targets
add_subdirectory(src)
# Enable the testing of the library/executable
include(CTest)
if (CIVETWEB_BUILD_TESTING)
# Check unit testing framework Version
set(CIVETWEB_CHECK_VERSION 0.11.0 CACHE STRING
"The version of Check unit testing framework to build and include statically")
set_property(CACHE CIVETWEB_CHECK_VERSION PROPERTY VALUE ${CIVETWEB_CHECK_VERSION})
message(STATUS "Check Unit Testing Framework Version - ${CIVETWEB_CHECK_VERSION}")
mark_as_advanced(CIVETWEB_CHECK_VERSION)
# Check unit testing framework Verification Hash
# Hash for Check 0.10.0: 67a34c40b5bc888737f4e5ae82e9939f
# Hash for Check 0.11.0: 1b14ee307dca8e954a8219c34484d7c4
set(CIVETWEB_CHECK_MD5_HASH 1b14ee307dca8e954a8219c34484d7c4 CACHE STRING
"The hash of Check unit testing framework archive to be downloaded")
set_property(CACHE CIVETWEB_CHECK_MD5_HASH PROPERTY VALUE ${CIVETWEB_CHECK_MD5_HASH})
mark_as_advanced(CIVETWEB_CHECK_MD5_HASH)
# Build the testing
add_subdirectory(unittest)
endif()
# cmake config file
include(CMakePackageConfigHelpers)
install(
EXPORT ${PROJECT_NAME}-targets
NAMESPACE ${PROJECT_NAME}::
FILE ${PROJECT_NAME}-targets.cmake
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
COMPONENT civetweb-cmake-config
)
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PROJECT_NAME}-config.cmake.in"
${PROJECT_NAME}-config.cmake
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
NO_CHECK_REQUIRED_COMPONENTS_MACRO
PATH_VARS CMAKE_INSTALL_INCLUDEDIR
)
write_basic_package_version_file(${PROJECT_NAME}-config-version.cmake
VERSION ${CIVETWEB_VERSION}
COMPATIBILITY AnyNewerVersion
)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
COMPONENT civetweb-cmake-config
)
# Set up CPack
include(InstallRequiredSystemLibraries)
set(CPACK_PACKAGE_VENDOR "civetweb Contributors")
set(CPACK_PACKAGE_CONTACT "[email protected]")
set(CPACK_PACKAGE_VERSION_MAJOR "${CIVETWEB_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${CIVETWEB_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${CIVETWEB_VERSION_PATCH}")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A HTTP library and server")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.md")
set(CPACK_STRIP_FILES TRUE)
set(CPACK_PACKAGE_DEPENDS "openssl")
if (CIVETWEB_ENABLE_LUA_SHARED)
set(CPACK_PACKAGE_DEPENDS "lua, ${CPACK_PACKAGE_DEPENDS}")
endif()
# RPM Packaging
set(CPACK_RPM_PACKAGE_GROUP "Development/Libraries")
set(CPACK_RPM_PACKAGE_LICENSE "MIT")
set(CPACK_RPM_PACKAGE_ARCHITECTURE "${CIVETWEB_ARCHITECTURE}")
set(CPACK_RPM_PACKAGE_REQUIRES "${CPACK_PACKAGE_DEPENDS}")
# Debian Packaging
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "${CIVETWEB_ARCHITECTURE}")
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/civetweb/civetweb")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_PACKAGE_DEPENDS}")
# WiX Packaging
# TODO: www.cmake.org/cmake/help/v3.0/module/CPackWIX.html
# Finalize CPack settings
include(CPack)