CMakeLists.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. #
  2. # libwebsockets - small server side websockets and web server implementation
  3. #
  4. # Copyright (C) 2010 - 2020 Andy Green <[email protected]>
  5. #
  6. # Permission is hereby granted, free of charge, to any person obtaining a copy
  7. # of this software and associated documentation files (the "Software"), to
  8. # deal in the Software without restriction, including without limitation the
  9. # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  10. # sell copies of the Software, and to permit persons to whom the Software is
  11. # furnished to do so, subject to the following conditions:
  12. #
  13. # The above copyright notice and this permission notice shall be included in
  14. # all copies or substantial portions of the Software.
  15. #
  16. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21. # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  22. # IN THE SOFTWARE.
  23. #
  24. include_directories(.)
  25. #macro(add_subdir_include_dirs arg1)
  26. # add_subdirectory(${arg1})
  27. # list(APPEND LWS_LIB_BUILD_INC_PATHS ${_CMAKE_INC_LIST})
  28. #endmacro()
  29. set(LWS_LIB_INCLUDES "")
  30. #
  31. # Plat specific build items
  32. #
  33. if (LWS_PLAT_FREERTOS)
  34. add_subdir_include_dirs(plat/freertos)
  35. if (ESP_PLATFORM)
  36. include_directories($ENV{IDF_PATH}/components/freertos/include
  37. $ENV{IDF_PATH}/components/freertos/xtensa/include
  38. $ENV{IDF_PATH}/components/xtensa/include
  39. $ENV{IDF_PATH}/components/xtensa/esp32/include
  40. $ENV{IDF_PATH}/components/esp_common/include
  41. $ENV{IDF_PATH}/components/esp_timer/include
  42. $ENV{IDF_PATH}/components/soc/include
  43. $ENV{IDF_PATH}/components/soc/src/esp32/include
  44. $ENV{IDF_PATH}/components/lwip/port/esp32/include
  45. $ENV{IDF_PATH}/components/lwip/lwip/src/include
  46. $ENV{IDF_PATH}/components/lwip/port/esp32/include
  47. ${CMAKE_BINARY_DIR}/config
  48. $ENV{IDF_PATH}/components/esp_rom/include
  49. $ENV{IDF_PATH}/components/esp_system/include
  50. $ENV{IDF_PATH}/components/lwip/include/apps/sntp
  51. $ENV{IDF_PATH}/components/soc/soc/esp32/include
  52. $ENV{IDF_PATH}/components/heap/include
  53. $ENV{IDF_PATH}/components/mbedtls/mbedtls/include
  54. $ENV{IDF_PATH}/components/mbedtls/port/include
  55. $ENV{IDF_PATH}/components/esp_wifi/include
  56. $ENV{IDF_PATH}/components/esp_event/include
  57. $ENV{IDF_PATH}/components/esp_netif/include
  58. $ENV{IDF_PATH}/components/esp_eth/include
  59. $ENV{IDF_PATH}/components/driver/include
  60. $ENV{IDF_PATH}/components/soc/soc/include
  61. $ENV{IDF_PATH}/components/tcpip_adapter/include
  62. $ENV{IDF_PATH}/components/lwip/include/apps
  63. $ENV{IDF_PATH}/components/nvs_flash/include
  64. $ENV{IDF_PATH}/components/esp32/include
  65. $ENV{IDF_PATH}/components/spi_flash/include
  66. $ENV{IDF_PATH}/components/mdns/include
  67. $ENV{IDF_PATH}/components/lwip/lwip/src/include/lwip
  68. $ENV{IDF_PATH}/components/lwip/lwip/src/include
  69. $ENV{IDF_PATH}/components/lwip/lwip/src/include/lwip
  70. $ENV{IDF_PATH}/components/newlib/platform_include )
  71. endif()
  72. else()
  73. if (LWS_PLAT_OPTEE)
  74. add_subdir_include_dirs(plat/optee)
  75. else()
  76. if (WIN32)
  77. add_subdir_include_dirs(plat/windows)
  78. else()
  79. add_subdir_include_dirs(plat/unix)
  80. endif()
  81. endif()
  82. endif()
  83. if (LIB_LIST)
  84. set(CMAKE_REQUIRED_LIBRARIES ${LIB_LIST} ${CMAKE_REQUIRED_LIBRARIES})
  85. endif()
  86. if (LWS_WITH_ZLIB)
  87. if (LWS_WITH_BUNDLED_ZLIB)
  88. if (WIN32)
  89. # it's trying to delete internal zlib entry
  90. LIST(REMOVE_AT CMAKE_REQUIRED_LIBRARIES 0 )
  91. endif()
  92. endif()
  93. endif()
  94. # ideally we want to use pipe2()
  95. CHECK_C_SOURCE_COMPILES("#define _GNU_SOURCE\n#include <unistd.h>\nint main(void) {int fd[2];\n return pipe2(fd, 0);\n}\n" LWS_HAVE_PIPE2)
  96. # tcp keepalive needs this on linux to work practically... but it only exists
  97. # after kernel 2.6.37
  98. CHECK_C_SOURCE_COMPILES("#include <netinet/tcp.h>\nint main(void) { return TCP_USER_TIMEOUT; }\n" LWS_HAVE_TCP_USER_TIMEOUT)
  99. if (LWS_WITH_TLS)
  100. add_subdir_include_dirs(tls)
  101. endif()
  102. # Generate the lws_config.h that includes all the private compilation settings.
  103. #configure_file(
  104. # "${PROJECT_SOURCE_DIR}/cmake/lws_config_private.h.in"
  105. # "${PROJECT_BINARY_DIR}/lws_config_private.h")
  106. add_subdir_include_dirs(core)
  107. add_subdir_include_dirs(misc)
  108. add_subdir_include_dirs(system)
  109. if (LWS_WITH_DRIVERS)
  110. add_subdir_include_dirs(drivers)
  111. endif()
  112. if (LWS_WITH_NETWORK)
  113. add_subdir_include_dirs(core-net)
  114. if (LWS_WITH_ABSTRACT)
  115. add_subdir_include_dirs(abstract)
  116. endif()
  117. add_subdir_include_dirs(roles)
  118. endif()
  119. if (LWS_WITH_JOSE)
  120. add_subdir_include_dirs(jose)
  121. endif()
  122. if (LWS_WITH_SECURE_STREAMS)
  123. add_subdir_include_dirs(secure-streams)
  124. endif()
  125. add_subdir_include_dirs(event-libs)
  126. if (LWS_WITH_STATIC)
  127. if (LWS_STATIC_PIC)
  128. set(CMAKE_POSITION_INDEPENDENT_CODE ON)
  129. endif()
  130. # add_library(websockets STATIC ${SOURCES})# ${HDR_PUBLIC})
  131. # set_target_properties(websockets PROPERTIES LINKER_LANGUAGE C)
  132. list(APPEND LWS_LIBRARIES websockets)
  133. # target_include_directories(websockets PRIVATE ${LWS_LIB_BUILD_INC_PATHS})
  134. if (WIN32)
  135. # Windows uses the same .lib ending for static libraries and shared
  136. # library linker files, so rename the static library.
  137. # set_target_properties(websockets
  138. # PROPERTIES
  139. # OUTPUT_NAME websockets_static)
  140. endif()
  141. endif()
  142. if (LWS_WITH_SHARED)
  143. if (NOT RESOURCES)
  144. set(RESOURCES "")
  145. endif()
  146. add_library(websockets_shared SHARED ${SOURCES})# ${RESOURCES} ${HDR_PUBLIC})
  147. set_target_properties(websockets_shared PROPERTIES LINKER_LANGUAGE C)
  148. list(APPEND LWS_LIBRARIES websockets_shared)
  149. target_include_directories(websockets_shared PRIVATE ${LWS_LIB_BUILD_INC_PATHS})
  150. # We want the shared lib to be named "libwebsockets"
  151. # not "libwebsocket_shared".
  152. set_target_properties(websockets_shared
  153. PROPERTIES
  154. OUTPUT_NAME websockets)
  155. if (WIN32)
  156. # Compile as DLL (export function declarations)
  157. set_property(
  158. TARGET websockets_shared
  159. PROPERTY COMPILE_DEFINITIONS
  160. LWS_DLL
  161. LWS_INTERNAL)
  162. endif()
  163. if (APPLE)
  164. set_property(TARGET websockets_shared PROPERTY MACOSX_RPATH YES)
  165. endif()
  166. if (UNIX AND LWS_WITH_PLUGINS_API)
  167. set (CMAKE_POSITION_INDEPENDENT_CODE ON)
  168. if (NOT((${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") OR
  169. (${CMAKE_SYSTEM_NAME} MATCHES "QNX")))
  170. if (LWS_WITH_SHARED)
  171. target_link_libraries(websockets_shared dl)
  172. endif()
  173. endif()
  174. endif()
  175. endif()
  176. #
  177. # expose the library private include dirs to plugins, test apps etc that are
  178. # part of the lib build but different targets
  179. #
  180. #if (LWS_WITH_SHARED)
  181. # get_target_property(LWS_LIB_INCLUDES websockets_shared INCLUDE_DIRECTORIES)
  182. #else()
  183. # get_target_property(LWS_LIB_INCLUDES websockets INCLUDE_DIRECTORIES)
  184. #endif()
  185. # Set the so version of the lib.
  186. # Equivalent to LDFLAGS=-version-info x:x:x
  187. if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR COMPILER_IS_CLANG)
  188. foreach(lib ${LWS_LIBRARIES})
  189. # set_target_properties(${lib}
  190. # PROPERTIES
  191. # SOVERSION ${SOVERSION})
  192. endforeach()
  193. endif()
  194. # Setup the linking for all libs.
  195. foreach (lib ${LWS_LIBRARIES})
  196. # target_link_libraries(${lib} ${LIB_LIST})
  197. endforeach()
  198. #
  199. # These will be available to parent projects including libwebsockets
  200. # using add_subdirectory()
  201. #
  202. set(LIBWEBSOCKETS_LIBRARIES ${LWS_LIBRARIES} CACHE STRING "Libwebsocket libraries")
  203. if (LWS_WITH_STATIC)
  204. set(LIBWEBSOCKETS_LIBRARIES_STATIC websockets CACHE STRING "Libwebsocket static library")
  205. endif()
  206. if (LWS_WITH_SHARED)
  207. set(LIBWEBSOCKETS_LIBRARIES_SHARED websockets_shared CACHE STRING "Libwebsocket shared library")
  208. endif()
  209. # Install libs and headers.
  210. #install(TARGETS ${LWS_LIBRARIES}
  211. # EXPORT LibwebsocketsTargets
  212. # LIBRARY DESTINATION "${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}" COMPONENT core
  213. # ARCHIVE DESTINATION "${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}" COMPONENT core
  214. # RUNTIME DESTINATION "${LWS_INSTALL_BIN_DIR}" COMPONENT core # Windows DLLs
  215. # PUBLIC_HEADER DESTINATION "${LWS_INSTALL_INCLUDE_DIR}" COMPONENT dev)
  216. #set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries" PARENT_SCOPE)
  217. set(CPACK_COMPONENT_DEV_DISPLAY_NAME "Development files" PARENT_SCOPE)
  218. if (UNIX)
  219. # figure out pkfcfg required libs here
  220. set(lws_requires "")
  221. if (LWS_HAVE_LIBCAP)
  222. if (NOT lws_requires STREQUAL "")
  223. set(lws_requires "${lws_requires},libcap")
  224. else()
  225. set(lws_requires "libcap")
  226. endif()
  227. endif()
  228. # Generate and install pkgconfig.
  229. # (This is not indented, because the tabs will be part of the output)
  230. file(WRITE "${PROJECT_BINARY_DIR}/libwebsockets.pc"
  231. "prefix=\"${CMAKE_INSTALL_PREFIX}\"
  232. exec_prefix=\${prefix}
  233. libdir=\${exec_prefix}/lib${LIB_SUFFIX}
  234. includedir=\${prefix}/include
  235. Name: libwebsockets
  236. Description: Websockets server and client library
  237. Version: ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}
  238. Libs: -L\${libdir} -lwebsockets
  239. Cflags: -I\${includedir}
  240. "
  241. )
  242. if (NOT ${lws_requires} STREQUAL "")
  243. file(APPEND "${PROJECT_BINARY_DIR}/libwebsockets.pc" "Requires: ${lws_requires}")
  244. endif()
  245. install(FILES "${PROJECT_BINARY_DIR}/libwebsockets.pc"
  246. DESTINATION lib${LIB_SUFFIX}/pkgconfig)
  247. file(WRITE "${PROJECT_BINARY_DIR}/libwebsockets_static.pc"
  248. "prefix=\"${CMAKE_INSTALL_PREFIX}\"
  249. exec_prefix=\${prefix}
  250. libdir=\${exec_prefix}/lib${LIB_SUFFIX}
  251. includedir=\${prefix}/include
  252. Name: libwebsockets_static
  253. Description: Websockets server and client static library
  254. Version: ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}
  255. Libs: -L\${libdir} -lwebsockets_static
  256. Libs.private:
  257. Cflags: -I\${includedir}
  258. "
  259. )
  260. if (NOT ${lws_requires} STREQUAL "")
  261. file(APPEND "${PROJECT_BINARY_DIR}/libwebsockets_static.pc" "Requires: ${lws_requires}")
  262. endif()
  263. install(FILES "${PROJECT_BINARY_DIR}/libwebsockets_static.pc"
  264. DESTINATION lib${LIB_SUFFIX}/pkgconfig)
  265. endif(UNIX)
  266. # Keep explicit parent scope exports at end
  267. #
  268. export_to_parent_intermediate()
  269. if (DEFINED LWS_PLAT_UNIX)
  270. set(LWS_PLAT_UNIX ${LWS_PLAT_UNIX} PARENT_SCOPE)
  271. if (ILLUMOS)
  272. add_definitions("-D__illumos__")
  273. endif()
  274. endif()
  275. set(LWS_HAVE_MBEDTLS_NET_SOCKETS ${LWS_HAVE_MBEDTLS_NET_SOCKETS} PARENT_SCOPE)
  276. set(TEST_SERVER_SSL_KEY "${TEST_SERVER_SSL_KEY}" PARENT_SCOPE)
  277. set(TEST_SERVER_SSL_CERT "${TEST_SERVER_SSL_CERT}" PARENT_SCOPE)
  278. set(TEST_SERVER_DATA ${TEST_SERVER_DATA} PARENT_SCOPE)
  279. set(LWS_HAVE_PIPE2 ${LWS_HAVE_PIPE2} PARENT_SCOPE)
  280. set(LWS_LIBRARIES ${LWS_LIBRARIES} PARENT_SCOPE)
  281. if (DEFINED WIN32_HELPERS_PATH)
  282. set(WIN32_HELPERS_PATH ${WIN32_HELPERS_PATH} PARENT_SCOPE)
  283. endif()
  284. if (DEFINED HDR_PRIVATE)
  285. set(HDR_PRIVATE ${HDR_PRIVATE} PARENT_SCOPE)
  286. endif()
  287. if (DEFINED ZLIB_FOUND)
  288. set(ZLIB_FOUND ${ZLIB_FOUND} PARENT_SCOPE)
  289. endif()
  290. if (DEFINED LIB_LIST_AT_END)
  291. set(LIB_LIST_AT_END ${LIB_LIST_AT_END} PARENT_SCOPE)
  292. endif()
  293. set(USE_WOLFSSL ${USE_WOLFSSL} PARENT_SCOPE)
  294. set(LWS_DEPS_LIB_PATHS ${LWS_DEPS_LIB_PATHS} PARENT_SCOPE)