Skip to content

Commit

Permalink
Allow linking alternate memory management implementations (openstreet…
Browse files Browse the repository at this point in the history
…map#454)

With new `CMake CACHE` entry `MALLOC_LIB`, supporting the following values:
* `libc` (default): Use the system's implementation
* `jemalloc`: Use [jemalloc](http://jemalloc.net)
* `mimalloc`: Use [mimalloc](https://github.com/microsoft/mimalloc)
* `tcmalloc`: Use [tcmalloc](https://github.com/google/tcmalloc)

Co-authored-by: Roland Bosa <[email protected]>
  • Loading branch information
hummeltech and rolandbosa authored Jun 29, 2024
1 parent c4e3e62 commit 0478a1b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ set(USE_CAIRO ON CACHE BOOL "Add cairo support if available (for `store_ro_compo
set(USE_CURL ON CACHE BOOL "Add curl support if available (for `store_ro_http_proxy.c` backend)")
set(USE_MEMCACHED ON CACHE BOOL "Add memcached support if available (for `store_memcached.c` backend)")
set(USE_RADOS ON CACHE BOOL "Add rados support if available (for `store_rados.c` backend)")
set(MALLOC_LIB "libc" CACHE STRING "Memory Management Library for `renderd`")
set_property(CACHE MALLOC_LIB PROPERTY STRINGS "libc" "jemalloc" "mimalloc" "tcmalloc")

#-----------------------------------------------------------------------------
#
Expand Down Expand Up @@ -90,6 +92,20 @@ if(NOT HAVE_POW)
find_library(MATH_LIBRARY m REQUIRED)
endif()

if(NOT MALLOC_LIB STREQUAL "libc")
message(STATUS "Using '${MALLOC_LIB}' for memory managment")
if(MALLOC_LIB STREQUAL "jemalloc")
# jemalloc (http://jemalloc.net)
find_library(MALLOC_LIBRARY jemalloc REQUIRED)
elseif(MALLOC_LIB STREQUAL "mimalloc")
# mimalloc (https://github.com/microsoft/mimalloc)
find_library(MALLOC_LIBRARY mimalloc REQUIRED)
elseif(MALLOC_LIB STREQUAL "tcmalloc")
# tcmalloc (https://github.com/google/tcmalloc)
find_library(MALLOC_LIBRARY tcmalloc REQUIRED)
endif()
endif()

#-----------------------------------------------------------------------------
#
# Set variables
Expand Down
6 changes: 5 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ set(RENDER_LIBRARIES
${COMMON_LIBRARIES}
${INIPARSER_LIBRARIES}
${MATH_LIBRARY}
Threads::Threads
)

set(STORE_SRCS
Expand All @@ -61,6 +60,11 @@ set(STORE_LIBRARIES
${LIBRADOS_LIBRARIES}
)

if(NOT MALLOC_LIB STREQUAL "libc")
message(STATUS "Prepending '${MALLOC_LIBRARY}' to RENDER_LIBRARIES")
list(PREPEND RENDER_LIBRARIES ${MALLOC_LIBRARY})
endif()

#-----------------------------------------------------------------------------
#
# Installed targets
Expand Down

0 comments on commit 0478a1b

Please sign in to comment.