Clean up (and optionalize) use of jemalloc

This commit is contained in:
Marcus Holland-Moritz 2020-12-30 13:13:05 +01:00
parent bb4b41ab3d
commit e681dcb097
2 changed files with 38 additions and 2 deletions

View File

@ -25,6 +25,7 @@ option(WITH_PYTHON "build with Python scripting support" OFF)
option(ENABLE_ASAN "enable address sanitizer" OFF)
option(ENABLE_TSAN "enable thread sanitizer" OFF)
option(ENABLE_UBSAN "enable undefined behaviour sanitizer" OFF)
option(USE_JEMALLOC "build with jemalloc" ON)
option(STATIC_BUILD_DO_NOT_USE "try static build (experimental)" OFF)
set(default_build_type "Release")
@ -43,6 +44,8 @@ set(DWARFS_VERSION
"${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}"
)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules")
if(STATIC_BUILD_DO_NOT_USE)
if(WITH_PYTHON)
message(FATAL_ERROR "python is not supported in static builds")
@ -100,7 +103,10 @@ endif()
find_path(SPARSEHASH_INCLUDE_DIR sparsehash/dense_hash_map
DOC "dense_hash_map header" REQUIRED)
find_program(RONN_EXE ronn DOC "ronn man page generator" REQUIRED)
find_library(JEMALLOC_LIBRARIES jemalloc DOC "jemalloc library" REQUIRED)
if(USE_JEMALLOC)
find_package(Jemalloc REQUIRED)
endif()
set(ZSTD_INCLUDE_DIR
""
@ -349,6 +355,10 @@ list(
${CMAKE_CURRENT_BINARY_DIR}
${SPARSEHASH_INCLUDE_DIR})
if(USE_JEMALLOC)
list(APPEND INCLUDE_DIRS ${Jemalloc_INCLUDE_DIRS})
endif()
add_library(
thrift_light
${CMAKE_CURRENT_SOURCE_DIR}/fbthrift/thrift/lib/cpp2/FieldRef.cpp
@ -393,6 +403,7 @@ foreach(tgt dwarfs ${BINARY_TARGETS})
PRIVATE DWARFS_VERSION=\"${DWARFS_VERSION}\"
DWARFS_HAVE_LIBZSTD
DWARFS_STATIC_BUILD=${STATIC_BUILD_DO_NOT_USE}
$<$<BOOL:${USE_JEMALLOC}>:DWARFS_USE_JEMALLOC>
$<$<BOOL:${LIBLZ4_FOUND}>:DWARFS_HAVE_LIBLZ4>
$<$<BOOL:${LIBLZMA_FOUND}>:DWARFS_HAVE_LIBLZMA>
$<$<BOOL:${WITH_PYTHON}>:DWARFS_HAVE_PYTHON>)
@ -437,7 +448,9 @@ target_link_libraries(
foreach(tgt ${BINARY_TARGETS})
target_link_libraries(${tgt} dwarfs)
target_link_libraries(${tgt} ${JEMALLOC_LIBRARIES})
if(USE_JEMALLOC)
target_link_libraries(${tgt} ${Jemalloc_LIBRARIES})
endif()
if(TARGET folly_exception_tracer)
target_link_libraries(
${tgt} -Wl,--whole-archive folly_exception_tracer_base

View File

@ -0,0 +1,23 @@
# * Find Jemalloc library Find the native Jemalloc includes and library
#
# Jemalloc_INCLUDE_DIRS - where to find jemalloc.h, etc. Jemalloc_LIBRARIES -
# List of libraries when using jemalloc. Jemalloc_FOUND - True if jemalloc
# found.
find_path(Jemalloc_INCLUDE_DIRS NAMES jemalloc/jemalloc.h)
find_library(Jemalloc_LIBRARIES NAMES jemalloc)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Jemalloc DEFAULT_MSG Jemalloc_LIBRARIES
Jemalloc_INCLUDE_DIRS)
mark_as_advanced(Jemalloc_LIBRARIES Jemalloc_INCLUDE_DIRS)
if(Jemalloc_FOUND AND NOT (TARGET Jemalloc::Jemalloc))
add_library(Jemalloc::Jemalloc UNKNOWN IMPORTED)
set_target_properties(
Jemalloc::Jemalloc
PROPERTIES IMPORTED_LOCATION ${Jemalloc_LIBRARIES}
INTERFACE_INCLUDE_DIRECTORIES ${Jemalloc_INCLUDE_DIRS})
endif()