CMakeLists.txt 19 KB

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