-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
117 lines (96 loc) · 3.29 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
PROJECT(futures_cpp)
MACRO(FUTURES_CPP_ENABLE_CXX14)
if(NOT MSVC)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
endif()
ENDMACRO()
FUTURES_CPP_ENABLE_CXX14()
OPTION(ENABLE_EXAMPLES "build examples" OFF)
OPTION(ENABLE_UNITTEST "build unit tests" OFF)
OPTION(ENABLE_STATIC_DEPS "disable static dependencies" ON)
OPTION(ENABLE_MOD_REDIS "build redis module" ON)
OPTION(ENABLE_MOD_READLINE "build readline module" ON)
OPTION(ENABLE_MOD_ZOOKEEPER "build zookeeper module" ON)
OPTION(ENABLE_MOD_MYSQL "build mysql module" ON)
# find libs
if (ENABLE_STATIC_DEPS)
set(BOOST_USE_STATIC_LIBS ON)
endif ()
find_package(Boost 1.50 REQUIRED)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
if (ENABLE_STATIC_DEPS)
set(OPENSSL_USE_STATIC_LIBS ON)
endif()
find_package(OpenSSL REQUIRED)
INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
ADD_SUBDIRECTORY(${futures_cpp_SOURCE_DIR}/deps/libev)
find_package(ZLIB)
if (ZLIB_FOUND)
INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIRS})
ADD_DEFINITIONS(-DCONFIG_FUTURES_CPP_ZLIB)
endif ()
INCLUDE_DIRECTORIES(${futures_cpp_SOURCE_DIR}/include)
INCLUDE_DIRECTORIES(${futures_cpp_SOURCE_DIR}/deps/libev/include)
SET(FUTURES_CPP_ROOT ${futures_cpp_SOURCE_DIR})
AUX_SOURCE_DIRECTORY(src CORE_SRC)
AUX_SOURCE_DIRECTORY(src/folly FOLLY_LITE_SRC)
AUX_SOURCE_DIRECTORY(src/http HTTP_SRC)
ADD_SUBDIRECTORY(src/udns)
SET(ALL_SRC ${CORE_SRC} ${HTTP_SRC} ${FOLLY_LITE_SRC})
if (UNIX)
SET(LIBAE_SRC src/libae/anet.c)
endif()
SET(ALL_SRC ${ALL_SRC} ${LIBAE_SRC})
ADD_LIBRARY(futures_cpp STATIC ${ALL_SRC})
TARGET_LINK_LIBRARIES(futures_cpp udns ev ${ZLIB_LIBRARIES} ${OPENSSL_LIBRARIES}
${Boost_LIBRARIES} pthread dl)
if (ENABLE_ZLIB)
TARGET_LINK_LIBRARIES(futures_cpp zlibstatic)
endif ()
INSTALL(TARGETS futures_cpp
ARCHIVE DESTINATION lib
)
INSTALL(DIRECTORY ${futures_cpp_SOURCE_DIR}/include/futures DESTINATION
include)
MACRO(FUTURES_CPP_BUILD_EXAMPLE name)
ADD_EXECUTABLE(${name} ${ARGN})
TARGET_LINK_LIBRARIES(${name} futures_cpp)
INSTALL(TARGETS ${name} DESTINATION bin)
ENDMACRO()
# Modules
if (ENABLE_MOD_REDIS)
ADD_SUBDIRECTORY(${futures_cpp_SOURCE_DIR}/modules/futures_redis)
endif ()
if (ENABLE_MOD_READLINE)
ADD_SUBDIRECTORY(${futures_cpp_SOURCE_DIR}/modules/futures_readline)
endif ()
if (ENABLE_MOD_ZOOKEEPER)
ADD_SUBDIRECTORY(${futures_cpp_SOURCE_DIR}/modules/futures_zookeeper)
endif ()
if (ENABLE_MOD_MYSQL)
ADD_SUBDIRECTORY(${futures_cpp_SOURCE_DIR}/modules/futures_mysql)
endif ()
if (ENABLE_EXAMPLES)
FUTURES_CPP_BUILD_EXAMPLE(ex_fake_http examples/fake_http.cpp)
FUTURES_CPP_BUILD_EXAMPLE(ex_client_test examples/client_test.cpp)
FUTURES_CPP_BUILD_EXAMPLE(ex_connect_proxy examples/connect_proxy.cpp)
FUTURES_CPP_BUILD_EXAMPLE(ex_console examples/console.cpp)
FUTURES_CPP_BUILD_EXAMPLE(ex_ws_server examples/ws_server.cpp)
FUTURES_CPP_BUILD_EXAMPLE(ex_echo examples/echo.cpp)
endif()
if (ENABLE_TEST)
ADD_SUBDIRECTORY(${futures_cpp_SOURCE_DIR}/deps/gtest)
endif ()
MACRO(FUTURES_CPP_UNITTEST name)
if (ENABLE_TEST)
INCLUDE_DIRECTORIES(${futures_cpp_SOURCE_DIR}/deps/gtest/include)
FILE(GLOB_RECURSE unittest_SRC
"test/*.cc"
"test/*.cpp"
)
ADD_EXECUTABLE(${name}_test ${unittest_SRC})
TARGET_LINK_LIBRARIES(${name}_test futures_cpp gtest)
endif()
ENDMACRO()
FUTURES_CPP_UNITTEST(futures_cpp)