feat(build): add build option for jemalloc
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
368c94ccc5
commit
e81d96ffc1
3 changed files with 61 additions and 12 deletions
|
@ -13,6 +13,8 @@ option(STATIC "STATIC" OFF)
|
|||
option(SPLIT_STACK "SPLIT_STACK" OFF)
|
||||
option(READLINE "READLINE" OFF)
|
||||
option(CACHE_EXPRS "CACHE_EXPRS" ON)
|
||||
option(TCMALLOC "TCMALLOC" ON)
|
||||
option(JEMALLOC "JEMALLOC" OFF)
|
||||
|
||||
# Added for CTest
|
||||
include(CTest)
|
||||
|
@ -124,19 +126,32 @@ if("${TRACK_MEMORY_USAGE}" MATCHES "ON")
|
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D LEAN_TRACK_MEMORY")
|
||||
endif()
|
||||
|
||||
# tcmalloc
|
||||
option(TCMALLOC "TCMALLOC" ON)
|
||||
if("${TCMALLOC}" MATCHES "ON")
|
||||
find_package(Tcmalloc)
|
||||
if(${TCMALLOC_FOUND})
|
||||
set(EXTRA_LIBS ${EXTRA_LIBS} ${TCMALLOC_LIBRARIES})
|
||||
message(STATUS "Using tcmalloc.")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D HAS_TCMALLOC")
|
||||
# jemalloc
|
||||
if("${JEMALLOC}" MATCHES "ON")
|
||||
find_package(Jemalloc)
|
||||
if(${JEMALLOC_FOUND})
|
||||
set(EXTRA_LIBS ${EXTRA_LIBS} ${JEMALLOC_LIBRARIES})
|
||||
message(STATUS "Using jemalloc.")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D HAS_JEMALLOC")
|
||||
else()
|
||||
message(WARNING "FAILED to find tcmalloc, using standard malloc.")
|
||||
message(WARNING "FAILED to find jemalloc, will try tcmalloc and then standard malloc.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# tcmalloc
|
||||
if(NOT "${JEMALLOC_FOUND}")
|
||||
if("${TCMALLOC}" MATCHES "ON")
|
||||
find_package(Tcmalloc)
|
||||
if(${TCMALLOC_FOUND})
|
||||
set(EXTRA_LIBS ${EXTRA_LIBS} ${TCMALLOC_LIBRARIES})
|
||||
message(STATUS "Using tcmalloc.")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D HAS_TCMALLOC")
|
||||
else()
|
||||
message(WARNING "FAILED to find tcmalloc, using standard malloc.")
|
||||
endif()
|
||||
else()
|
||||
message(STATUS "Using standard malloc.")
|
||||
endif()
|
||||
else()
|
||||
message(STATUS "Using standard malloc.")
|
||||
endif()
|
||||
|
||||
# Readline
|
||||
|
@ -148,7 +163,7 @@ if("${READLINE}" MATCHES "ON")
|
|||
endif()
|
||||
|
||||
# Check malloc_usable_size
|
||||
if(NOT "${TCMALLOC_FOUND}" AND "${TRACK_MEMORY_USAGE}" MATCHES "ON")
|
||||
if(NOT "${TCMALLOC_FOUND}" AND NOT "${JEMALLOC_FOUND}" AND "${TRACK_MEMORY_USAGE}" MATCHES "ON")
|
||||
find_package(MallocUsableSize)
|
||||
if("${MUS_FOUND}" MATCHES "TRUE")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I ${MALLOC_DIR} -D HAS_MALLOC_USABLE_SIZE")
|
||||
|
|
8
src/cmake/Modules/CheckJemalloc.cc
Normal file
8
src/cmake/Modules/CheckJemalloc.cc
Normal file
|
@ -0,0 +1,8 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <jemalloc/jemalloc.h>
|
||||
|
||||
int main() {
|
||||
printf("%d.%d.%d", JEMALLOC_VERSION_MAJOR, JEMALLOC_VERSION_MINOR, JEMALLOC_VERSION_BUGFIX);
|
||||
return 0;
|
||||
}
|
26
src/cmake/Modules/FindJemalloc.cmake
Normal file
26
src/cmake/Modules/FindJemalloc.cmake
Normal file
|
@ -0,0 +1,26 @@
|
|||
if (JEMALLOC_INCLUDE_DIR AND JEMALLOC_LIBRARIES)
|
||||
# Already in cache, be silent
|
||||
set(JEMALLOC_FIND_QUIETLY TRUE)
|
||||
endif (JEMALLOC_INCLUDE_DIR AND JEMALLOC_LIBRARIES)
|
||||
|
||||
find_path(JEMALLOC_INCLUDE_DIR NAMES jemalloc/jemalloc.h)
|
||||
find_library(JEMALLOC_LIBRARIES NAMES jemalloc)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(JEMALLOC DEFAULT_MSG JEMALLOC_INCLUDE_DIR JEMALLOC_LIBRARIES)
|
||||
|
||||
# Print out version number
|
||||
if (JEMALLOC_FOUND)
|
||||
try_run(JE_CHECK JE_CHECK_BUILD
|
||||
${LEAN_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
|
||||
${LEAN_SOURCE_DIR}/cmake/Modules/CheckJemalloc.cc
|
||||
CMAKE_FLAGS -DINCLUDE_DIRECTORIES=${JEMALLOC_INCLUDE_DIR}
|
||||
-DLINK_LIBRARIES=${JEMALLOC_LIBRARIES}
|
||||
RUN_OUTPUT_VARIABLE JE_TRY_OUT)
|
||||
message("-- Found JEMALLOC: version ${JE_TRY_OUT}")
|
||||
else ()
|
||||
message("*** WARNING: failed to find jemalloc")
|
||||
message("*** The (optional) jemalloc library is available at: https://github.com/jemalloc/jemalloc")
|
||||
endif ()
|
||||
|
||||
mark_as_advanced(JEMALLOC_INCLUDE_DIR JEMALLOC_LIBRARIES)
|
Loading…
Reference in a new issue