/
CMakeLists.txt
354 lines (320 loc) · 11.1 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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
#
# Set compile flags for entire src/ directory
#
enable_tnt_compile_flags()
include_directories(${LIBEV_INCLUDE_DIR})
include_directories(${LIBEIO_INCLUDE_DIR})
include_directories(${LIBCORO_INCLUDE_DIR})
include_directories(${LUAJIT_INCLUDE_DIRS})
include_directories(${READLINE_INCLUDE_DIRS})
include_directories(${LIBYAML_INCLUDE_DIRS})
include_directories(${MSGPUCK_INCLUDE_DIRS})
include_directories(${CURL_INCLUDE_DIRS})
include_directories(${ICU_INCLUDE_DIRS})
include_directories(${ICONV_INCLUDE_DIRS})
set(LIBUTIL_FREEBSD_SRC ${CMAKE_SOURCE_DIR}/third_party/libutil_freebsd)
include_directories(${LIBUTIL_FREEBSD_SRC})
# Compile src/lua/*.lua files into src/lua/*.lua.c sources
set(lua_sources)
lua_source(lua_sources lua/init.lua)
lua_source(lua_sources lua/string.lua)
lua_source(lua_sources lua/fiber.lua)
lua_source(lua_sources lua/buffer.lua)
lua_source(lua_sources lua/uuid.lua)
lua_source(lua_sources lua/crypto.lua)
lua_source(lua_sources lua/error.lua)
lua_source(lua_sources lua/digest.lua)
lua_source(lua_sources lua/msgpackffi.lua)
lua_source(lua_sources lua/uri.lua)
lua_source(lua_sources lua/socket.lua)
lua_source(lua_sources lua/errno.lua)
lua_source(lua_sources lua/log.lua)
lua_source(lua_sources lua/help.lua)
lua_source(lua_sources lua/help_en_US.lua)
lua_source(lua_sources lua/tap.lua)
lua_source(lua_sources lua/fio.lua)
lua_source(lua_sources lua/csv.lua)
lua_source(lua_sources lua/strict.lua)
lua_source(lua_sources lua/clock.lua)
lua_source(lua_sources lua/title.lua)
lua_source(lua_sources lua/argparse.lua)
lua_source(lua_sources lua/env.lua)
lua_source(lua_sources lua/pwd.lua)
lua_source(lua_sources lua/trigger.lua)
lua_source(lua_sources lua/table.lua)
lua_source(lua_sources ../third_party/luafun/fun.lua)
lua_source(lua_sources lua/httpc.lua)
lua_source(lua_sources lua/iconv.lua)
# LuaJIT jit.* library
lua_source(lua_sources "${CMAKE_BINARY_DIR}/third_party/luajit/src/jit/bc.lua")
lua_source(lua_sources "${CMAKE_BINARY_DIR}/third_party/luajit/src/jit/bcsave.lua")
lua_source(lua_sources "${CMAKE_BINARY_DIR}/third_party/luajit/src/jit/dis_x86.lua")
lua_source(lua_sources "${CMAKE_BINARY_DIR}/third_party/luajit/src/jit/dis_x64.lua")
lua_source(lua_sources "${CMAKE_BINARY_DIR}/third_party/luajit/src/jit/dump.lua")
lua_source(lua_sources "${CMAKE_BINARY_DIR}/third_party/luajit/src/jit/vmdef.lua")
lua_source(lua_sources "${CMAKE_BINARY_DIR}/third_party/luajit/src/jit/v.lua")
lua_source(lua_sources "${CMAKE_BINARY_DIR}/third_party/luajit/src/jit/p.lua")
lua_source(lua_sources "${CMAKE_BINARY_DIR}/third_party/luajit/src/jit/zone.lua")
add_custom_target(generate_lua_sources
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/src/box
DEPENDS ${lua_sources})
set_property(DIRECTORY PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${lua_sources})
add_custom_target(ragel
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND ragel -G2 src/uri.rl -o src/uri.c)
# There is no libdl.so on FreeBSD prior to 11.2.
#
# Always links pthread and dl dynamically.
set(generic_libraries pthread)
find_library(DL_LIBRARY NAMES dl)
if(NOT "${DL_LIBRARY}" STREQUAL "DL_LIBRARY-NOTFOUND")
set(generic_libraries ${generic_libraries} dl)
endif()
set (core_sources
diag.c
say.c
memory.c
clock.c
fiber.c
backtrace.cc
cbus.c
fiber_pool.c
fiber_cond.c
fiber_channel.c
latch.c
sio.cc
evio.cc
coio.cc
coio_task.c
coio_file.c
coio_buf.cc
fio.c
cbus.c
exception.cc
errinj.c
reflection.c
assoc.c
util.c
random.c
trigger.cc
http_parser.c
coll.c
coll_def.c
mpstream.c
port.c
)
if (TARGET_OS_NETBSD)
# A workaround for "undefined reference to `__gcc_personality_v0'"
# on x86_64-rumprun-netbsd-gcc
set_source_files_properties(util.c PROPERTIES COMPILE_FLAGS
-fno-exceptions)
endif ()
add_library(core STATIC ${core_sources})
target_link_libraries(core
salad small
${LIBEV_LIBRARIES}
${LIBEIO_LIBRARIES}
${LIBCORO_LIBRARIES}
${MSGPUCK_LIBRARIES}
${generic_libraries})
add_library(stat STATIC rmean.c latency.c histogram.c)
target_link_libraries(stat core)
if (ENABLE_BACKTRACE AND NOT TARGET_OS_DARWIN)
target_link_libraries(core gcc_s ${UNWIND_LIBRARIES})
endif()
if (CC_HAS_WNO_IMPLICIT_FALLTHROUGH)
# Suppress noise warnings for autogenerated Ragel code
set_source_files_properties(uri.c PROPERTIES COMPILE_FLAGS
-Wno-implicit-fallthrough)
endif()
add_library(uri STATIC uri.c)
add_library(uuid STATIC tt_uuid.c)
target_link_libraries(uuid core bit)
add_library(scramble STATIC scramble.c)
target_link_libraries(scramble core misc)
add_library(crc32 STATIC
crc32.c
cpu_feature.c
${PROJECT_SOURCE_DIR}/third_party/crc32.c
)
set (server_sources
find_path.c
curl.c
httpc.c
pickle.c
cfg.c
cpu_feature.c
title.c
proc_title.c
path_lock.c
systemd.c
version.c
lua/digest.c
lua/init.c
lua/fiber.c
lua/fiber_cond.c
lua/fiber_channel.c
lua/trigger.c
lua/msgpack.c
lua/utils.c
lua/errno.c
lua/tnt_iconv.c
lua/error.c
lua/socket.c
lua/pickle.c
lua/fio.c
lua/crypto.c
lua/httpc.c
lua/utf8.c
lua/luastream.c
${lua_sources}
${PROJECT_SOURCE_DIR}/third_party/lua-yaml/lyaml.cc
${PROJECT_SOURCE_DIR}/third_party/lua-yaml/b64.c
${PROJECT_SOURCE_DIR}/third_party/lua-cjson/lua_cjson.c
${PROJECT_SOURCE_DIR}/third_party/lua-cjson/strbuf.c
)
set(api_headers
${CMAKE_BINARY_DIR}/src/trivia/config.h
${CMAKE_SOURCE_DIR}/src/trivia/util.h
${CMAKE_SOURCE_DIR}/src/say.h
${CMAKE_SOURCE_DIR}/src/fiber.h
${CMAKE_SOURCE_DIR}/src/fiber_cond.h
${CMAKE_SOURCE_DIR}/src/coio.h
${CMAKE_SOURCE_DIR}/src/coio_task.h
${CMAKE_SOURCE_DIR}/src/lua/utils.h
${CMAKE_SOURCE_DIR}/src/lua/error.h
${CMAKE_SOURCE_DIR}/src/box/txn.h
${CMAKE_SOURCE_DIR}/src/box/key_def.h
${CMAKE_SOURCE_DIR}/src/box/field_def.h
${CMAKE_SOURCE_DIR}/src/box/tuple.h
${CMAKE_SOURCE_DIR}/src/box/tuple_format.h
${CMAKE_SOURCE_DIR}/src/box/tuple_extract_key.h
${CMAKE_SOURCE_DIR}/src/box/schema_def.h
${CMAKE_SOURCE_DIR}/src/box/box.h
${CMAKE_SOURCE_DIR}/src/box/index.h
${CMAKE_SOURCE_DIR}/src/box/iterator_type.h
${CMAKE_SOURCE_DIR}/src/box/error.h
${CMAKE_SOURCE_DIR}/src/box/lua/call.h
${CMAKE_SOURCE_DIR}/src/box/lua/tuple.h
${CMAKE_SOURCE_DIR}/src/latch.h
${CMAKE_SOURCE_DIR}/src/clock.h
)
rebuild_module_api(${api_headers})
if (NOT TARGET_OS_DEBIAN_FREEBSD)
if (TARGET_OS_FREEBSD)
set_source_files_properties(
${PROJECT_SOURCE_DIR}/src/proc_title.c
PROPERTIES COMPILE_FLAGS "-DHAVE_SETPROCTITLE")
endif()
endif()
set_source_files_compile_flags(${server_sources})
add_library(server STATIC ${server_sources})
target_link_libraries(server core bit uri uuid ${ICU_LIBRARIES})
# Rule of thumb: if exporting a symbol from a static library, list the
# library here.
set (reexport_libraries server core misc bitset csv
${LUAJIT_LIBRARIES} ${MSGPUCK_LIBRARIES} ${ICU_LIBRARIES})
set (common_libraries
${reexport_libraries}
${LIBYAML_LIBRARIES}
${READLINE_LIBRARIES}
${CURL_LIBRARIES}
${ICONV_LIBRARIES}
${OPENSSL_LIBRARIES}
)
if (TARGET_OS_LINUX OR TARGET_OS_DEBIAN_FREEBSD)
set (common_libraries ${common_libraries} dl rt)
endif()
if (TARGET_OS_FREEBSD AND NOT TARGET_OS_DEBIAN_FREEBSD)
find_library (INTL intl)
if (NOT INTL)
message(FATAL_ERROR "intl library not found")
else()
set (common_libraries ${common_libraries} ${INTL})
endif()
endif()
set (common_libraries ${common_libraries} ${LIBUUID_LIBRARIES})
set (common_libraries ${common_libraries} PARENT_SCOPE)
add_subdirectory(lib)
add_subdirectory(box)
# Save CMAKE_XXX_FLAGS from this directory for config.h (used in --version)
set(TARANTOOL_C_FLAGS ${CMAKE_C_FLAGS} PARENT_SCOPE)
set(TARANTOOL_CXX_FLAGS ${CMAKE_CXX_FLAGS} PARENT_SCOPE)
set(EXPORT_LIST)
if(BUILD_STATIC)
# for each static library we should find a corresponding shared library to
# parse and reexport library api functions
foreach(libstatic
${READLINE_LIBRARIES}
${CURL_LIBRARIES}
${OPENSSL_LIBRARIES}
${ICU_LIBRARIES})
if (${libstatic} MATCHES "lib[^/]+.a")
string(REGEX MATCH "lib[^/]+.a" libname ${libstatic})
string(REGEX REPLACE "\\.a$" "" libname ${libname})
string(REGEX REPLACE "^lib" "" libname ${libname})
find_library(SYMBOLS_LIB NAMES ${libname})
# add found library to export list
list(APPEND EXPORT_LIST ${SYMBOLS_LIB})
# set variable to allow rescan (CMake depended)
set(SYMBOLS_LIB "SYMBOLS_LIB-NOTFOUND")
else()
message(WARNING "${libstatic} should be a static")
endif()
endforeach(libstatic)
string(REPLACE ";" " " EXPORT_LIST "${EXPORT_LIST}")
if (HAVE_OPENMP)
# Link libgomp explicitly to make it static. Avoid linking
# against DSO version of libgomp, which implied by -fopenmp
set (common_libraries ${common_libraries} "libgomp.a")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-openmp")
endif()
endif()
# Exports syntax is toolchain-dependent, preprocessing is necessary
set(exports_file ${CMAKE_BINARY_DIR}/extra/exports.${CMAKE_SYSTEM_NAME})
add_custom_target(preprocess_exports
DEPENDS ${exports_file})
add_custom_command(
OUTPUT ${exports_file}
DEPENDS ${CMAKE_SOURCE_DIR}/extra/exports
COMMAND ${CMAKE_SOURCE_DIR}/extra/mkexports
${CMAKE_SOURCE_DIR}/extra/exports
${exports_file} ${CMAKE_SYSTEM_NAME}
${EXPORT_LIST}
)
add_executable(
tarantool main.cc
${LIBUTIL_FREEBSD_SRC}/flopen.c
${LIBUTIL_FREEBSD_SRC}/pidfile.c)
add_dependencies(tarantool build_bundled_libs preprocess_exports sql)
# Re-link if exports changed
set_target_properties(tarantool PROPERTIES LINK_DEPENDS ${exports_file})
# A note about linkers:
# [GNU linker] When linking an *executable* visibility is ignored, and
# either nothing is exported (default), or any non-static
# symbol is exported (-rdynamic), or explicitly listed
# symbols are exported (--dynamic-list).
#
# However, if a symbol listed lives in a static library it
# won't be automatically pulled, hence --whole-archive
# option.
#
# [Apple linker] One can provide an explicit export list; pulls symbols
# from static libraries.
#
if (TARGET_OS_DARWIN)
target_link_libraries(tarantool box ${common_libraries})
set_target_properties(tarantool PROPERTIES
LINK_FLAGS "-Wl,-exported_symbols_list,${exports_file}")
else ()
target_link_libraries(tarantool
-Wl,--whole-archive box ${reexport_libraries}
salad -Wl,--no-whole-archive
${common_libraries}
${generic_libraries})
set_target_properties(tarantool PROPERTIES
LINK_FLAGS "-Wl,--dynamic-list,${exports_file}")
# get rid of -rdynamic
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
endif()
install (TARGETS tarantool DESTINATION bin)