CMakeLists.txt 18 KB

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