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