cmake: enhance dependency check

This commit is contained in:
Shuanglei Tao
2016-09-27 23:28:05 +08:00
parent 17e972f5df
commit 659567dd5f
3 changed files with 25 additions and 13 deletions

View 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)
# libwebsockets 1.x doesn't support cmake
find_package(PkgConfig)
# 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)

View File

@@ -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
```

View 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);