CMakeLists.txt 24 KB

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