CMakeLists.txt 25 KB

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