-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathCMakeLists.txt
221 lines (190 loc) · 7.45 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
if (POLICY CMP0048)
cmake_policy(SET CMP0048 NEW)
endif (POLICY CMP0048)
# No in-source build
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
message(FATAL_ERROR "In-source builds are not allowed.")
endif("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
include(ExternalProject)
include(FetchContent)
project(bztree)
cmake_minimum_required(VERSION 3.11)
# Set backend to PMDK by default to build persistent version. This will be passed
# in directly to PMwCAS which provides persistence support.
set(PMEM_BACKEND "PMDK" CACHE STRING "Persistent memory backend type")
string(TOUPPER ${PMEM_BACKEND} PMEM_BACKEND)
# Both volatile and persistent versions are supported, by setting PMEM_BACKEND to:
# PMDK : use PMDK for persistence
# EMU : use simple shared memory for emulating persistent memory. This
# should only be used for experimental and profiling purpose. No real
# persistence is guaranteed.
# VOLATILE: turn off persistence and build a volatile version, no persistence
# whatsoever. Equivalent to the original MwCAS operation.
#
# If persistent memory support is turned on, in the code we define both PMEM and
# the corresponding macro for the backend. Code that is agnostic to the backend
# is wrapped by PMEM; code that is specific to the backend is wrapped around by
# PMEMEMU (for using emulation) or PMDK (for using PMDK).
#
# Note: these macros definitions follow strictly those in PMwCAS and are needed
# to make sure of the inclusion of code in PMwCAS headers in included by BzTree.
if(${PMEM_BACKEND} STREQUAL "PMDK")
add_definitions(-DPMEM)
add_definitions(-DPMDK)
message(STATUS "Persistence support: PMDK")
elseif(${PMEM_BACKEND} STREQUAL "EMU")
add_definitions(-DPMEM)
add_definitions(-DPMEMEMU)
message(STATUS "Persistence support: emulation")
elseif(${PMEM_BACKEND} STREQUAL "VOLATILE")
message(STATUS "Persistence support: off")
else()
message(FATAL_ERROR "Unsupported persistent memory backend: ${PMEM_BACKEND}")
endif()
option(GOOGLE_FRAMEWORK "Use glog, gflags and gtest" ON)
if(${GOOGLE_FRAMEWORK})
add_definitions(-DGOOGLE_FRAMEWORK)
message(STATUS "GOOGLE_FRAMEWORK is defined, will use glog, gflags and gtest")
else()
message(STATUS "GOOGLE_FRAMEWORK is not defined, will not use glog, gflags and gtest")
endif()
option(BUILD_TESTS "Build test cases using gflags, glog and gtest" ON)
if(${BUILD_TESTS})
if(NOT ${GOOGLE_FRAMEWORK})
message(FATAL_ERROR "BUILD_TESTS defined but GOOGLE_FRAMEWORK not defined")
endif()
add_definitions(-DBUILD_TESTS)
message(STATUS "BUILD_TESTS: defined")
else()
message(STATUS "BUILD_TESTS: not defined")
endif()
##################### PMwCAS #########################
add_definitions(-DDESC_CAP=16)
set(PMWCAS_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/pmwcas")
ExternalProject_Add(PMWCAS
PREFIX "${PMWCAS_PREFIX}"
GIT_REPOSITORY https://github.com/sfu-dis/pmwcas.git
GIT_TAG master
INSTALL_COMMAND ""
BUILD_COMMAND $(MAKE)
CMAKE_ARGS -DPMEM_BACKEND=${PMEM_BACKEND} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DDESC_CAP=16 -DBUILD_APPS=${BUILD_TESTS} -DGOOGLE_FRAMEWORK=${GOOGLE_FRAMEWORK}
LOG_DOWNLOAD ON
LOG_CONFIGURE ON
LOG_BUILD ON
)
##################### PiBench #########################
FetchContent_Declare(
pibench
GIT_REPOSITORY https://github.com/sfu-dis/pibench.git
GIT_TAG master
)
if (NOT pibench_POPULATED)
FetchContent_Populate(pibench)
include_directories(${pibench_SOURCE_DIR}/include)
endif ()
# PMwCAS
include_directories(
${PMWCAS_PREFIX}/src/PMWCAS
${PMWCAS_PREFIX}/src/PMWCAS/src/
${PMWCAS_PREFIX}/src/PMWCAS/include
)
link_directories(${PMWCAS_PREFIX}/src/PMWCAS-build/)
if(${GOOGLE_FRAMEWORK})
######################## glog #####################
# Google Log
FetchContent_Declare(
glog
GIT_REPOSITORY https://github.com/google/glog.git
GIT_TAG v0.4.0
)
FetchContent_GetProperties(glog)
if (NOT glog_POPULATED)
FetchContent_Populate(glog)
set(WITH_GFLAGS OFF CACHE BOOL "we don't use gflags")
add_subdirectory(${glog_SOURCE_DIR} ${glog_BINARY_DIR})
endif ()
######################## gtest #####################
# Google Test
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.8.1
)
FetchContent_GetProperties(googletest)
if (NOT googletest_POPULATED)
FetchContent_Populate(googletest)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
include_directories(${googletest_SOURCE_DIR}/GTestExternal/googletest/include)
endif ()
include(GoogleTest)
endif()
####################################################
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
set(LINK_FLAGS "-lnuma -lpthread -pthread -lrt")
link_libraries(${LINK_FLAGS})
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
if(${CMAKE_BUILD_TYPE} STREQUAL "Release")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Ofast -march=native")
endif()
set_property(GLOBAL APPEND PROPERTY BZTREE_SRC
${CMAKE_CURRENT_SOURCE_DIR}/bztree.cc
)
get_property(BZTREE_LIB_SRC GLOBAL PROPERTY BZTREE_SRC)
#add_library(bztree_static STATIC ${BZTREE_LIB_SRC})
add_library(bztree SHARED ${BZTREE_LIB_SRC})
add_dependencies(bztree cpplint)
#add_dependencies(bztree_static PMWCAS)
add_dependencies(bztree PMWCAS)
set (BZTREE_LINK_LIBS
pmwcas
)
if(${GOOGLE_FRAMEWORK})
list(APPEND BZTREE_LINK_LIBS
glog::glog
gtest_main
)
endif()
if(${PMEM_BACKEND} STREQUAL "PMDK")
set(PMDK_LIB_PATH "/usr/local/lib" CACHE STRING "PMDK lib install path")
#add_library(pmemobj STATIC IMPORTED)
#set_property(TARGET pmemobj PROPERTY IMPORTED_LOCATION ${PMDK_LIB_PATH}/libpmemobj.a)
list(APPEND BZTREE_LINK_LIBS
pmemobj
)
endif()
target_link_libraries(bztree ${BZTREE_LINK_LIBS})
#target_link_libraries(bztree_static ${BZTREE_LINK_LIBS})
#set_property(TARGET bztree_static PROPERTY POSITION_INDEPENDENT_CODE ON)
if(${BUILD_TESTS})
if((${PMEM_BACKEND} STREQUAL "PMDK"))
add_executable(bztree_pmdk_tests ${CMAKE_CURRENT_SOURCE_DIR}/tests/bztree_pmdk_tests.cc)
target_link_libraries(bztree_pmdk_tests bztree ${BZTREE_LINK_LIBS})
else()
add_executable(bztree_tests ${CMAKE_CURRENT_SOURCE_DIR}/tests/bztree_tests.cc)
add_executable(bztree_thread_tests ${CMAKE_CURRENT_SOURCE_DIR}/tests/bztree_multithread_tests.cc)
target_link_libraries(bztree_tests bztree ${BZTREE_LINK_LIBS})
target_link_libraries(bztree_thread_tests bztree ${BZTREE_LINK_LIBS})
add_dependencies(bztree_tests cpplint)
endif()
endif()
if(${PMEM_BACKEND} STREQUAL "PMDK")
add_library(bztree_pibench_wrapper SHARED tests/bztree_pibench_wrapper.cc)
target_link_libraries(bztree_pibench_wrapper bztree)
endif()
add_custom_target(
cpplint ALL
COMMAND python2 ${CMAKE_CURRENT_SOURCE_DIR}/third-party/cpplint/cpplint.py
--linelength=100
--filter=-runtime/references,-build/header_guard,-build/include
${CMAKE_CURRENT_SOURCE_DIR}/bztree.h
${CMAKE_CURRENT_SOURCE_DIR}/bztree.cc
${CMAKE_CURRENT_SOURCE_DIR}/tests/bztree_tests.cc
|| (exit 0)
)
set(MAX_FREEZE_RETRY 1 CACHE STRING "MAX retry on frozen node")
target_compile_definitions(bztree PRIVATE MAX_FREEZE_RETRY=${MAX_FREEZE_RETRY})
#target_compile_definitions(bztree_static PRIVATE MAX_FREEZE_RETRY=${MAX_FREEZE_RETRY})
set(ENABLE_MERGE 0 CACHE STRING "MAX retry on frozen node")
message(STATUS "ENABLE_MERGE: " ${ENABLE_MERGE})
target_compile_definitions(bztree PRIVATE ENABLE_MERGE=${ENABLE_MERGE})
#target_compile_definitions(bztree_static PUBLIC ENABLE_MERGE=${ENABLE_MERGE})