-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
288 lines (234 loc) · 5.48 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
cmake_minimum_required(VERSION 3.0)
project("webcom-sdk-c"
LANGUAGES C
VERSION 2.0.1
)
# Extra version information appearing after "Major.minor.patch" in the library
# version string.
# set to "false" to disable
# set to "git" to use the current git revision abbbreviated hash
# set to anything else to specify anything else
set(PROJECT_VERSION_EXTRA "false")
if(PROJECT_VERSION_EXTRA)
if(PROJECT_VERSION_EXTRA STREQUAL "git")
execute_process(
COMMAND git rev-parse --short HEAD
WORKING_DIRECTORY "${webcom-sdk-c_SOURCE_DIR}"
OUTPUT_VARIABLE PROJECT_VERSION_EXTRA
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif(PROJECT_VERSION_EXTRA STREQUAL "git")
endif(PROJECT_VERSION_EXTRA)
option(WITH_LIBEV "Enable libev event loop support" ON)
option(WITH_LIBUV "Enable libuv event loop support" OFF)
option(WITH_LIBEVENT "Enable libevent event loop support" OFF)
#### webcom-c library
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
find_package(PkgConfig REQUIRED)
find_package(Readline REQUIRED)
include(FindCURL REQUIRED)
pkg_search_module(WEBSOCKETS REQUIRED libwebsockets)
pkg_search_module(JSONC REQUIRED json-c)
if(${WITH_LIBEV})
find_package(Libev REQUIRED)
list(APPEND WC_LIB_LIST ${LIBEV_LIBRARIES})
list(APPEND WC_SRC_LIST "lib/libev.c")
endif()
if(${WITH_LIBUV})
pkg_search_module(LIBUV REQUIRED libuv)
list(APPEND WC_LIB_LIST ${LIBUV_LIBRARIES})
list(APPEND WC_SRC_LIST "lib/libuv.c")
endif()
if(${WITH_LIBEVENT})
pkg_search_module(LIBEVENT REQUIRED libevent)
list(APPEND WC_LIB_LIST ${LIBEVENT_LIBRARIES})
list(APPEND WC_SRC_LIST "lib/libevent.c")
endif()
link_directories(
${WEBSOCKETS_LIBRARY_DIRS}
${JSONC_LIBRARY_DIRS}
${CURL_LIBRARY_DIRS}
)
include(CheckIncludeFile)
include(CheckSymbolExists)
check_symbol_exists("srand48_r" "stdlib.h" HAVE_RAND48_R)
check_include_file("endian.h" HAVE_ENDIAN_H)
check_include_file("sys/endian.h" HAVE_SYS_ENDIAN_H)
check_include_file("syslog.h" WITH_SYSLOG)
check_include_file("systemd/sd-journal.h" WITH_JOURNALD)
if(${WITH_JOURNALD})
pkg_search_module(SYSTEMD REQUIRED libsystemd)
list(APPEND WC_LIB_LIST ${SYSTEMD_LIBRARIES})
endif()
configure_file(
"${webcom-sdk-c_SOURCE_DIR}/lib/compat.h.in"
"${webcom-sdk-c_SOURCE_DIR}/lib/compat.h")
configure_file(
"${webcom-sdk-c_SOURCE_DIR}/include/webcom-c/webcom-config.h.in"
"${webcom-sdk-c_SOURCE_DIR}/include/webcom-c/webcom-config.h")
#### libwebcom-c.so
add_library(
webcom-c
SHARED
lib/webcom_base.c
lib/log.c
lib/sha1.c
lib/base64.c
lib/hash.c
${WC_SRC_LIST}
lib/collection/ht.c
lib/collection/avl.c
lib/datasync/parser.c
lib/datasync/message.c
lib/datasync/datasync.c
lib/datasync/datasync_utils.c
lib/datasync/request.c
lib/datasync/path.c
lib/datasync/json.c
lib/datasync/listen/listen_registry.c
lib/datasync/cache/treenode.c
lib/datasync/cache/treenode_cache.c
lib/datasync/on/on_api.c
lib/datasync/on/on_registry.c
#lib/datasync/on/on_subscription.c
lib/auth/auth.c
)
target_compile_options(
webcom-c
PRIVATE
-Werror
-Wall
-Wextra
)
target_include_directories(
webcom-c
PRIVATE
${JSONC_INCLUDE_DIRS}
${WEBSOCKETS_INCLUDE_DIRS}
${CURL_INCLUDE_DIRS}
${webcom-sdk-c_SOURCE_DIR}/include
)
target_link_libraries(
webcom-c
${WEBSOCKETS_LIBRARIES}
${JSONC_LIBRARIES}
${CURL_LIBRARIES}
${WC_LIB_LIST}
)
#### install
set(LIBRARY_INSTALL_DIR lib)
set(INCLUDE_INSTALL_DIR include)
set(CONFIG_INSTALL_DIR lib/cmake/webcom-c)
install(
TARGETS
webcom-c
EXPORT
webcom-c-targets
LIBRARY DESTINATION
${LIBRARY_INSTALL_DIR}
)
install(
DIRECTORY
"${webcom-sdk-c_SOURCE_DIR}/include/"
DESTINATION
${INCLUDE_INSTALL_DIR}
FILES_MATCHING PATTERN
"webcom-c/*.h"
)
### CMake library interface export
install(
EXPORT
webcom-c-targets
FILE
webcom-c-targets.cmake
NAMESPACE
webcom-c::
DESTINATION
${CONFIG_INSTALL_DIR}
)
include(CMakePackageConfigHelpers)
configure_package_config_file(
webcom-c-config.cmake.in
webcom-c-config.cmake
INSTALL_DESTINATION
${CONFIG_INSTALL_DIR}
PATH_VARS
CONFIG_INSTALL_DIR
INCLUDE_INSTALL_DIR
)
write_basic_package_version_file(
webcom-c-config-version.cmake
COMPATIBILITY
ExactVersion
)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/webcom-c-config-version.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/webcom-c-config.cmake"
DESTINATION
${CONFIG_INSTALL_DIR}
)
#### code checker
add_custom_target(
cppcheck-lib
COMMAND
cppcheck --enable=warning,performance,portability,style
--std=posix --verbose --quiet --template=gcc
"-I${JSONC_INCLUDE_DIRS}" "-I${webcom-sdk-c_SOURCE_DIR}/include"
lib/
WORKING_DIRECTORY
${webcom-sdk-c_SOURCE_DIR}
)
add_custom_target(
cppcheck-tools
COMMAND
cppcheck --enable=warning,performance,portability,style
--std=posix --verbose --quiet --template=gcc
"-I${JSONC_INCLUDE_DIRS}" "-I${webcom-sdk-c_SOURCE_DIR}/include"
tools/
WORKING_DIRECTORY
${webcom-sdk-c_SOURCE_DIR}
)
#### sub-projects
add_subdirectory(examples)
add_subdirectory(doc)
enable_testing()
add_subdirectory(test)
set_target_properties(webcom-c
PROPERTIES
VERSION
${PROJECT_VERSION}
SOVERSION
${PROJECT_VERSION_MAJOR}
)
#### packaging
include("${webcom-sdk-c_SOURCE_DIR}/pkg/pkg.cmake")
### Tools
## wcsh
add_executable(
wcsh
tools/wcsh.c
tools/wcsh_parse.c
tools/wcsh_program.c
tools/wcsh_vt100.c
tools/fsm.c
)
target_include_directories(
wcsh
PRIVATE
${webcom-sdk-c_SOURCE_DIR}/include
${JSONC_INCLUDE_DIRS}
${READLINE_INCLUDE_DIR}
)
target_link_libraries(
wcsh
webcom-c
${JSONC_LIBRARIES}
${LIBEV}
${READLINE_LIBRARY}
)
install(
TARGETS
wcsh
RUNTIME DESTINATION
bin
)