summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authoranand76 <anand76@devvm4702.ftw0.facebook.com>2022-09-11 21:40:11 -0700
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>2022-09-11 21:40:11 -0700
commitbe09943fb58a2dd3f70e6e30781ebfa3fcbcb8fa (patch)
tree08c636fa6bf2ad473071a3b0318b9ce447c454c6 /CMakeLists.txt
parent7a9ecdac3c13f2da361fb543ce8dd0371d49f4f4 (diff)
Build and link libfolly with RocksDB (#10103)
Summary: The current integration with folly requires cherry-picking folly source files to include in RocksDB for external CI builds. Its not scaleable as we depend on more features in folly, such as coroutines. This PR adds a dependency from RocksDB to the folly library when ```USE_FOLLY``` or ```USE_COROUTINES``` are set. We build folly using the build scripts in ```third-party/folly```, relying on it to download and build its dependencies. A new ```Makefile``` target, ```build_folly```, is provided to make building folly easier. A new option, ```USE_FOLLY_LITE``` is added to retain the old model of compiling selected folly sources with RocksDB. This might be useful for short-term development. Pull Request resolved: https://github.com/facebook/rocksdb/pull/10103 Reviewed By: pdillinger Differential Revision: D38426787 Pulled By: anand1976 fbshipit-source-id: 33bc84abd9fdc7e2567749f02aa1b2494eb62b2f
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt83
1 files changed, 68 insertions, 15 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1584ea1a8..b00f31d23 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -74,6 +74,7 @@ option(WITH_WINDOWS_UTF8_FILENAMES "use UTF8 as characterset for opening files,
if (WITH_WINDOWS_UTF8_FILENAMES)
add_definitions(-DROCKSDB_WINDOWS_UTF8_FILENAMES)
endif()
+option(ROCKSDB_BUILD_SHARED "Build shared versions of the RocksDB libraries" ON)
if ($ENV{CIRCLECI})
message(STATUS "Build for CircieCI env, a few tests may be disabled")
@@ -584,10 +585,61 @@ endif()
include_directories(${PROJECT_SOURCE_DIR})
include_directories(${PROJECT_SOURCE_DIR}/include)
+
+if(USE_COROUTINES)
+ if(USE_FOLLY OR USE_FOLLY_LITE)
+ message(FATAL_ERROR "Please specify exactly one of USE_COROUTINES,"
+ " USE_FOLLY, and USE_FOLLY_LITE")
+ endif()
+ set(CMAKE_CXX_STANDARD 20)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcoroutines -Wno-maybe-uninitialized")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-redundant-move")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-memory-model")
+ add_compile_definitions(USE_COROUTINES)
+ set(USE_FOLLY 1)
+endif()
+
if(USE_FOLLY)
- include_directories(${PROJECT_SOURCE_DIR}/third-party/folly)
- add_definitions(-DUSE_FOLLY -DFOLLY_NO_CONFIG)
- list(APPEND THIRDPARTY_LIBS glog)
+ if(USE_FOLLY_LITE)
+ message(FATAL_ERROR "Please specify one of USE_FOLLY or USE_FOLLY_LITE")
+ endif()
+ if(ROCKSDB_BUILD_SHARED)
+ message(FATAL_ERROR "Cannot build RocksDB shared library with folly")
+ endif()
+ set(ROCKSDB_BUILD_SHARED OFF)
+ set(GFLAGS_SHARED FALSE)
+ find_package(folly)
+ # If cmake could not find the folly-config.cmake file, fall back
+ # to looking in third-party/folly for folly and its dependencies
+ if(NOT FOLLY_LIBRARIES)
+ exec_program(python3 ${PROJECT_SOURCE_DIR}/third-party/folly ARGS
+ build/fbcode_builder/getdeps.py show-inst-dir OUTPUT_VARIABLE
+ FOLLY_INST_PATH)
+ exec_program(ls ARGS -d ${FOLLY_INST_PATH}/../boost* OUTPUT_VARIABLE
+ BOOST_INST_PATH)
+ exec_program(ls ARGS -d ${FOLLY_INST_PATH}/../fmt* OUTPUT_VARIABLE
+ FMT_INST_PATH)
+ exec_program(ls ARGS -d ${FOLLY_INST_PATH}/../gflags* OUTPUT_VARIABLE
+ GFLAGS_INST_PATH)
+ set(Boost_DIR ${BOOST_INST_PATH}/lib/cmake/Boost-1.78.0)
+ if(EXISTS ${FMT_INST_PATH}/lib64)
+ set(fmt_DIR ${FMT_INST_PATH}/lib64/cmake/fmt)
+ else()
+ set(fmt_DIR ${FMT_INST_PATH}/lib/cmake/fmt)
+ endif()
+ set(gflags_DIR ${GFLAGS_INST_PATH}/lib/cmake/gflags)
+
+ exec_program(sed ARGS -i 's/gflags_shared//g'
+ ${FOLLY_INST_PATH}/lib/cmake/folly/folly-targets.cmake)
+
+ include(${FOLLY_INST_PATH}/lib/cmake/folly/folly-config.cmake)
+ endif()
+
+ add_compile_definitions(USE_FOLLY FOLLY_NO_CONFIG HAVE_CXX11_ATOMIC)
+ list(APPEND THIRDPARTY_LIBS Folly::folly)
+ set(FOLLY_LIBS Folly::folly)
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--copy-dt-needed-entries")
endif()
find_package(Threads REQUIRED)
@@ -983,7 +1035,7 @@ else()
env/io_posix.cc)
endif()
-if(USE_FOLLY)
+if(USE_FOLLY_LITE)
list(APPEND SOURCES
third-party/folly/folly/container/detail/F14Table.cpp
third-party/folly/folly/detail/Futex.cpp
@@ -993,13 +1045,14 @@ if(USE_FOLLY)
third-party/folly/folly/synchronization/AtomicNotification.cpp
third-party/folly/folly/synchronization/DistributedMutex.cpp
third-party/folly/folly/synchronization/ParkingLot.cpp)
+ include_directories(${PROJECT_SOURCE_DIR}/third-party/folly)
+ add_definitions(-DUSE_FOLLY -DFOLLY_NO_CONFIG)
+ list(APPEND THIRDPARTY_LIBS glog)
endif()
set(ROCKSDB_STATIC_LIB rocksdb${ARTIFACT_SUFFIX})
set(ROCKSDB_SHARED_LIB rocksdb-shared${ARTIFACT_SUFFIX})
-option(ROCKSDB_BUILD_SHARED "Build shared versions of the RocksDB libraries" ON)
-
if(WIN32)
set(SYSTEM_LIBS ${SYSTEM_LIBS} shlwapi.lib rpcrt4.lib)
@@ -1425,7 +1478,7 @@ if(WITH_TESTS)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
set(TESTUTILLIB testutillib${ARTIFACT_SUFFIX})
add_library(${TESTUTILLIB} STATIC ${TESTUTIL_SOURCE})
- target_link_libraries(${TESTUTILLIB} ${ROCKSDB_LIB})
+ target_link_libraries(${TESTUTILLIB} ${ROCKSDB_LIB} ${FOLLY_LIBS})
if(MSVC)
set_target_properties(${TESTUTILLIB} PROPERTIES COMPILE_FLAGS "/Fd${CMAKE_CFG_INTDIR}/testutillib${ARTIFACT_SUFFIX}.pdb")
endif()
@@ -1483,32 +1536,32 @@ if(WITH_BENCHMARK_TOOLS)
cache/cache_bench.cc
cache/cache_bench_tool.cc)
target_link_libraries(cache_bench${ARTIFACT_SUFFIX}
- ${ROCKSDB_LIB} ${GFLAGS_LIB})
+ ${ROCKSDB_LIB} ${GFLAGS_LIB} ${FOLLY_LIBS})
add_executable(memtablerep_bench${ARTIFACT_SUFFIX}
memtable/memtablerep_bench.cc)
target_link_libraries(memtablerep_bench${ARTIFACT_SUFFIX}
- ${ROCKSDB_LIB} ${GFLAGS_LIB})
+ ${ROCKSDB_LIB} ${GFLAGS_LIB} ${FOLLY_LIBS})
add_executable(range_del_aggregator_bench${ARTIFACT_SUFFIX}
db/range_del_aggregator_bench.cc)
target_link_libraries(range_del_aggregator_bench${ARTIFACT_SUFFIX}
- ${ROCKSDB_LIB} ${GFLAGS_LIB})
+ ${ROCKSDB_LIB} ${GFLAGS_LIB} ${FOLLY_LIBS})
add_executable(table_reader_bench${ARTIFACT_SUFFIX}
table/table_reader_bench.cc)
target_link_libraries(table_reader_bench${ARTIFACT_SUFFIX}
- ${ROCKSDB_LIB} testharness ${GFLAGS_LIB})
+ ${ROCKSDB_LIB} testharness ${GFLAGS_LIB} ${FOLLY_LIBS})
add_executable(filter_bench${ARTIFACT_SUFFIX}
util/filter_bench.cc)
target_link_libraries(filter_bench${ARTIFACT_SUFFIX}
- ${ROCKSDB_LIB} ${GFLAGS_LIB})
+ ${ROCKSDB_LIB} ${GFLAGS_LIB} ${FOLLY_LIBS})
add_executable(hash_table_bench${ARTIFACT_SUFFIX}
utilities/persistent_cache/hash_table_bench.cc)
target_link_libraries(hash_table_bench${ARTIFACT_SUFFIX}
- ${ROCKSDB_LIB} ${GFLAGS_LIB})
+ ${ROCKSDB_LIB} ${GFLAGS_LIB} ${FOLLY_LIBS})
endif()
option(WITH_TRACE_TOOLS "build with trace tools" ON)
@@ -1516,12 +1569,12 @@ if(WITH_TRACE_TOOLS)
add_executable(block_cache_trace_analyzer_tool${ARTIFACT_SUFFIX}
tools/block_cache_analyzer/block_cache_trace_analyzer_tool.cc)
target_link_libraries(block_cache_trace_analyzer_tool${ARTIFACT_SUFFIX}
- ${ROCKSDB_LIB} ${GFLAGS_LIB})
+ ${ROCKSDB_LIB} ${GFLAGS_LIB} ${FOLLY_LIBS})
add_executable(trace_analyzer${ARTIFACT_SUFFIX}
tools/trace_analyzer.cc)
target_link_libraries(trace_analyzer${ARTIFACT_SUFFIX}
- ${ROCKSDB_LIB} ${GFLAGS_LIB})
+ ${ROCKSDB_LIB} ${GFLAGS_LIB} ${FOLLY_LIBS})
endif()