From 659567dd5fb8565c0daf53af214882acd279012a Mon Sep 17 00:00:00 2001 From: Shuanglei Tao Date: Tue, 27 Sep 2016 23:28:05 +0800 Subject: [PATCH] cmake: enhance dependency check --- CMakeLists.txt | 23 +++++++++++++++++------ README.md | 5 ++++- src/server.h | 10 ++++------ 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5fc296f..c6fc9b2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,16 +1,25 @@ -cmake_minimum_required(VERSION 3.2) -set(CMAKE_C_STANDARD 99) +cmake_minimum_required(VERSION 2.8) + +# enable C99 mode +if (CMAKE_VERSION VERSION_LESS "3.1") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") +else () + set (CMAKE_C_STANDARD 99) +endif() project(ttyd) +set(LIBWEBSOCKETS_MIN_VERSION 1.6) set(SOURCE_FILES src/server.c src/http.c src/protocol.c src/utils.c) find_package(OpenSSL REQUIRED) -find_package(Libwebsockets QUIET) +find_package(Libwebsockets ${LIBWEBSOCKETS_MIN_VERSION} QUIET) + +find_package(PkgConfig) -# libwebsockets 1.x doesn't support cmake +# try to find libwebsockets with pkg-config if (NOT Libwebsockets_DIR) - pkg_check_modules(Libwebsockets REQUIRED libwebsockets) + pkg_check_modules(Libwebsockets REQUIRED libwebsockets>=${LIBWEBSOCKETS_MIN_VERSION}) find_path(LIBWEBSOCKETS_INCLUDE_DIR libwebsockets.h HINTS ${LIBWEBSOCKETS_INCLUDEDIR} ${LIBWEBSOCKETS_INCLUDE_DIRS}) find_library(LIBWEBSOCKETS_LIBRARIES NAMES websockets libwebsockets @@ -20,7 +29,9 @@ if (NOT Libwebsockets_DIR) mark_as_advanced(LIBWEBSOCKETS_INCLUDE_DIR LIBWEBSOCKETS_LIBRARIES) endif() -find_package(PkgConfig) +include(CheckIncludeFile) +check_include_file(lws_config.h HAVE_LWS_CONFIG_H) + pkg_check_modules(PC_JSON-C REQUIRED json-c) find_path(JSON-C_INCLUDE_DIR json.h HINTS ${PC_JSON-C_INCLUDEDIR} ${PC_JSON-C_INCLUDE_DIRS} PATH_SUFFIXES json-c json) diff --git a/README.md b/README.md index d86abc3..b5d13e1 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ brew install ttyd ### For Linux users -Ubuntu as example: +Ubuntu 16.04 as example: ```bash sudo apt-get install cmake g++ pkg-config git vim-common libwebsockets-dev libjson-c-dev libssl-dev @@ -36,6 +36,9 @@ cmake .. make && make install ``` +> **NOTE:** You may need to compile libwebsockets from source for ubuntu versions old than 16.04, +> since they have outdated `libwebsockets-dev` package ([Issue #6](https://github.com/tsl0922/ttyd/issues/6)). + # Usage ``` diff --git a/src/server.h b/src/server.h index ae4bad4..1acb41b 100644 --- a/src/server.h +++ b/src/server.h @@ -1,4 +1,8 @@ +#ifdef HAVE_LWS_CONFIG_H #include "lws_config.h" +#endif + +#define _GNU_SOURCE #include #include @@ -68,12 +72,6 @@ struct tty_server { pthread_mutex_t lock; }; -extern char * -base64_encode(const unsigned char *buffer, size_t length); - -extern int -check_auth(struct lws *wsi); - extern int callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len); -- 2.43.4