-
Notifications
You must be signed in to change notification settings - Fork 315
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
450 lines (380 loc) · 13.6 KB
/
CMakeLists.txt
File metadata and controls
450 lines (380 loc) · 13.6 KB
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
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# https://cmake.org/examples/
# CMakeLists files in this project can
# refer to the root source directory of the project as ${HELLO_SOURCE_DIR} and
# to the root binary directory of the project as ${HELLO_BINARY_DIR}.
cmake_minimum_required (VERSION 3.12)
## TODO: get version from variable
project (CacheLib VERSION 0.1)
#configure_file(cachelib/cachelib_config.h.in cachelib_config.h)
if (NOT DEFINED CACHELIB_MAJOR_VERSION)
set(CACHELIB_MAJOR_VERSION 0)
endif ()
set(CACHELIB_MINOR_VERSION 1)
set(CACHELIB_PATCH_VERSION 0)
set(CACHELIB_VERSION
${CACHELIB_MAJOR_VERSION}.${CACHELIB_MINOR_VERSION}.${CACHELIB_PATCH_VERSION})
set(PACKAGE_NAME "cachelib")
if (NOT DEFINED PACKAGE_VERSION)
set(PACKAGE_VERSION "${CACHELIB_VERSION}")
endif ()
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
set(PACKAGE_TARNAME "${PACKAGE_NAME}-${PACKAGE_VERSION}")
set(PACKAGE_BUGREPORT "https://github.com/facebook/TBD")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
option(BUILD_TESTS "If enabled, compile the tests." ON)
option(BUILD_WITH_DTO "If enabled, build with the DTO library for DSA support." ON)
if (BUILD_WITH_DTO)
find_package(DTO REQUIRED)
if (DTO_FOUND)
message(STATUS "DTO found, remember to configure DSA devices for acceleration. If no DSA device is found, cachelib will fallback to software path.")
endif()
endif ()
include(CMakeDependentOption)
# USE_DTO_API is only meaningful if BUILD_WITH_DTO is ON *and* DTO was found
cmake_dependent_option(
USE_DTO_API
"Use DTO library API functions for DSA acceleration."
OFF
"BUILD_WITH_DTO;DTO_FOUND"
OFF
)
if (USE_DTO_API)
message(STATUS "Using DTO API for offloading")
add_compile_definitions(DTO_API)
endif()
set(BIN_INSTALL_DIR bin CACHE STRING
"The subdirectory where binaries should be installed")
set(TESTS_INSTALL_DIR tests CACHE STRING
"The subdirectory where test binaries should be installed")
set(INCLUDE_INSTALL_DIR include/cachelib CACHE STRING
"The subdirectory where header files should be installed")
set(LIB_INSTALL_DIR lib CACHE STRING
"The subdirectory where libraries should be installed")
set(CMAKE_INSTALL_DIR lib/cmake/cachelib CACHE STRING
"The subdirectory where CMake package config files should be installed")
set(CONFIGS_INSTALL_DIR test_configs CACHE STRING
"The subdirectory where sample test configurations should be installed")
# CMake include directories
set(CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/CMake"
# For shipit-transformed builds
"${CMAKE_CURRENT_SOURCE_DIR}/../build/fbcode_builder/CMake"
${CMAKE_MODULE_PATH})
include(FBThriftLibrary)
# When installing the library (and dependencies like folly) in a non-default
# prefix, this will let projects linking against *.so to find libfolly.so
# automatically.
#set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}")
##https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling
set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib:$ORIGIN/../lib64:$ORIGIN/../lib-os")
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
set(CACHELIB_HOME ${CMAKE_CURRENT_SOURCE_DIR})
set(CACHELIB_BUILD ${CMAKE_CURRENT_BINARY_DIR})
# Add root dir so qualified includes work.
# E.g. #include "cachelib/allocator/foobar.h"
include_directories(${CACHELIB_HOME}/..)
include_directories(${CACHELIB_BUILD}/..)
include_directories(${CACHELIB_BUILD})
# Set directory of the Find$x.cmake files to properly include dependencies
set(CMAKE_MODULE_PATH
"${CACHELIB_HOME}/cmake"
${CMAKE_MODULE_PATH})
# specify the C++ standard
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
message(STATUS "setting C++ standard to C++${CMAKE_CXX_STANDARD}")
endif()
set(CMAKE_CXX_EXTENSIONS OFF)
# include(fb_cxx_flags)
message(STATUS "Update CXXFLAGS: ${CMAKE_CXX_FLAGS}")
set(CMAKE_THREAD_PREFER_PTHREAD ON)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
find_package(Boost REQUIRED COMPONENTS
system filesystem regex context program_options thread)
find_package(Gflags REQUIRED)
find_package(Glog REQUIRED)
find_package(GTest REQUIRED)
include(GoogleTest)
enable_testing()
find_package(folly CONFIG REQUIRED)
find_package(fizz CONFIG REQUIRED)
find_package(fmt CONFIG REQUIRED)
find_package(wangle CONFIG REQUIRED)
find_package(Zlib REQUIRED)
find_package(Zstd REQUIRED)
find_package(FBThrift REQUIRED) # must come after wangle
find_package(NUMA REQUIRED)
find_package(Sparsemap REQUIRED)
find_package(uring)
if (NOT uring_FOUND)
add_definitions(-DCACHELIB_IOURING_DISABLE)
endif()
# FBThrift - generates h/cpp files from .*thrift files
find_program(FBTHRIFT1 thrift1
DOC "Facebook's fork of apache thrift")
if(NOT FBTHRIFT1)
message(FATAL_ERROR "thrift1 not found!")
endif()
add_custom_target(thrift_generated_files)
set_property(GLOBAL PROPERTY TEST_BINARIES)
function (generic_add_source_test TEST_PREFIX SOURCE_FILE)
# Get the basename of the first source file
get_filename_component(TEST_NAME "${SOURCE_FILE}" NAME_WE)
#message(STATUS "Adding test: ${TEST_PREFIX}-${TEST_NAME}"
#" source: ${SOURCE_FILE} additional libraries: ${ARGN}")
add_executable("${TEST_PREFIX}-${TEST_NAME}" "${SOURCE_FILE}")
target_link_libraries("${TEST_PREFIX}-${TEST_NAME}" "${ARGN}")
install(
TARGETS "${TEST_PREFIX}-${TEST_NAME}"
DESTINATION ${TESTS_INSTALL_DIR}
)
get_property(tmp GLOBAL PROPERTY TEST_BINARIES)
set(tmp "${tmp} \\\n\t${TEST_PREFIX}-${TEST_NAME}")
set_property(GLOBAL PROPERTY TEST_BINARIES "${tmp}")
# make tests visible to ctest
gtest_add_tests(TARGET "${TEST_PREFIX}-${TEST_NAME}"
WORKING_DIRECTORY "${TOP_DIR}"
TEST_PREFIX "${TEST_PREFIX}-${TEST_NAME}."
TEST_LIST "test_cases")
# use same timeout as folly
set_tests_properties(${test_cases} PROPERTIES TIMEOUT 120)
endfunction()
#add_custom_command(
# OUTPUT
# gen-cpp2/BloomFilter_constants.cpp
# gen-cpp2/BloomFilter_constants.h
# gen-cpp2/BloomFilter_data.cpp
# gen-cpp2/BloomFilter_data.h
# gen-cpp2/BloomFilter_metadata.cpp
# gen-cpp2/BloomFilter_metadata.h
# gen-cpp2/BloomFilter_types.cpp
# gen-cpp2/BloomFilter_types_custom_protocol.h
# gen-cpp2/BloomFilter_types.h
# gen-cpp2/BloomFilter_types.tcc
# gen-cpp2/BloomFilter_layouts.cpp
# gen-cpp2/BloomFilter_layouts.h
# COMMAND
# ${FBTHRIFT1} -o ${CMAKE_CURRENT_BINARY_DIR} --gen mstch_cpp2:frozen2
# -I ${CACHELIB_HOME} BloomFilter.thrift
# DEPENDS
# BloomFilter.thrift
# WORKING_DIRECTORY
# ${CMAKE_CURRENT_SOURCE_DIR}
#)
#add_custom_target(common_thrift_files
# DEPENDS
# gen-cpp2/BloomFilter_constants.cpp
# #${XBLOOM_THRIFT_FILES}
# )
#add_dependencies(thrift_generated_files common_thrift_files)
function(add_thrift_file PREFIX THRIFT_RELATIVE_PATH CPP_OPTION)
# Get the basename of the thrift file
get_filename_component(THRIFT_BASENAME "${THRIFT_RELATIVE_PATH}" NAME)
# Get the basename of the thrift file (without extension)
get_filename_component(THRIFT_BASENAME_NO_EXT
"${THRIFT_RELATIVE_PATH}" NAME_WE)
# Get the relative-directory of the thrift file (if any)
get_filename_component(THRIFT_REL_DIR "${THRIFT_RELATIVE_PATH}" DIRECTORY)
#message(STATUS "add-thrift: PREFIX: ${PREFIX} REL_PATH:"
#" ${THRIFT_RELATIVE_PATH} BASENAME: ${THRIFT_BASENAME}"
#" REL_DIR: ${THRIFT_REL_DIR} current_source_dir: "
# "${CMAKE_CURRENT_SOURCE_DIR} cur-bin-dir: ${CMAKE_CURRENT_BINARY_DIR}")
if (THRIFT_REL_DIR)
# Create the sub-directory in the binary directory
# (e.g. for "allocator/serialize/objects.thrift", create the "serizlize"
# under "build/allocator/serialize" , where the "gen-cpp2" directory will
# be created). Reldir might be empty.
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${THRIFT_REL_DIR}")
# HACK ALERT, see below
string(APPEND THRIFT_REL_DIR "/")
endif()
# Generate a list of expected output files.
# NOTE: the list is tightly-coupled with the cpp flavor
# generated by 'thrift1'.
set(${PREFIX}_THRIFT_FILES "constants.cpp"
"constants.h"
"data.cpp"
"data.h"
"metadata.cpp"
"metadata.h"
"types.cpp"
"types_custom_protocol.h"
"types.h"
"types.tcc"
"types_binary.cpp"
"types_compact.cpp"
"types_serialization.cpp"
)
# The thrift cpp option "frozen2"
# (e.g. "thrift1 --gen mstch_cpp2:frozen2 ...")
# generates two additional files. The "json" option does not.
if (CPP_OPTION STREQUAL "frozen2")
list(APPEND ${PREFIX}_THRIFT_FILES
"layouts.h"
"layouts.cpp")
endif()
string(LENGTH "${CMAKE_BINARY_DIR}" "FOOJ")
#message(STATUS "*** FOOJ: ${FOOJ}")
string(SUBSTRING "${CMAKE_CURRENT_BINARY_DIR}" "${FOOJ}" -1 "FOOP")
#message(STATUS "*** FOOP: ${FOOP}")
string(CONCAT FOOM "${CMAKE_BINARY_DIR}"
"/cachelib" "${FOOP}/${THRIFT_REL_DIR}")
#message(STATUS "*** FOOM: ${FOOM}")
string(CONCAT FOOX "${FOOM}" "gen-cpp2")
#message(STATUS "*** FOOX: ${FOOX}")
message(STATUS "*** OUTDIR: ${CMAKE_CURRENT_BINARY_DIR}/${THRIFT_REL_DIR} ")
file(MAKE_DIRECTORY "${FOOM}")
#message(STATUS "thrift suffixes: ${${PREFIX}_THRIFT_FILES}")
#HACK ALERT: there is NO slash after "${THRIFT_REL_DIR}" as it might
# be empty. if it's not empty, the slash was added above.
#list(TRANSFORM ${PREFIX}_THRIFT_FILES PREPEND
# "${THRIFT_REL_DIR}gen-cpp2/${THRIFT_BASENAME_NO_EXT}_")
message(STATUS "before: ${${PREFIX}_THRIFT_FILES}")
#string(REGEX REPLACE "([^;]+)"
# "${THRIFT_REL_DIR}gen-cpp2/${THRIFT_BASENAME_NO_EXT}_\\1"
# TMP "${${PREFIX}_THRIFT_FILES}")
string(REGEX REPLACE "([^;]+)" "${FOOX}/${THRIFT_BASENAME_NO_EXT}_\\1"
TMP "${${PREFIX}_THRIFT_FILES}")
message(STATUS "after: ${TMP}")
set(${PREFIX}_THRIFT_FILES "${TMP}")
message(STATUS "thrift files: ${${PREFIX}_THRIFT_FILES}")
add_custom_command(
OUTPUT
${${PREFIX}_THRIFT_FILES}
COMMAND
${FBTHRIFT1} -o ${FOOM} --gen mstch_cpp2:${CPP_OPTION}
-I "${FBTHRIFT_INCLUDE_DIR}" -I ${CACHELIB_HOME}/..
${THRIFT_BASENAME}
DEPENDS
${THRIFT_RELATIVE_PATH}
WORKING_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/${THRIFT_REL_DIR}
)
add_custom_target(${PREFIX}_thrift_target
DEPENDS ${${PREFIX}_THRIFT_FILES})
add_dependencies(thrift_generated_files ${PREFIX}_thrift_target)
# HACK ALERT: transfer the list of files to the parent's (caller's) scope
set(${PREFIX}_THRIFT_FILES "${${PREFIX}_THRIFT_FILES}" PARENT_SCOPE)
endfunction()
add_subdirectory (common)
add_subdirectory (shm)
add_subdirectory (navy)
add_subdirectory (allocator)
add_subdirectory (datatype)
add_subdirectory (compact_cache)
add_subdirectory (benchmarks)
add_subdirectory (cachebench)
# Install the source header files
install(
DIRECTORY
allocator
common
compact_cache
datatype
navy
shm
DESTINATION ${INCLUDE_INSTALL_DIR}
FILES_MATCHING PATTERN "*.h"
PATTERN "external" EXCLUDE
PATTERN "tests" EXCLUDE
PATTERN "benchmarks" EXCLUDE
PATTERN "cachebench" EXCLUDE
PATTERN "scripts" EXCLUDE
PATTERN "cmake" EXCLUDE
)
# Install the thrift-generated header files
install(
DIRECTORY
${CACHELIB_BUILD}/cachelib/
DESTINATION
${INCLUDE_INSTALL_DIR}
FILES_MATCHING
PATTERN "gen-cpp2/*.h"
PATTERN "gen-cpp2/*.tcc"
PATTERN "tests" EXCLUDE
PATTERN "*.dir" EXCLUDE
PATTERN "CMakeFiles" EXCLUDE
)
# Install CMake package configuration files for cachelib
# TODO: @ONLY?
include(CMakePackageConfigHelpers)
configure_package_config_file(
cmake/cachelib-config.cmake.in
cachelib-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_DIR}
PATH_VARS
INCLUDE_INSTALL_DIR
CMAKE_INSTALL_DIR
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/cachelib-config.cmake
DESTINATION ${CMAKE_INSTALL_DIR}
)
install(
DIRECTORY ${CACHELIB_HOME}/cachebench/test_configs/
DESTINATION ${CONFIGS_INSTALL_DIR}
)
add_library(cachelib INTERFACE)
target_link_libraries(cachelib INTERFACE
cachelib_common
cachelib_shm
cachelib_navy
cachelib_allocator
)
target_include_directories(
cachelib
INTERFACE
$<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}>
)
target_compile_features(cachelib_common INTERFACE cxx_std_20)
install(TARGETS
cachelib
EXPORT cachelib-exports
DESTINATION ${LIB_INSTALL_DIR}
)
install(EXPORT cachelib-exports
FILE cachelib-targets.cmake
#NAMESPACE cachelib::
DESTINATION ${CMAKE_INSTALL_DIR})
if (BUILD_SHARED_LIBS)
set_target_properties(
cachelib_allocator
cachelib_cachebench
cachelib_common
cachelib_datatype
cachelib_navy
cachelib_shm
PROPERTIES
SOVERSION ${CACHELIB_MAJOR_VERSION}
VERSION ${PACKAGE_VERSION}
)
endif ()
if (BUILD_TESTS)
get_property(TEST_BINARIES GLOBAL PROPERTY TEST_BINARIES)
#message(STATUS "=== Test binaries : ${TEST_BINARIES} ===")
configure_file(cmake/Makefile.tests.in Makefile.tests @ONLY)
install(
FILES
${CACHELIB_BUILD}/Makefile.tests
DESTINATION
${TESTS_INSTALL_DIR}
RENAME
Makefile
)
endif()