CMakeLists.txt 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. # The C API library
  2. add_library(c-library civetweb.c)
  3. set_target_properties(c-library PROPERTIES
  4. OUTPUT_NAME "civetweb"
  5. VERSION ${CIVETWEB_VERSION}
  6. SOVERSION ${CIVETWEB_VERSION}
  7. )
  8. if (BUILD_SHARED_LIBS)
  9. target_compile_definitions(c-library PRIVATE CIVETWEB_DLL_EXPORTS)
  10. endif()
  11. target_include_directories(
  12. c-library PUBLIC
  13. ${PROJECT_SOURCE_DIR}/include)
  14. install(
  15. TARGETS c-library
  16. ARCHIVE DESTINATION lib
  17. LIBRARY DESTINATION lib
  18. RUNTIME DESTINATION bin
  19. COMPONENT c-library)
  20. install(FILES
  21. ${PROJECT_SOURCE_DIR}/include/civetweb.h
  22. DESTINATION include
  23. COMPONENT c-library)
  24. # Need Windows sockets if available
  25. find_package(WinSock)
  26. if (WINSOCK_FOUND)
  27. target_link_libraries(c-library WINSOCK::WINSOCK)
  28. endif()
  29. # We need threading
  30. find_package(Threads)
  31. target_link_libraries(c-library ${CMAKE_THREAD_LIBS_INIT})
  32. # Need the realtime library if we're using timers
  33. find_package(LibRt)
  34. if (CIVETWEB_ENABLE_WEBSOCKETS AND CIVETWEB_ENABLE_LUA AND LIBRT_FOUND)
  35. target_link_libraries(c-library LIBRT::LIBRT)
  36. endif()
  37. # We need to link OpenSSL if not dynamically loading
  38. if (CIVETWEB_ENABLE_SSL)
  39. if (CIVETWEB_ENABLE_SSL_DYNAMIC_LOADING)
  40. find_package(LibDl)
  41. if (LIBDL_FOUND)
  42. target_link_libraries(c-library -ldl)
  43. endif()
  44. else()
  45. find_package(OpenSSL)
  46. target_link_libraries(c-library ${OPENSSL_LIBRARIES})
  47. endif()
  48. endif()
  49. # If Lua support is needed we build some extra Lua libraries
  50. if (CIVETWEB_ENABLE_LUA)
  51. include(ExternalProject)
  52. # Determine if we should print to the output
  53. if (CIVETWEB_ENABLE_THIRD_PARTY_OUTPUT)
  54. set(THIRD_PARTY_LOGGING 0)
  55. else()
  56. set(THIRD_PARTY_LOGGING 1)
  57. endif()
  58. # If Lua is static we must build it from source
  59. if (NOT CIVETWEB_ENABLE_LUA_SHARED)
  60. if (LINUX)
  61. set(LUA_MAKE_TARGET linux)
  62. elseif(DARWIN)
  63. set(LUA_MAKE_TARGET macosx)
  64. elseif(FREEBSD)
  65. set(LUA_MAKE_TARGET freebsd)
  66. elseif(WINDOWS)
  67. set(LUA_MAKE_TARGET mingw)
  68. elseif(UNIX)
  69. set(LUA_MAKE_TARGET posix)
  70. else()
  71. set(LUA_MAKE_TARGET generic)
  72. endif()
  73. set(LUA_BUILD_COMMAND "${CMAKE_MAKE_PROGRAM};${LUA_MAKE_TARGET}")
  74. if (BUILD_SHARED_LIBS)
  75. set(LUA_BUILD_COMMAND "${LUA_BUILD_COMMAND};MYCFLAGS=-fPIC")
  76. endif()
  77. ExternalProject_Add(lua
  78. URL "http://www.lua.org/ftp/lua-${CIVETWEB_LUA_VERSION}.tar.gz"
  79. URL_MD5 ${CIVETWEB_LUA_MD5_HASH}
  80. PREFIX "${CIVETWEB_THIRD_PARTY_DIR}"
  81. CONFIGURE_COMMAND ""
  82. BUILD_COMMAND ${LUA_BUILD_COMMAND}
  83. BUILD_IN_SOURCE 1
  84. INSTALL_COMMAND make install "INSTALL_TOP=<INSTALL_DIR>"
  85. LOG_DOWNLOAD ${THIRD_PARTY_LOGGING}
  86. LOG_UPDATE ${THIRD_PARTY_LOGGING}
  87. LOG_CONFIGURE ${THIRD_PARTY_LOGGING}
  88. LOG_BUILD ${THIRD_PARTY_LOGGING}
  89. LOG_TEST ${THIRD_PARTY_LOGGING}
  90. LOG_INSTALL ${THIRD_PARTY_LOGGING})
  91. ExternalProject_Get_Property(lua INSTALL_DIR)
  92. set(LUA_INSTALL_DIR ${INSTALL_DIR})
  93. unset(INSTALL_DIR)
  94. link_directories("${LUA_INSTALL_DIR}/lib")
  95. include_directories("${LUA_INSTALL_DIR}/include")
  96. set(LUA_LIBRARIES "${LUA_INSTALL_DIR}/lib/liblua.a")
  97. add_dependencies(c-library lua)
  98. else()
  99. find_package(Lua)
  100. endif()
  101. # Lua Filesystem Support
  102. string(REPLACE "." "_" LUA_FILESYSTEM_VERSION_UNDERSCORE ${CIVETWEB_LUA_FILESYSTEM_VERSION})
  103. ExternalProject_Add(luafilesystem
  104. URL "https://github.com/keplerproject/luafilesystem/archive/v_${LUA_FILESYSTEM_VERSION_UNDERSCORE}.tar.gz"
  105. URL_MD5 ${CIVETWEB_LUA_FILESYSTEM_MD5_HASH}
  106. PREFIX "${CIVETWEB_THIRD_PARTY_DIR}"
  107. PATCH_COMMAND ${CMAKE_COMMAND} -E copy
  108. "${CMAKE_CURRENT_SOURCE_DIR}/cmake/luafilesystem/CMakeLists.txt" <SOURCE_DIR>/CMakeLists.txt
  109. CMAKE_ARGS
  110. "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
  111. "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>"
  112. LOG_DOWNLOAD ${THIRD_PARTY_LOGGING}
  113. LOG_UPDATE ${THIRD_PARTY_LOGGING}
  114. LOG_CONFIGURE ${THIRD_PARTY_LOGGING}
  115. LOG_BUILD ${THIRD_PARTY_LOGGING}
  116. LOG_TEST ${THIRD_PARTY_LOGGING}
  117. LOG_INSTALL ${THIRD_PARTY_LOGGING})
  118. ExternalProject_Get_Property(luafilesystem INSTALL_DIR)
  119. set(LUA_FILESYSTEM_INSTALL_DIR ${INSTALL_DIR})
  120. unset(INSTALL_DIR)
  121. link_directories("${LUA_FILESYSTEM_INSTALL_DIR}/lib")
  122. include_directories("${LUA_FILESYSTEM_INSTALL_DIR}/include")
  123. set(LUA_LIBRARIES "${LUA_LIBRARIES};${LUA_FILESYSTEM_INSTALL_DIR}/lib/libluafilesystem.a")
  124. add_dependencies(c-library luafilesystem)
  125. # Lua SQLite Support
  126. if (${CIVETWEB_LUA_SQLITE_VERSION} VERSION_EQUAL "0.9.3")
  127. set(LUA_SQLITE_FILENAME lsqlite3_fsl09w.zip)
  128. elseif (${CIVETWEB_LUA_SQLITE_VERSION} VERSION_EQUAL "0.9.2")
  129. set(LUA_SQLITE_FILENAME lsqlite3_fsl09v.zip)
  130. elseif (${CIVETWEB_LUA_SQLITE_VERSION} VERSION_EQUAL "0.9.1")
  131. set(LUA_SQLITE_FILENAME lsqlite3_fsl09t.zip)
  132. else()
  133. message(FATAL_ERROR "The Lua SQLite archive filename is unknown for version ${CIVETWEB_LUA_SQLITE_VERSION}")
  134. endif()
  135. ExternalProject_Add(luasqlite
  136. URL "http://lua.sqlite.org/index.cgi/zip/${LUA_SQLITE_FILENAME}"
  137. URL_MD5 ${CIVETWEB_LUA_SQLITE_MD5_HASH}
  138. PREFIX "${CIVETWEB_THIRD_PARTY_DIR}"
  139. PATCH_COMMAND ${CMAKE_COMMAND} -E copy
  140. "${CMAKE_CURRENT_SOURCE_DIR}/cmake/luasqlite/CMakeLists.txt" <SOURCE_DIR>/CMakeLists.txt
  141. CMAKE_ARGS
  142. "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
  143. "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>"
  144. LOG_DOWNLOAD ${THIRD_PARTY_LOGGING}
  145. LOG_UPDATE ${THIRD_PARTY_LOGGING}
  146. LOG_CONFIGURE ${THIRD_PARTY_LOGGING}
  147. LOG_BUILD ${THIRD_PARTY_LOGGING}
  148. LOG_TEST ${THIRD_PARTY_LOGGING}
  149. LOG_INSTALL ${THIRD_PARTY_LOGGING})
  150. ExternalProject_Get_Property(luasqlite INSTALL_DIR)
  151. set(LUA_SQLITE_INSTALL_DIR ${INSTALL_DIR})
  152. unset(INSTALL_DIR)
  153. link_directories("${LUA_SQLITE_INSTALL_DIR}/lib")
  154. set(LUA_LIBRARIES "${LUA_LIBRARIES};${LUA_SQLITE_INSTALL_DIR}/lib/libluasqlite.a")
  155. add_dependencies(c-library luasqlite)
  156. # Lua XML Support
  157. if (${CIVETWEB_LUA_XML_VERSION} VERSION_EQUAL "1.8.0")
  158. set(LUA_XML_FILENAME LuaXML_130610.zip)
  159. elseif (${CIVETWEB_LUA_XML_VERSION} VERSION_EQUAL "1.7.4")
  160. set(LUA_XML_FILENAME LuaXML_101012.zip)
  161. else()
  162. message(FATAL_ERROR "The Lua XML archive filename is unknown for version ${CIVETWEB_LUA_XML_VERSION}")
  163. endif()
  164. ExternalProject_Add(luaxml
  165. URL "http://viremo.eludi.net/LuaXML/${LUA_XML_FILENAME}"
  166. URL_MD5 ${CIVETWEB_LUA_XML_MD5_HASH}
  167. PREFIX "${CIVETWEB_THIRD_PARTY_DIR}"
  168. PATCH_COMMAND ${CMAKE_COMMAND} -E copy
  169. "${CMAKE_CURRENT_SOURCE_DIR}/cmake/luaxml/CMakeLists.txt" <SOURCE_DIR>/CMakeLists.txt
  170. CMAKE_ARGS
  171. "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
  172. "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>"
  173. LOG_DOWNLOAD ${THIRD_PARTY_LOGGING}
  174. LOG_UPDATE ${THIRD_PARTY_LOGGING}
  175. LOG_CONFIGURE ${THIRD_PARTY_LOGGING}
  176. LOG_BUILD ${THIRD_PARTY_LOGGING}
  177. LOG_TEST ${THIRD_PARTY_LOGGING}
  178. LOG_INSTALL ${THIRD_PARTY_LOGGING})
  179. ExternalProject_Get_Property(luaxml INSTALL_DIR)
  180. set(LUA_XML_INSTALL_DIR ${INSTALL_DIR})
  181. unset(INSTALL_DIR)
  182. link_directories("${LUA_XML_INSTALL_DIR}/lib")
  183. set(LUA_LIBRARIES "${LUA_LIBRARIES};${LUA_XML_INSTALL_DIR}/lib/libluaxml.a")
  184. add_dependencies(c-library luaxml)
  185. # SQLite Support
  186. string (REGEX MATCHALL "[0-9]+" SQLITE_VERSION_MATCHES ${CIVETWEB_SQLITE_VERSION})
  187. list(GET SQLITE_VERSION_MATCHES 0 SQLITE_VERSION_MAJOR)
  188. list(GET SQLITE_VERSION_MATCHES 1 SQLITE_VERSION_MINOR)
  189. list(GET SQLITE_VERSION_MATCHES 2 SQLITE_VERSION_PATCH)
  190. set(SQLITE_FILE_VERSION ${SQLITE_VERSION_MAJOR}0${SQLITE_VERSION_MINOR}0${SQLITE_VERSION_PATCH}00)
  191. ExternalProject_Add(sqlite
  192. URL "http://www.sqlite.org/2015/sqlite-amalgamation-${SQLITE_FILE_VERSION}.zip"
  193. URL_MD5 ${CIVETWEB_SQLITE_MD5_HASH}
  194. PREFIX "${CIVETWEB_THIRD_PARTY_DIR}"
  195. PATCH_COMMAND ${CMAKE_COMMAND} -E copy
  196. "${CMAKE_CURRENT_SOURCE_DIR}/cmake/sqlite/CMakeLists.txt" <SOURCE_DIR>/CMakeLists.txt
  197. CMAKE_ARGS
  198. "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
  199. "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>"
  200. LOG_DOWNLOAD ${THIRD_PARTY_LOGGING}
  201. LOG_UPDATE ${THIRD_PARTY_LOGGING}
  202. LOG_CONFIGURE ${THIRD_PARTY_LOGGING}
  203. LOG_BUILD ${THIRD_PARTY_LOGGING}
  204. LOG_TEST ${THIRD_PARTY_LOGGING}
  205. LOG_INSTALL ${THIRD_PARTY_LOGGING})
  206. ExternalProject_Get_Property(sqlite INSTALL_DIR)
  207. set(SQLITE_INSTALL_DIR ${INSTALL_DIR})
  208. unset(INSTALL_DIR)
  209. link_directories("${SQLITE_INSTALL_DIR}/lib")
  210. include_directories("${SQLITE_INSTALL_DIR}/include")
  211. set(LUA_LIBRARIES "${LUA_LIBRARIES};${SQLITE_INSTALL_DIR}/lib/libsqlite.a")
  212. add_dependencies(c-library sqlite)
  213. # Link all the Lua libraries
  214. target_link_libraries(c-library ${LUA_LIBRARIES})
  215. endif()
  216. # The web server executable
  217. add_executable(c-executable main.c)
  218. set_target_properties(c-executable PROPERTIES
  219. OUTPUT_NAME "civetweb"
  220. )
  221. install(
  222. TARGETS c-executable
  223. ARCHIVE DESTINATION lib
  224. LIBRARY DESTINATION lib
  225. RUNTIME DESTINATION bin
  226. COMPONENT server)
  227. if (BUILD_SHARED_LIBS)
  228. target_compile_definitions(c-executable PRIVATE CIVETWEB_DLL_IMPORTS)
  229. endif()
  230. target_include_directories(
  231. c-executable PUBLIC
  232. ${PROJECT_SOURCE_DIR}/include)
  233. target_link_libraries(c-executable c-library)
  234. if (LIBRT_FOUND)
  235. target_link_libraries(c-executable LIBRT::LIBRT)
  236. endif()
  237. if (CIVETWEB_ENABLE_LUA)
  238. add_library(lua-library third_party/lfs.c third_party/lsqlite3.c third_party/LuaXML_lib.c third_party/sqlite3.c)
  239. set_target_properties(lua-library PROPERTIES
  240. OUTPUT_NAME "lua-library"
  241. VERSION ${CIVETWEB_VERSION}
  242. SOVERSION ${CIVETWEB_VERSION}
  243. )
  244. target_include_directories(
  245. lua-library PUBLIC
  246. ${PROJECT_SOURCE_DIR}/src/third_party/lua-5.2.4)
  247. install(
  248. TARGETS lua-library
  249. ARCHIVE DESTINATION lib
  250. LIBRARY DESTINATION lib
  251. RUNTIME DESTINATION bin
  252. COMPONENT lua-library)
  253. endif()
  254. # The C++ API library
  255. if (CIVETWEB_ENABLE_CXX)
  256. add_library(civetweb-cpp CivetServer.cpp)
  257. set_target_properties(civetweb-cpp PROPERTIES
  258. OUTPUT_NAME "civetweb-cpp"
  259. VERSION ${CIVETWEB_VERSION}
  260. SOVERSION ${CIVETWEB_VERSION}
  261. )
  262. if (BUILD_SHARED_LIBS)
  263. target_compile_definitions(civetweb-cpp PRIVATE CIVETWEB_DLL_EXPORTS)
  264. endif()
  265. target_include_directories(
  266. civetweb-cpp PUBLIC
  267. ${PROJECT_SOURCE_DIR}/include)
  268. install(
  269. TARGETS civetweb-cpp
  270. ARCHIVE DESTINATION lib
  271. LIBRARY DESTINATION lib
  272. RUNTIME DESTINATION bin
  273. COMPONENT civetweb-cpp)
  274. install(FILES
  275. ${PROJECT_SOURCE_DIR}/include/CivetServer.h
  276. DESTINATION include
  277. COMPONENT civetweb-cpp)
  278. endif()