From 38b96791f68bd3a7d2f0de950788066740f45b6f Mon Sep 17 00:00:00 2001 From: heinrich5991 Date: Wed, 14 Feb 2018 12:55:04 +0100 Subject: [PATCH] Try to find `libwebsockets` on the host system --- CMakeLists.txt | 54 ++++++++++++-------------------------- cmake/FindWebsockets.cmake | 31 ++++++++++++++++++++++ 2 files changed, 48 insertions(+), 37 deletions(-) create mode 100644 cmake/FindWebsockets.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c34517c0..b8c3b859c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -282,6 +282,13 @@ find_package(PythonInterp) find_package(SDL2) find_package(Threads) find_package(Wavpack) +if(WEBSOCKETS) + find_package(Websockets) +else() + set(WEBSOCKETS_LIBRARIES) + set(WEBSOCKETS_INCLUDE_DIRS) +endif() + if(TARGET_OS AND TARGET_OS STREQUAL "mac") find_program(DMG dmg) @@ -338,6 +345,9 @@ show_dependency_status("PythonInterp" PYTHONINTERP) show_dependency_status("SDL2" SDL2) show_dependency_status("Wavpack" WAVPACK) show_dependency_status("Zlib" ZLIB) +if(WEBSOCKETS) + show_dependency_status("Websockets" WEBSOCKETS) +endif() if(NOT(PYTHONINTERP_FOUND)) message(SEND_ERROR "You must install Python to compile DDNet") @@ -347,6 +357,10 @@ if(MYSQL AND NOT(MYSQL_FOUND)) message(SEND_ERROR "You must install MySQL to compile the DDNet server with MySQL support") endif() +if(WEBSOCKETS AND NOT(WEBSOCKETS_FOUND)) + message(SEND_ERROR "You must install libwebsockets to compile the DDNet server with websocket support") +endif() + if(CLIENT AND NOT(CURL_FOUND)) message(SEND_ERROR "You must install Curl to compile the DDNet client") endif() @@ -664,45 +678,10 @@ add_library(md5 EXCLUDE_FROM_ALL OBJECT ${DEP_MD5_SRC}) set(DEP_MD5 $) list(APPEND TARGETS_DEP md5) -if(WEBSOCKETS) - set_glob(DEP_WEBSOCKETS_SRC GLOB src/engine/external/libwebsockets - alloc.c - base64-decode.c - config.h - context.c - extension-deflate-frame.c - extension-deflate-frame.h - extension-deflate-stream.c - extension-deflate-stream.h - extension.c - getifaddrs.h - handshake.c - huftable.h - lextable-strings.h - lextable.h - libwebsockets.c - libwebsockets.h - lws-plat-unix.c - output.c - parsers.c - pollfd.c - private-libwebsockets.h - server-handshake.c - server.c - service.c - sha-1.c - ) - add_library(websockets EXCLUDE_FROM_ALL OBJECT ${DEP_WEBSOCKETS_SRC}) - list(APPEND TARGETS_DEP websockets) - set(DEP_WEBSOCKETS $) -else() - set(DEP_WEBSOCKETS) -endif() - -set(DEPS ${DEP_MD5} ${DEP_WEBSOCKETS} ${ZLIB_DEP}) +set(DEPS ${DEP_MD5} ${ZLIB_DEP}) # Libraries -set(LIBS ${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES} ${PLATFORM_LIBS}) +set(LIBS ${CMAKE_THREAD_LIBS_INIT} ${WEBSOCKETS_LIBRARIES} ${ZLIB_LIBRARIES} ${PLATFORM_LIBS}) # Targets add_library(engine-shared EXCLUDE_FROM_ALL OBJECT ${ENGINE_INTERFACE} ${ENGINE_SHARED} ${ENGINE_GENERATED_SHARED} ${BASE}) @@ -1511,6 +1490,7 @@ foreach(target ${TARGETS_OWN}) target_compile_definitions(${target} PRIVATE GLEW_STATIC) if(WEBSOCKETS) target_compile_definitions(${target} PRIVATE CONF_WEBSOCKETS) + target_include_directories(${target} PRIVATE ${WEBSOCKETS_INCLUDE_DIRS}) endif() if(MYSQL) target_compile_definitions(${target} PRIVATE CONF_SQL) diff --git a/cmake/FindWebsockets.cmake b/cmake/FindWebsockets.cmake new file mode 100644 index 000000000..a3d3ee102 --- /dev/null +++ b/cmake/FindWebsockets.cmake @@ -0,0 +1,31 @@ +if(NOT CMAKE_CROSSCOMPILING) + find_package(PkgConfig QUIET) + pkg_check_modules(PC_WEBSOCKETS libwebsockets) +endif() + +set_extra_dirs_lib(WEBSOCKETS websockets) +find_library(WEBSOCKETS_LIBRARY + NAMES websockets + HINTS ${HINTS_WEBSOCKETS_LIBDIR} ${PC_WEBSOCKETS_LIBDIR} ${PC_WEBSOCKETS_LIBRARY_DIRS} + PATHS ${PATHS_WEBSOCKETS_LIBDIR} + ${CROSSCOMPILING_NO_CMAKE_SYSTEM_PATH} +) +set_extra_dirs_include(WEBSOCKETS websockets "${WEBSOCKETS_LIBRARY}") +find_path(WEBSOCKETS_INCLUDEDIR + NAMES libwebsockets.h + HINTS ${HINTS_WEBSOCKETS_INCLUDEDIR} ${PC_WEBSOCKETS_INCLUDEDIR} ${PC_WEBSOCKETS_INCLUDE_DIRS} + PATHS ${PATHS_WEBSOCKETS_INCLUDEDIR} + ${CROSSCOMPILING_NO_CMAKE_SYSTEM_PATH} +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Websockets DEFAULT_MSG WEBSOCKETS_LIBRARY WEBSOCKETS_INCLUDEDIR) + +mark_as_advanced(WEBSOCKETS_LIBRARY WEBSOCKETS_INCLUDEDIR) + +if(WEBSOCKETS_FOUND) + set(WEBSOCKETS_LIBRARIES ${WEBSOCKETS_LIBRARY}) + set(WEBSOCKETS_INCLUDE_DIRS ${WEBSOCKETS_INCLUDEDIR}) + + is_bundled(WEBSOCKETS_BUNDLED "${WEBSOCKETS_LIBRARY}") +endif()