]> prime8.dev >> repos - ttyd.git/commitdiff
cmake: enhance dependency check
authorShuanglei Tao <tsl0922@gmail.com>
Tue, 27 Sep 2016 15:28:05 +0000 (23:28 +0800)
committerShuanglei Tao <tsl0922@gmail.com>
Tue, 27 Sep 2016 15:28:05 +0000 (23:28 +0800)
CMakeLists.txt
README.md
src/server.h

index 5fc296f085501801860123a00050e70b436e6758..c6fc9b2d01ceb7b7a6e8808ce83d436d6440ef37 100644 (file)
@@ -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)
index d86abc3f48fc91c71e60d89644ef04c51d6f6d47..b5d13e193ecce547ccf740de44533a04a7bd382a 100644 (file)
--- 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
 
 ```
index ae4bad43b5996bf957128e6c6081988f633eb9c4..1acb41b3b9f996407a56d397c663cea32156b94a 100644 (file)
@@ -1,4 +1,8 @@
+#ifdef HAVE_LWS_CONFIG_H
 #include "lws_config.h"
+#endif
+
+#define _GNU_SOURCE
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -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);