-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
145 lines (116 loc) · 4.65 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
# TODO(sheep) fix this
set(CMAKE_C_COMPILER "/usr/bin/clang-16")
set(CMAKE_CXX_COMPILER "/usr/bin/clang++-16")
cmake_minimum_required(VERSION 3.13)
project(ArcaneDB)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING
"Using debug build type" FORCE)
endif(NOT CMAKE_BUILD_TYPE)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(C_FLAG_COMMON "")
set(CMAKE_CXX_FLAGS_DEBUG "${C_FLAG_COMMON}")
set(CMAKE_CXX_FLAGS "${C_FLAG_COMMON} -O3 -g -fPIC -fno-omit-frame-pointer -fno-optimize-sibling-calls")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fPIC -Wall -Wextra")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wno-unused-parameter -Wno-attributes")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIC -flto -ldl")
# set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fPIC")
# set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} -fPIC")
# enable CTest
enable_testing()
add_subdirectory(third_party)
find_package(GTest)
# brpc related
set(BRPC_OUTPUT_PATH ${PROJECT_BINARY_DIR}/third_party/incubator-brpc/output)
include(FindThreads)
include(FindProtobuf)
set(BRPC_INCLUDE_PATH ${BRPC_OUTPUT_PATH}/include)
include_directories(${BRPC_INCLUDE_PATH})
set(BRPC_LIB_PATH ${BRPC_OUTPUT_PATH}/lib)
link_directories(${BRPC_LIB_PATH})
message(STATUS "brpc output path: ${BRPC_OUTPUT_PATH}")
message(STATUS "brpc lib path: ${BRPC_LIB_PATH}")
message(STATUS "brpc include path: ${BRPC_INCLUDE_PATH}")
find_path(GFLAGS_INCLUDE_PATH gflags/gflags.h)
find_library(GFLAGS_LIBRARY NAMES gflags libgflags)
if((NOT GFLAGS_INCLUDE_PATH) OR (NOT GFLAGS_LIBRARY))
message(FATAL_ERROR "Fail to find gflags")
endif()
include_directories(${GFLAGS_INCLUDE_PATH})
find_path(LEVELDB_INCLUDE_PATH NAMES leveldb/db.h)
find_library(LEVELDB_LIB NAMES leveldb)
if ((NOT LEVELDB_INCLUDE_PATH) OR (NOT LEVELDB_LIB))
message(FATAL_ERROR "Fail to find leveldb")
endif()
include_directories(${LEVELDB_INCLUDE_PATH})
find_package(OpenSSL)
include_directories(${OPENSSL_INCLUDE_DIR})
set(ARCANEDB_LIBS brpc-static
${CMAKE_THREAD_LIBS_INIT}
${GFLAGS_LIBRARY}
${PROTOBUF_LIBRARIES}
${LEVELDB_LIB}
${OPENSSL_CRYPTO_LIBRARY}
${OPENSSL_SSL_LIBRARY})
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(ARCANEDB_LIBS ${ARCANEDB_LIBS}
pthread
"-framework CoreFoundation"
"-framework CoreGraphics"
"-framework CoreData"
"-framework CoreText"
"-framework Security"
"-framework Foundation"
"-Wl,-U,_MallocExtension_ReleaseFreeMemory"
"-Wl,-U,_ProfilerStart"
"-Wl,-U,_ProfilerStop")
endif()
# brpc end
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
message(STATUS "CMAKE_CXX_FLAGS_DEBUG: ${CMAKE_CXX_FLAGS_DEBUG}")
message(STATUS "CMAKE_EXE_LINKER_FLAGS: ${CMAKE_EXE_LINKER_FLAGS}")
message(STATUS "CMAKE_SHARED_LINKER_FLAGS: ${CMAKE_SHARED_LINKER_FLAGS}")
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
message(STATUS "Compiler info: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
# spdlog
include_directories(third_party/spdlog/include)
link_directories(${PROJECT_BINARY_DIR}/third_party/spdlog)
set(ARCANEDB_LIBS ${ARCANEDB_LIBS}
spdlog::spdlog)
# FIXME: better way to compile.
include_directories(third_party/abseil-cpp)
link_directories(${PROJECT_BINARY_DIR}/third_party/abseil-cpp/absl)
# include_directories(third_party/rocksdb/include)
# set (ARCANEDB_LIBS ${ARCANEDB_LIBS} rocksdb)
set(ARCANEDB_LIBS ${ARCANEDB_LIBS}
jemalloc)
set(ARCANEDB_LIBS ${ARCANEDB_LIBS}
absl::base
absl::hash
absl::raw_hash_set)
set(ARCANEDB_SRC_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/src)
set(ARCANEDB_TEST_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/test)
include_directories(${ARCANEDB_SRC_INCLUDE_DIR}
${ARCANEDB_TEST_INCLUDE_DIR})
include_directories(BEFORE src)
add_subdirectory(src)
add_subdirectory(test)
add_subdirectory(benchmark)
# clang-format
find_program(CLANG_FORMAT_BIN
NAMES clang-format-16)
string(CONCAT ARCANEDB_FORMAT_DIRS
"${PROJECT_SOURCE_DIR}/src,"
"${PROJECT_SOURCE_DIR}/test,")
# Port from bustub
# Runs clang format and updates files in place.
add_custom_target(format
${PROJECT_SOURCE_DIR}/dev-tools/run_clang_format.py
${CLANG_FORMAT_BIN}
${PROJECT_SOURCE_DIR}/dev-tools/clang_format_exclusions.txt
--source_dirs ${ARCANEDB_FORMAT_DIRS}
--fix
--quiet)