forked from OpenAtomFoundation/pikiwidb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
168 lines (141 loc) · 5.77 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
CMAKE_MINIMUM_REQUIRED(VERSION 3.14)
PROJECT(PikiwiDB)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated -g -D'GIT_COMMIT_ID=\"${GIT_COMMIT_ID}\"'")
# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
IF (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
CMAKE_POLICY(SET CMP0135 NEW)
ENDIF ()
SET(CMAKE_CXX_STANDARD 20)
SET(CMAKE_EXPORT_COMPILE_COMMANDS ON)
ENABLE_TESTING()
IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# using Clang
IF (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "10.0")
MESSAGE(FATAL_ERROR "Clang version must be greater than 10.0")
ENDIF ()
ELSEIF (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# using GCC
IF (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "10.0")
MESSAGE(FATAL_ERROR "GCC G++ version must be greater than 10.0")
ENDIF ()
ENDIF ()
############# You should enable sanitizer if you are developing pika #############
# Uncomment the following two lines to enable AddressSanitizer to detect memory leaks and other memory-related bugs.
# SET(CMAKE_BUILD_TYPE "Debug")
# SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -O0 -fno-omit-frame-pointer -fno-optimize-sibling-calls")
# [Notice] AddressSanitizer and ThreadSanitizer can not be enabled at the same time.
# Uncomment the following two lines to enable ThreadSanitizer to detect data race and other thread-related issue.
# SET(CMAKE_BUILD_TYPE "Debug")
# SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=thread -O0 -fno-omit-frame-pointer -fno-optimize-sibling-calls")
EXECUTE_PROCESS(COMMAND uname -p OUTPUT_VARIABLE HOST_ARCH)
STRING(TOLOWER ${HOST_ARCH} HOST_ARCH)
IF (NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE RELEASE)
ENDIF ()
# NOTE !!! CMAKE_BUILD_TYPE is case-sensitive
STRING(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE)
IF (${BUILD_TYPE} STREQUAL DEBUG)
SET(LIB_BUILD_TYPE DEBUG)
ELSEIF (${BUILD_TYPE} STREQUAL MINSIZEREL)
SET(LIB_BUILD_TYPE MINSIZEREL)
ELSEIF (${BUILD_TYPE} STREQUAL RELWITHDEBINFO)
SET(LIB_BUILD_TYPE RELWITHDEBINFO)
ELSE ()
SET(LIB_BUILD_TYPE RELEASE)
SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
ENDIF ()
IF (CMAKE_SYSTEM_NAME MATCHES "Darwin")
SET(CMAKE_CXX_FLAGS "-pthread")
SET(CMAKE_EXE_LINKER_FLAGS "-stdlib=libc++ -lc++ -lc++abi ${CMAKE_EXE_LINKER_FLAGS}")
ADD_DEFINITIONS(-DOS_MACOSX)
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Linux")
IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
SET(CMAKE_EXE_LINKER_FLAGS "-stdlib=libc++ -fuse-ld=lld -lc++ -lc++abi ${CMAKE_EXE_LINKER_FLAGS}")
SET(CMAKE_CXX_FLAGS "-stdlib=libc++ -pthread ${CMAKE_CXX_FLAGS}")
set(CMAKE_THREAD_LIBS_INIT "-lpthread")
ELSEIF (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
SET(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
SET(CMAKE_CXX_FLAGS "-pthread -Wl,--no-as-needed -ldl -Wno-restrict")
ENDIF ()
ADD_DEFINITIONS(-DOS_LINUX)
ELSE ()
MESSAGE(FATAL_ERROR "only support linux or macOS")
ENDIF ()
IF (HOST_ARCH MATCHES "x86_64" OR HOST_ARCH MATCHES "i386")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse -msse4.2")
ELSEIF (HOST_ARCH MATCHES "arm")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv8-a+crc+crypto -moutline-atomics")
ENDIF ()
SET(EP_BASE_SUFFIX "buildtrees")
SET_PROPERTY(DIRECTORY PROPERTY EP_BASE ${CMAKE_CURRENT_SOURCE_DIR}/${EP_BASE_SUFFIX})
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/modules/")
SET(STAGED_INSTALL_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/deps)
SET(CMAKE_UTILS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/utils)
SET(INSTALL_INCLUDEDIR ${STAGED_INSTALL_PREFIX}/include)
SET(INSTALL_LIBDIR ${STAGED_INSTALL_PREFIX}/lib)
SET(INSTALL_LIBDIR_64 ${STAGED_INSTALL_PREFIX}/lib64)
SET(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${STAGED_INSTALL_PREFIX})
SET(BUILD_SUPPORT_DIR ${PROJECT_SOURCE_DIR}/build_support)
MESSAGE(STATUS "${PROJECT_NAME} staged install: ${STAGED_INSTALL_PREFIX}")
MESSAGE(STATUS "Current platform: ${OS_VERSION} ")
CMAKE_HOST_SYSTEM_INFORMATION(RESULT CPU_CORE QUERY NUMBER_OF_LOGICAL_CORES)
MESSAGE(STATUS "CPU core ${CPU_CORE}")
INCLUDE(FetchContent)
#include(cmake/CmakeLists.txt)
include(cmake/findTools.cmake)
include(cmake/libevent.cmake)
include(cmake/llhttp.cmake)
include(cmake/fmt.cmake)
include(cmake/spdlog.cmake)
include(cmake/gtest.cmake)
include(cmake/rocksdb.cmake)
enable_testing()
ADD_SUBDIRECTORY(src/pstd)
ADD_SUBDIRECTORY(src/net)
ADD_SUBDIRECTORY(src/storage)
ADD_SUBDIRECTORY(src)
#############################################################################
### custom target
#############################################################################
SET(CMAKE_EXPORT_COMPILE_COMMANDS ON)
STRING(CONCAT FORMAT_DIRS "${PROJECT_SOURCE_DIR}/src,")
FILE(WRITE
${BUILD_SUPPORT_DIR}/clang_format_exclusions.txt
"${PROJECT_SOURCE_DIR}/src/redis_intset.c\n${PROJECT_SOURCE_DIR}/src/redis_zip_list.c")
ADD_CUSTOM_TARGET(format
COMMAND ${BUILD_SUPPORT_DIR}/run_clang_format.py
${CLANG_FORMAT_BIN}
${BUILD_SUPPORT_DIR}/clang_format_exclusions.txt
--source_dirs ${FORMAT_DIRS}
--quiet
--fix
)
ADD_CUSTOM_TARGET(check-format
COMMAND ${BUILD_SUPPORT_DIR}/run_clang_format.py
${CLANG_FORMAT_BIN}
${BUILD_SUPPORT_DIR}/clang_format_exclusions.txt
--source_dirs ${FORMAT_DIRS}
)
ADD_CUSTOM_TARGET(clang-tidy
COMMAND ${BUILD_SUPPORT_DIR}/run_clang_tidy.py
-clang-tidy-binary ${CLANG_TIDY_BIN}
-p ${CMAKE_BINARY_DIR}
-extra-arg=-std=c++17
)
ADD_CUSTOM_TARGET(clang-tidy-fix
COMMAND ${BUILD_SUPPORT_DIR}/run_clang_tidy.py
-clang-tidy-binary ${CLANG_TIDY_BIN}
-p ${CMAKE_BINARY_DIR}
-extra-arg=-std=c++17
-fix
)
FILE(GLOB_RECURSE LINT_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.cc"
)
ADD_CUSTOM_TARGET(cpplint echo '${LINT_FILES}' | xargs -n12 -P8
${CPPLINT_BIN}
--verbose=2 --quiet
--linelength=120
--filter=-legal/copyright,-build/header_guard,-runtime/references
)