CMakeLists.txt 25 KB

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