CMakeLists.txt 23 KB

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