CMakeLists.txt 23 KB

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