From 3e40a5e8325905e32b15a646d914a571ff2633d2 Mon Sep 17 00:00:00 2001 From: Nikhil Benesch Date: Thu, 30 Nov 2017 22:37:19 -0800 Subject: [PATCH] add missing config checks to CMakeLists.txt Summary: Bring CMakeLists.txt back up to parity with build_detect_platform. Closes https://github.com/facebook/rocksdb/pull/3211 Differential Revision: D6452908 Pulled By: ajkr fbshipit-source-id: 93f5f336ad7eff6ecf65dec47bfaf114dd24cfb2 --- CMakeLists.txt | 49 +++++++++++++++++++++++++++++++----- cmake/modules/FindNUMA.cmake | 21 ++++++++++++++++ cmake/modules/FindTBB.cmake | 21 ++++++++++++++++ 3 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 cmake/modules/FindNUMA.cmake create mode 100644 cmake/modules/FindTBB.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 77ff7cfb6..99c4c4fd2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -249,6 +249,20 @@ if(WITH_UBSAN) endif() endif() +find_package(NUMA) +if(NUMA_FOUND) + add_definitions(-DNUMA) + include_directories(${NUMA_INCLUDE_DIR}) + list(APPEND THIRDPARTY_LIBS ${NUMA_LIBRARIES}) +endif() + +find_package(TBB) +if(TBB_FOUND) + add_definitions(-DTBB) + include_directories(${TBB_INCLUDE_DIR}) + list(APPEND THIRDPARTY_LIBS ${TBB_LIBRARIES}) +endif() + # Used to run CI build and tests so we can run faster set(OPTIMIZE_DEBUG_DEFAULT 0) # Debug build is unoptimized by default use -DOPTDBG=1 to optimize @@ -316,11 +330,8 @@ if(NOT WIN32) endif() option(WITH_FALLOCATE "build with fallocate" ON) - if(WITH_FALLOCATE) - set(CMAKE_REQUIRED_FLAGS ${CMAKE_C_FLAGS}) - include(CheckCSourceCompiles) - CHECK_C_SOURCE_COMPILES(" + CHECK_CXX_SOURCE_COMPILES(" #include #include int main() { @@ -333,12 +344,38 @@ int main() { endif() endif() -include(CheckFunctionExists) -CHECK_FUNCTION_EXISTS(malloc_usable_size HAVE_MALLOC_USABLE_SIZE) +CHECK_CXX_SOURCE_COMPILES(" +#include +int main() { + int fd = open(\"/dev/null\", 0); + sync_file_range(fd, 0, 1024, SYNC_FILE_RANGE_WRITE); +} +" HAVE_SYNC_FILE_RANGE_WRITE) +if(HAVE_SYNC_FILE_RANGE_WRITE) + add_definitions(-DROCKSDB_RANGESYNC_PRESENT) +endif() + +CHECK_CXX_SOURCE_COMPILES(" +#include +int main() { + (void) PTHREAD_MUTEX_ADAPTIVE_NP; +} +" HAVE_PTHREAD_MUTEX_ADAPTIVE_NP) +if(HAVE_PTHREAD_MUTEX_ADAPTIVE_NP) + add_definitions(-DROCKSDB_PTHREAD_ADAPTIVE_MUTEX) +endif() + +include(CheckCXXSymbolExists) +check_cxx_symbol_exists(malloc_usable_size malloc.h HAVE_MALLOC_USABLE_SIZE) if(HAVE_MALLOC_USABLE_SIZE) add_definitions(-DROCKSDB_MALLOC_USABLE_SIZE) endif() +check_cxx_symbol_exists(sched_getcpu sched.h HAVE_SCHED_GETCPU) +if(HAVE_SCHED_GETCPU) + add_definitions(-DROCKSDB_SCHED_GETCPU_PRESENT) +endif() + include_directories(${PROJECT_SOURCE_DIR}) include_directories(${PROJECT_SOURCE_DIR}/include) include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/third-party/gtest-1.7.0/fused-src) diff --git a/cmake/modules/FindNUMA.cmake b/cmake/modules/FindNUMA.cmake new file mode 100644 index 000000000..02760344c --- /dev/null +++ b/cmake/modules/FindNUMA.cmake @@ -0,0 +1,21 @@ +# - Find NUMA +# Find the NUMA library and includes +# +# NUMA_INCLUDE_DIR - where to find numa.h, etc. +# NUMA_LIBRARIES - List of libraries when using NUMA. +# NUMA_FOUND - True if NUMA found. + +find_path(NUMA_INCLUDE_DIR + NAMES numa.h numaif.h + HINTS ${NUMA_ROOT_DIR}/include) + +find_library(NUMA_LIBRARIES + NAMES numa + HINTS ${NUMA_ROOT_DIR}/lib) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(NUMA DEFAULT_MSG NUMA_LIBRARIES NUMA_INCLUDE_DIR) + +mark_as_advanced( + NUMA_LIBRARIES + NUMA_INCLUDE_DIR) diff --git a/cmake/modules/FindTBB.cmake b/cmake/modules/FindTBB.cmake new file mode 100644 index 000000000..f0289e7a1 --- /dev/null +++ b/cmake/modules/FindTBB.cmake @@ -0,0 +1,21 @@ +# - Find TBB +# Find the Thread Building Blocks library and includes +# +# TBB_INCLUDE_DIR - where to find tbb.h, etc. +# TBB_LIBRARIES - List of libraries when using TBB. +# TBB_FOUND - True if TBB found. + +find_path(TBB_INCLUDE_DIR +NAMES tbb/tbb.h +HINTS ${TBB_ROOT_DIR}/include) + +find_library(TBB_LIBRARIES +NAMES tbb +HINTS ${TBB_ROOT_DIR}/lib) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(TBB DEFAULT_MSG TBB_LIBRARIES TBB_INCLUDE_DIR) + +mark_as_advanced( +TBB_LIBRARIES +TBB_INCLUDE_DIR)