forked from v6d-io/v6d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
739 lines (656 loc) · 27.8 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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
cmake_minimum_required(VERSION 2.8)
set(VINEYARD_MAJOR_VERSION 0)
set(VINEYARD_MINOR_VERSION 3)
set(VINEYARD_PATCH_VERSION 1)
set(VINEYARD_VERSION ${VINEYARD_MAJOR_VERSION}.${VINEYARD_MINOR_VERSION}.${VINEYARD_PATCH_VERSION})
message(STATUS "Configuring and building vineyard version '${VINEYARD_VERSION}'.")
if(POLICY CMP0025)
cmake_policy(SET CMP0025 NEW)
endif()
if(POLICY CMP0048)
cmake_policy(SET CMP0048 NEW)
endif()
project(vineyard LANGUAGES C CXX VERSION ${VINEYARD_VERSION})
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(USE_STATIC_BOOST_LIBS "Build with static-linked boost libraries" OFF)
option(USE_EXTERNAL_ETCD_LIBS "Build with external etcd-cpp-apiv3 library rather than the submodule one" OFF)
option(USE_EXTERNAL_TBB_LIBS "Build with external tbb library rather than the submodule one" OFF)
option(USE_ASAN "Using address sanitizer to check memory accessing" OFF)
option(BUILD_VINEYARD_SERVER "Build vineyard's server" ON)
option(BUILD_VINEYARD_CLIENT "Build vineyard's client" ON)
option(BUILD_VINEYARD_PYTHON_BINDINGS "Build vineyard's python bindings" ON)
option(BUILD_VINEYARD_PYPI_PACKAGES "Build vineyard's python bindings" OFF)
option(BUILD_VINEYARD_BASIC "Build vineyard's basic data structures" ON)
option(BUILD_VINEYARD_IO "Enable vineyard's IOAdaptor support" ON)
option(BUILD_VINEYARD_GRAPH "Enable vineyard's graph data structures" ON)
option(BUILD_VINEYARD_MALLOC "Build vineyard's implementation for client-side malloc" ON)
option(BUILD_VINEYARD_MIGRATION "Enable vineyard's object migration support" ON)
option(BUILD_VINEYARD_TESTS "Generate make targets for vineyard tests" ON)
option(BUILD_VINEYARD_TESTS_ALL "Include make targets for vineyard tests to ALL" OFF)
option(BUILD_VINEYARD_COVERAGE "Build vineyard with coverage information, requires build with Debug" OFF)
option(BUILD_VINEYARD_PROFILING "Build vineyard with profiling information" OFF)
include(CheckCXXCompilerFlag)
include(CheckLibraryExists)
include(ExternalProject)
include(GNUInstallDirs)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
include(ProcessorCount)
ProcessorCount(N)
set(DEFAULT_BUILD_TYPE "Release")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified.")
set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE
STRING "Choose the type of build." FORCE
)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo"
)
else()
message(STATUS "Setting build type to '${CMAKE_BUILD_TYPE}'.")
endif()
find_program(ccache_EXECUTABLE ccache)
if(ccache_EXECUTABLE)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${ccache_EXECUTABLE})
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${ccache_EXECUTABLE})
add_custom_target(ccache-stats
COMMAND ${ccache_EXECUTABLE} --show-stats
)
else()
add_custom_target(ccache-stats
COMMAND echo "ccache not found."
)
endif(ccache_EXECUTABLE)
set(DEFAUTL_ALLOCATOR "dlmalloc")
set(WITH_ALLOCATOR "${DEFAUTL_ALLOCATOR}" CACHE
STRING "Choose the allocator for vineyard server (vineyardd)."
)
set_property(CACHE WITH_ALLOCATOR PROPERTY STRINGS
"dlmalloc" "jemalloc"
)
message(STATUS "Setting the allocator to vineyardd as '${WITH_ALLOCATOR}'.")
# reference: https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling#always-full-rpath
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib:${CMAKE_INSTALL_PREFIX}/lib64")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC \
-Wall \
-Wno-attributes \
-Wno-unknown-pragmas"
)
check_cxx_compiler_flag(-Wno-class-memaccess W_NO_CLASS_MEMACCESS)
check_cxx_compiler_flag(-Wno-deprecated-declarations W_NO_DEPRECATED_DECLARATIONS)
check_cxx_compiler_flag(-Wno-defaulted-function-deleted W_NO_DEFAULTED_FUNCTION_DELETED)
check_cxx_compiler_flag(-Wno-error=c++11-narrowing W_NO_ERROR_CXX11_NARROWING)
check_cxx_compiler_flag(-Wno-format-truncation W_NO_FORMAT_TRUNCATION)
if(W_NO_CLASS_MEMACCESS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-class-memaccess")
endif()
if(W_NO_DEPRECATED_DECLARATIONS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
endif()
if(W_NO_DEFAULTED_FUNCTION_DELETED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-defaulted-function-deleted")
endif()
if(W_NO_ERROR_CXX11_NARROWING)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=c++11-narrowing")
endif()
if(W_NO_FORMAT_TRUNCATION)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-format-truncation")
endif()
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g")
if(BUILD_VINEYARD_COVERAGE)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage")
endif()
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -g")
if(APPLE)
set(CMAKE_MACOSX_RPATH ON)
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,$ORIGIN:$ORIGIN/../lib")
endif()
if(CMAKE_VERSION VERSION_LESS "3.1")
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
check_cxx_compiler_flag(-std=c++14 HAVE_FLAG_STD_CXX14)
if(BUILD_VINEYARD_PYPI_PACKAGES AND NOT HAVE_FLAG_STD_CXX14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
endif()
else()
set(HAVE_FLAG_STD_CXX14 TRUE)
endif()
else()
set(CMAKE_CXX_STANDARD 14)
set(HAVE_FLAG_STD_CXX14 TRUE)
endif()
macro(find_apache_arrow)
# workaround for: https://issues.apache.org/jira/projects/ARROW/issues/ARROW-11836
if(NOT BUILD_VINEYARD_PYPI_PACKAGES)
find_package(Arrow QUIET)
endif()
if(Arrow_FOUND)
set(ARROW_INCLUDE_DIR)
if (TARGET arrow_shared)
set(ARROW_SHARED_LIB arrow_shared)
endif()
if (TARGET arrow_static)
set(ARROW_STATIC_LIB arrow_static)
endif()
else()
include("cmake/FindArrow.cmake")
if(NOT ARROW_FOUND)
message(FATAL_ERROR "apache-arrow is required, please install it and retry")
endif()
endif()
endmacro(find_apache_arrow)
macro(find_boost)
if(NOT BUILD_SHARED_LIBS AND USE_STATIC_BOOST_LIBS)
set(Boost_USE_STATIC_LIBS ON CACHE BOOL "Use static version of boost libraries.")
set(Boost_USE_STATIC_RUNTIME ON CACHE BOOL "Use static version of boost runtimes.")
endif()
find_package(Boost COMPONENTS system)
# Make boost::property_tree thread safe.
add_compile_options(-DBOOST_SPIRIT_THREADSAFE)
# Don't depends on the boost::system library.
add_compile_options(-DBOOST_ERROR_CODE_HEADER_ONLY)
add_compile_options(-DBOOST_SYSTEM_NO_DEPRECATED)
# eliminate a lot of warnings for newer version of boost library.
add_compile_options(-DBOOST_BIND_GLOBAL_PLACEHOLDERS)
endmacro(find_boost)
macro(find_ctti)
add_subdirectory(thirdparty/ctti)
endmacro(find_ctti)
macro(find_etcd_cpp_apiv3)
if(USE_EXTERNAL_ETCD_LIBS)
find_package(etcd-cpp-api QUIET)
if(NOT etcd-cpp-api_FOUND)
message(WARNING "etcd-cpp-apiv3 not found, will use the bundled one from git submodules.")
include("cmake/BuildEtcdCpp.cmake")
endif()
else()
include("cmake/BuildEtcdCpp.cmake")
endif()
endmacro(find_etcd_cpp_apiv3)
macro(find_intel_tbb)
set(TBB_TEST OFF CACHE BOOL "Disable tbb testing")
set(TBB_EXAMPLES OFF CACHE BOOL "Disable tbb examples")
set(TBB_STRICT OFF CACHE BOOL "Don't treat warnings as errors for tbb library")
set(TBB4PY_BUILD OFF CACHE BOOL "Disable tbb4py build")
set(TBB_CPF ON CACHE BOOL "Enable preview features of the library")
if(USE_EXTERNAL_TBB_LIBS)
find_package(TBB QUIET)
if(NOT TBB_FOUND)
message(WARNING "intel-tbb not found, will use the bundled one from git submodules.")
add_subdirectory(thirdparty/intel-tbb)
endif()
else()
add_subdirectory(thirdparty/intel-tbb)
endif()
endmacro(find_intel_tbb)
macro(find_jemalloc)
# ./configure --disable-shared --enable-static --disable-cxx --enable-stats --disable-initial-exec-tls --with-jemalloc-prefix=vineyard_je_
#
# see: https://github.com/jemalloc/jemalloc/issues/1237
# install jemalloc when building static libs
if(BUILD_SHARED_LIBS)
set(JEMALLOC_INSTALL_CMD echo "No need to install for jemalloc.")
else()
set(JEMALLOC_INSTALL_CMD echo "Installing jemalloc." && ${CMAKE_MAKE_PROGRAM} install)
endif()
ExternalProject_Add(libjemalloc
SOURCE_DIR "${PROJECT_SOURCE_DIR}/thirdparty/jemalloc"
BUILD_IN_SOURCE 1
BUILD_ALWAYS 1
CONFIGURE_COMMAND "${PROJECT_SOURCE_DIR}/thirdparty/jemalloc/autogen.sh"
--prefix=${CMAKE_INSTALL_PREFIX}
--disable-shared
--enable-static
--disable-cxx
--enable-stats
--disable-initial-exec-tls
--with-jemalloc-prefix=vineyard_je_
BUILD_COMMAND ${CMAKE_MAKE_PROGRAM}
INSTALL_COMMAND ${JEMALLOC_INSTALL_CMD}
)
add_library(jemalloc STATIC IMPORTED)
add_dependencies(jemalloc libjemalloc)
set_target_properties(jemalloc PROPERTIES IMPORTED_LOCATION
${PROJECT_SOURCE_DIR}/thirdparty/jemalloc/lib/libjemalloc_pic.a)
set_target_properties(jemalloc PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
${PROJECT_SOURCE_DIR}/thirdparty)
endmacro(find_jemalloc)
macro(find_glog)
include("cmake/FindGlog.cmake")
endmacro(find_glog)
macro(find_gflags)
include("cmake/FindGFlags.cmake")
endmacro(find_gflags)
macro(find_libunwind)
include("cmake/FindLibUnwind.cmake")
endmacro(find_libunwind)
macro(find_nlohmann_json)
# include nlohmann/json
set(JSON_BuildTests OFF CACHE INTERNAL "")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(JSON_Diagnostics ON CACHE INTERNAL "")
endif()
set(JSON_Install ON CACHE INTERNAL "")
set(JSON_MultipleHeaders ON CACHE INTERNAL "")
set(JSON_ImplicitConversions OFF CACHE INTERNAL "")
add_subdirectory(thirdparty/nlohmann-json)
endmacro(find_nlohmann_json)
macro(find_openssl_libraries)
if (APPLE)
# If we're on OS X check for Homebrew's copy of OpenSSL instead of Apple's
if (NOT OpenSSL_DIR)
find_program(HOMEBREW brew)
if (HOMEBREW STREQUAL "HOMEBREW-NOTFOUND")
message(WARNING "Homebrew not found: not using Homebrew's OpenSSL")
if (NOT OPENSSL_ROOT_DIR)
message(WARNING "Use -DOPENSSL_ROOT_DIR for non-Apple OpenSSL")
endif()
else()
execute_process(COMMAND brew --prefix openssl
OUTPUT_VARIABLE OPENSSL_ROOT_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
endif()
endif()
find_package(OpenSSL ${ARGN})
if (OPENSSL_FOUND)
include_directories(SYSTEM ${OPENSSL_INCLUDE_DIR})
endif()
endmacro(find_openssl_libraries)
macro(find_pthread)
# find pthread
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads)
endmacro(find_pthread)
macro(find_common_libraries)
find_apache_arrow()
find_boost()
find_ctti()
find_glog()
find_jemalloc()
find_libunwind()
find_pthread()
find_nlohmann_json()
include_directories(SYSTEM ${ARROW_INCLUDE_DIR})
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
include_directories(SYSTEM ${GLOG_INCLUDE_DIR})
include_directories(SYSTEM ${GFLAGS_INCLUDE_DIR})
endmacro(find_common_libraries)
if(NOT BUILD_VINEYARD_PYPI_PACKAGES)
find_gflags()
endif()
# find openssl first since apache-arrow may requires that (on MacOS, installed by brew)
find_openssl_libraries(QUIET)
find_common_libraries()
include_directories(${PROJECT_SOURCE_DIR}/src)
include_directories(${PROJECT_SOURCE_DIR}/modules)
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/thirdparty)
# build profiling library
if(BUILD_VINEYARD_PROFILING)
add_definitions(-DWITH_PROFILING)
include("cmake/FindGperftools.cmake")
endif()
if(${LIBUNWIND_FOUND})
add_definitions(-DWITH_LIBUNWIND)
endif ()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
macro(add_target_link_options target scope)
set(options)
set(oneValueArgs)
set(multiValueArgs OPTIONS)
cmake_parse_arguments(add_target_link_options "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(${CMAKE_VERSION} VERSION_LESS "3.13")
target_link_libraries(${target} INTERFACE ${add_target_link_options_OPTIONS})
else()
target_link_options(${target} ${scope} ${add_target_link_options_OPTIONS})
endif()
endmacro()
macro(install_vineyard_target target)
install(TARGETS ${target}
EXPORT vineyard-targets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
endmacro()
macro(install_vineyard_headers header_path)
install(DIRECTORY ${header_path}
DESTINATION include/vineyard # target directory
FILES_MATCHING # install only matched files
PATTERN "*.h" # select header files
PATTERN "*.hpp" # select C++ template header files
PATTERN "*.vineyard-mod" # select vineyard template files
)
endmacro()
install_vineyard_headers("${PROJECT_SOURCE_DIR}/src/common")
set(VINEYARD_INSTALL_LIBS)
# resolve targets dependencies
if(BUILD_VINEYARD_PYPI_PACKAGES)
set(BUILD_VINEYARD_PYTHON_BINDINGS ON)
endif()
if(BUILD_VINEYARD_GRAPH)
set(BUILD_VINEYARD_BASIC ON)
set(BUILD_VINEYARD_IO ON)
endif()
if(BUILD_VINEYARD_IO)
set(BUILD_VINEYARD_BASIC ON)
endif()
if(BUILD_VINEYARD_BASIC OR BUILD_VINEYARD_IO OR BUILD_VINEYARD_MIGRATION OR BUILD_VINEYARD_PYTHON_BINDINGS)
set(BUILD_VINEYARD_CLIENT ON)
endif()
if(BUILD_VINEYARD_MALLOC)
set(BUILD_VINEYARD_CLIENT ON)
endif()
# build vineyardd
if(BUILD_VINEYARD_SERVER)
find_openssl_libraries(REQUIRED)
find_etcd_cpp_apiv3()
find_intel_tbb()
file(GLOB_RECURSE SERVER_SRC_FILES "src/server/*.cc"
"src/common/memory/*.cc"
"src/common/util/*.cc"
)
add_executable(vineyardd ${SERVER_SRC_FILES})
target_compile_options(vineyardd PRIVATE -DBUILD_VINEYARDD)
target_link_libraries(vineyardd PUBLIC ${Boost_LIBRARIES}
${CPPREST_LIB}
${ETCD_CPP_LIBRARIES}
${GFLAGS_LIBRARIES}
${GLOG_LIBRARIES}
${OPENSSL_LIBRARIES}
nlohmann_json::nlohmann_json
TBB::tbb
)
target_include_directories(vineyardd PRIVATE ${ETCD_CPP_INCLUDE_DIR})
if(${LIBUNWIND_FOUND})
target_link_libraries(vineyardd PRIVATE ${LIBUNWIND_LIBRARIES})
endif()
install_vineyard_target(vineyardd)
install_vineyard_headers("${PROJECT_SOURCE_DIR}/src/server")
if(NOT BUILD_SHARED_LIBS)
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
target_compile_options(vineyardd PRIVATE -static-libgcc -static-libstdc++ -Os)
add_target_link_options(vineyardd PRIVATE OPTIONS -static-libgcc -static-libstdc++ -Os)
endif()
target_link_libraries(vineyardd PRIVATE ${GRPC_GRPC++_LIBRARY} ${GRPC_LIBRARY} ${GPR_LIBRARY})
endif()
if(BUILD_VINEYARD_PROFILING)
target_include_directories(vineyardd PRIVATE ${Gperftools_INCLUDE_DIRS})
target_link_libraries(vineyardd PRIVATE ${Gperftools_LIBRARIES})
endif()
message(STATUS "Vineyard will use '${WITH_ALLOCATOR}' for shared memory allocation")
if(WITH_ALLOCATOR STREQUAL "dlmalloc")
# use dlmalloc
target_compile_options(vineyardd PRIVATE -DWITH_DLMALLOC)
elseif(WITH_ALLOCATOR STREQUAL "jemalloc")
target_link_libraries(vineyardd PRIVATE jemalloc ${CMAKE_DL_LIBS})
target_compile_options(vineyardd PRIVATE -DWITH_JEMALLOC)
else()
message(FATAL "The allocator '${WITH_ALLOCATOR}' is not supported")
endif()
# sanitizer
if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND USE_ASAN)
target_compile_options(vineyardd PRIVATE -fsanitize=address)
add_target_link_options(vineyardd PRIVATE OPTIONS -fsanitize=address)
endif()
endif()
# build vineyard-client
if(BUILD_VINEYARD_CLIENT)
# build vineyard registry library, it can only be a shared library, as a singleton.
add_library(vineyard_internal_registry SHARED "src/client/ds/factory/registry.cc")
target_link_libraries(vineyard_internal_registry PRIVATE ${CMAKE_DL_LIBS})
if(BUILD_VINEYARD_PYPI_PACKAGES)
target_compile_options(vineyard_internal_registry PRIVATE -Os)
add_target_link_options(vineyard_internal_registry PRIVATE OPTIONS -Os)
add_target_link_options(vineyard_internal_registry PRIVATE OPTIONS -Os)
endif()
install_vineyard_target(vineyard_internal_registry)
add_target_link_options(vineyard_internal_registry PRIVATE
OPTIONS -Wl,-rpath,.:$ORIGIN:${CMAKE_INSTALL_PREFIX}/lib:${CMAKE_INSTALL_PREFIX}/lib64
)
set_target_properties(vineyard_internal_registry PROPERTIES CXX_VISIBILITY_PRESET "hidden")
target_include_directories(vineyard_internal_registry PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/ctti/include>
$<INSTALL_INTERFACE:include>
)
# build the vineyard client library
file(GLOB CLIENT_SRC_FILES "src/client/*.cc"
"src/client/ds/*.cc"
"src/common/memory/*.cc"
"src/common/util/*.cc"
)
# the vineyard_client can only be a shared library, since the ObjectFactory
# is a singleton.
add_library(vineyard_client ${CLIENT_SRC_FILES})
target_link_libraries(vineyard_client PUBLIC ${CMAKE_DL_LIBS}
Threads::Threads
nlohmann_json::nlohmann_json
${GLOG_LIBRARIES}
)
if(NOT BUILD_VINEYARD_PYPI_PACKAGES)
# required on mac, but cause problem on linux.
target_link_libraries(vineyard_client PUBLIC ${GFLAGS_LIBRARIES})
endif()
if(ARROW_SHARED_LIB)
target_link_libraries(vineyard_client PUBLIC ${ARROW_SHARED_LIB})
else()
target_link_libraries(vineyard_client PUBLIC ${ARROW_STATIC_LIB})
endif()
target_link_libraries(vineyard_client PRIVATE jemalloc ${CMAKE_DL_LIBS})
target_compile_options(vineyard_client PUBLIC -DWITH_JEMALLOC)
target_include_directories(vineyard_client PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/ctti/include>
$<INSTALL_INTERFACE:include>
)
if(BUILD_VINEYARD_PYPI_PACKAGES)
target_compile_options(vineyard_client PRIVATE -Os)
add_target_link_options(vineyard_client PRIVATE OPTIONS -Os)
endif()
install_vineyard_target(vineyard_client)
install_vineyard_headers("${PROJECT_SOURCE_DIR}/src/client")
list(APPEND VINEYARD_INSTALL_LIBS vineyard_client)
install(DIRECTORY thirdparty/ctti/include/ctti
DESTINATION include # target directory
FILES_MATCHING # install only matched files
PATTERN "*.hpp" # select C++ template header files
)
endif()
include("cmake/GenerateVineyard.cmake")
if(BUILD_VINEYARD_PYTHON_BINDINGS)
set(PYBIND11_PYTHON_VERSION 3)
add_subdirectory(thirdparty/pybind11)
set(PYTHON_BIND_FILES "python/client.cc"
"python/core.cc"
"python/error.cc"
"python/pybind11_utils.cc"
"python/vineyard.cc")
if(BUILD_VINEYARD_BASIC)
list(APPEND PYTHON_BIND_FILES "python/stream.cc")
endif()
pybind11_add_module(_C MODULE ${PYTHON_BIND_FILES})
target_link_libraries(_C PRIVATE vineyard_client)
if(BUILD_VINEYARD_BASIC)
target_link_libraries(_C PRIVATE vineyard_basic)
target_compile_options(_C PRIVATE -DBIND_STREAM)
endif()
target_include_directories(_C PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
thirdparty/pybind11/include)
target_compile_options(_C PRIVATE -Wno-unused-value)
set_target_properties(_C PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/vineyard")
add_target_link_options(_C PRIVATE
OPTIONS -Wl,-rpath,.:$ORIGIN:${CMAKE_INSTALL_PREFIX}/lib:${CMAKE_INSTALL_PREFIX}/lib64
)
if(UNIX AND NOT APPLE)
add_target_link_options(_C PRIVATE OPTIONS -Wl,--exclude-libs=ALL)
endif()
if(BUILD_VINEYARD_PYPI_PACKAGES AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(_C PRIVATE -static)
add_target_link_options(_C PRIVATE OPTIONS -static)
else()
target_compile_options(_C PRIVATE -Os)
add_target_link_options(_C PRIVATE OPTIONS -Os)
endif()
add_custom_target(vineyard_client_python
ALL
COMMAND cp "$<TARGET_FILE:_C>" "${PROJECT_SOURCE_DIR}/python/vineyard/"
COMMAND cp "$<TARGET_FILE:vineyard_internal_registry>" "${PROJECT_SOURCE_DIR}/python/vineyard/"
DEPENDS _C vineyard_internal_registry
COMMENT "Copying python extensions."
VERBATIM)
endif()
add_custom_target(vineyard_tests)
# add sub_directories
if(BUILD_VINEYARD_BASIC)
add_subdirectory(modules/basic)
list(APPEND VINEYARD_INSTALL_LIBS vineyard_basic)
endif()
if(BUILD_VINEYARD_IO)
add_subdirectory(modules/io)
list(APPEND VINEYARD_INSTALL_LIBS vineyard_io)
endif()
if(BUILD_VINEYARD_GRAPH)
add_subdirectory(modules/graph)
list(APPEND VINEYARD_INSTALL_LIBS vineyard_graph)
endif()
if(BUILD_VINEYARD_MALLOC)
add_subdirectory(modules/malloc)
list(APPEND VINEYARD_INSTALL_LIBS vineyard_malloc)
endif()
if(BUILD_VINEYARD_MIGRATION)
add_subdirectory(modules/migrate)
# don't includes vineyard_migrate to "VINEYARD_LIBRARIES"
endif()
if(BUILD_VINEYARD_TESTS)
enable_testing()
file(GLOB TEST_FILES RELATIVE "${PROJECT_SOURCE_DIR}/test"
"${PROJECT_SOURCE_DIR}/test/*.cc"
)
foreach(f ${TEST_FILES})
string(REGEX MATCH "^(.*)\\.[^.]*$" dummy ${f})
set(T_NAME ${CMAKE_MATCH_1})
message(STATUS "Found unit_test - " ${T_NAME})
if(BUILD_VINEYARD_TESTS_ALL)
add_executable(${T_NAME} test/${T_NAME}.cc)
else()
add_executable(${T_NAME} EXCLUDE_FROM_ALL test/${T_NAME}.cc)
endif()
target_link_libraries(${T_NAME} PRIVATE ${VINEYARD_INSTALL_LIBS})
if(ARROW_SHARED_LIB)
target_link_libraries(${T_NAME} PRIVATE ${ARROW_SHARED_LIB})
else()
target_link_libraries(${T_NAME} PRIVATE ${ARROW_STATIC_LIB})
endif()
if(${LIBUNWIND_FOUND})
target_link_libraries(${T_NAME} PRIVATE ${LIBUNWIND_LIBRARIES})
endif()
add_test(${T_NAME}, ${T_NAME})
add_dependencies(vineyard_tests ${T_NAME})
target_compile_options(${T_NAME} PRIVATE "-std=c++17")
if(${T_NAME} STREQUAL "delete_test" OR ${T_NAME} STREQUAL "rpc_delete_test")
target_compile_options(${T_NAME} PRIVATE "-fno-access-control")
endif()
endforeach()
endif()
file(GLOB_RECURSE FILES_NEED_FORMAT "src/*.cc" "src/*.h" "src/*.hpp" "src/*.vineyard-mod"
"modules/*.cc" "modules/*.h" "modules/*.vineyard-mod"
"python/*.cc" "python/*.h"
"test/*.cc"
)
file(GLOB_RECURSE FILES_NEED_LINT "src/*.cc" "src/*.h" "src/*.hpp"
"modules/*.cc" "modules/*.h"
"python/*.cc" "python/*.h"
"test/*.cc"
)
foreach (file_path ${FILES_NEED_FORMAT})
if (${file_path} MATCHES ".*vineyard.h" OR ${file_path} MATCHES ".*thirdparty.*")
list(REMOVE_ITEM FILES_NEED_FORMAT ${file_path})
endif ()
endforeach ()
foreach (file_path ${FILES_NEED_LINT})
if (${file_path} MATCHES ".*vineyard.h" OR ${file_path} MATCHES ".*thirdparty.*")
list(REMOVE_ITEM FILES_NEED_LINT ${file_path})
endif ()
endforeach ()
add_custom_target(vineyard_clformat
COMMAND clang-format --style=file -i ${FILES_NEED_FORMAT}
COMMENT "Running clang-format."
VERBATIM)
add_custom_target(vineyard_cpplint
COMMAND ${PROJECT_SOURCE_DIR}/misc/cpplint.py --root=vineyard ${FILES_NEED_LINT}
COMMENT "Running cpplint check."
VERBATIM)
add_custom_target(python_install
COMMAND python3 setup.py install
COMMAND python3 setup_airflow.py install
COMMAND python3 setup_ml.py install
COMMAND python3 setup_dask.py install
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
VERBATIM)
# install bundled thirdparty: flat_hash_map
install(DIRECTORY ${PROJECT_SOURCE_DIR}/thirdparty/flat_hash_map
DESTINATION include # target directory
FILES_MATCHING # install only matched files
PATTERN "*.h" # select header files
PATTERN "*.hpp" # select C++ template header files
)
# for python's setup.cfg
configure_file("${PROJECT_SOURCE_DIR}/setup.cfg.in"
"${PROJECT_SOURCE_DIR}/setup.cfg" @ONLY
)
configure_file("${PROJECT_SOURCE_DIR}/python/vineyard/version.py.in"
"${PROJECT_SOURCE_DIR}/python/vineyard/version.py" @ONLY
)
configure_file("${PROJECT_SOURCE_DIR}/src/common/util/config.h.in"
"${PROJECT_SOURCE_DIR}/src/common/util/config.h" @ONLY
)
configure_file("${PROJECT_SOURCE_DIR}/vineyard-config.in.cmake"
"${PROJECT_BINARY_DIR}/vineyard-config.cmake" @ONLY
)
configure_file("${PROJECT_SOURCE_DIR}/vineyard-config-version.in.cmake"
"${PROJECT_BINARY_DIR}/vineyard-config-version.cmake" @ONLY
)
# install vineyard-codegen script.
get_target_property(VINEYARD_CODEGEN_SCRIPT vineyard::codegen IMPORTED_LOCATION)
install(PROGRAMS "${VINEYARD_CODEGEN_SCRIPT}"
DESTINATION bin
RENAME vineyard-codegen
)
install(FILES "${PROJECT_BINARY_DIR}/vineyard-config.cmake"
"${PROJECT_BINARY_DIR}/vineyard-config-version.cmake"
"${PROJECT_SOURCE_DIR}/cmake/FindArrow.cmake"
"${PROJECT_SOURCE_DIR}/cmake/FindGFlags.cmake"
"${PROJECT_SOURCE_DIR}/cmake/FindGlog.cmake"
"${PROJECT_SOURCE_DIR}/cmake/FindRdkafka.cmake"
"${PROJECT_SOURCE_DIR}/cmake/GenerateVineyard.cmake"
"${PROJECT_SOURCE_DIR}/cmake/DetermineImplicitIncludes.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/vineyard
)
install(EXPORT vineyard-targets
FILE vineyard-targets.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/vineyard
)
# build docs
find_program(doxygen_EXECUTABLE doxygen NO_CMAKE_SYSTEM_PATH)
find_program(sphinx_build_EXECUTABLE sphinx-build NO_CMAKE_SYSTEM_PATH)
if(doxygen_EXECUTABLE AND sphinx_build_EXECUTABLE)
add_custom_target(vineyard_doc
COMMAND ${CMAKE_COMMAND} -E make_directory _build
COMMAND ${doxygen_EXECUTABLE}
COMMAND ${sphinx_build_EXECUTABLE} . _build/html
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/docs
VERBATIM
)
else()
if(NOT doxygen_EXECUTABLE)
message(STATUS "Cannot find the doxygen executable.")
endif()
if(NOT sphinx_build_EXECUTABLE)
message(STATUS "Cannot find the sphinx-build executable.")
endif()
endif()