-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
73 lines (58 loc) · 2.02 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
cmake_minimum_required(VERSION 2.8)
include(CheckCCompilerFlag)
include(CheckCSourceCompiles)
project(tcp-echo C)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
include_directories(src)
set(LIBUV_DEPS_DIR ${CMAKE_BINARY_DIR}/deps/libuv)
configure_file(cmake/in/libuv.in ${LIBUV_DEPS_DIR}/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . WORKING_DIRECTORY ${LIBUV_DEPS_DIR})
execute_process(COMMAND ${CMAKE_COMMAND} --build . WORKING_DIRECTORY ${LIBUV_DEPS_DIR})
include_directories(${LIBUV_DEPS_DIR}/src/include)
find_library(LIBUV_STATIC_LIBRARY NAMES libuv.a libuv PATHS ${LIBUV_DEPS_DIR}/src PATH_SUFFIXES .libs Release NO_DEFAULT_PATH)
set(SDS_DEPS_DIR ${CMAKE_BINARY_DIR}/deps/sds)
configure_file(cmake/in/sds.in ${SDS_DEPS_DIR}/CMakeLists.txt)
configure_file(cmake/in/sdsalloc.h.in ${SDS_DEPS_DIR}/src/sdsalloc.h)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . WORKING_DIRECTORY ${SDS_DEPS_DIR})
execute_process(COMMAND ${CMAKE_COMMAND} --build . WORKING_DIRECTORY ${SDS_DEPS_DIR})
include_directories(${SDS_DEPS_DIR}/src)
add_library(SDS_STATIC_LIBRARY STATIC ${SDS_DEPS_DIR}/src/sds.c)
CHECK_C_SOURCE_COMPILES(
"#include <string.h>
int main() { char x = *strerror_r(0, &x, sizeof(x)); return 0; }"
STRERROR_R_CHAR_P
)
set(CMAKE_C_FLAGS "-std=gnu99")
list(
APPEND
COMPILER_FLAGS
-Wall
-Wextra
-Wunused
-Wunreachable-code
-Wpedantic
-Wno-missing-field-initializers
)
if(DEFINED ENV{CI})
set(CMAKE_BUILD_TYPE Debug)
list(
APPEND
COMPILER_FLAGS
-Werror
-pedantic-errors
)
endif()
if(CMAKE_C_COMPILER_ID MATCHES "GNU|.*Clang")
foreach (COMPILER_FLAG IN LISTS COMPILER_FLAGS)
string(REPLACE "-" "" CLEAN_COMPILER_FLAG ${COMPILER_FLAG})
CHECK_C_COMPILER_FLAG(${COMPILER_FLAG} FLAG_${CLEAN_COMPILER_FLAG})
if(FLAG_${CLEAN_COMPILER_FLAG})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMPILER_FLAG}")
endif()
endforeach()
endif()
add_subdirectory(src)