Skip to content

Commit 0478a1b

Browse files
Allow linking alternate memory management implementations (openstreetmap#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]>
1 parent c4e3e62 commit 0478a1b

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ set(USE_CAIRO ON CACHE BOOL "Add cairo support if available (for `store_ro_compo
3232
set(USE_CURL ON CACHE BOOL "Add curl support if available (for `store_ro_http_proxy.c` backend)")
3333
set(USE_MEMCACHED ON CACHE BOOL "Add memcached support if available (for `store_memcached.c` backend)")
3434
set(USE_RADOS ON CACHE BOOL "Add rados support if available (for `store_rados.c` backend)")
35+
set(MALLOC_LIB "libc" CACHE STRING "Memory Management Library for `renderd`")
36+
set_property(CACHE MALLOC_LIB PROPERTY STRINGS "libc" "jemalloc" "mimalloc" "tcmalloc")
3537

3638
#-----------------------------------------------------------------------------
3739
#
@@ -90,6 +92,20 @@ if(NOT HAVE_POW)
9092
find_library(MATH_LIBRARY m REQUIRED)
9193
endif()
9294

95+
if(NOT MALLOC_LIB STREQUAL "libc")
96+
message(STATUS "Using '${MALLOC_LIB}' for memory managment")
97+
if(MALLOC_LIB STREQUAL "jemalloc")
98+
# jemalloc (http://jemalloc.net)
99+
find_library(MALLOC_LIBRARY jemalloc REQUIRED)
100+
elseif(MALLOC_LIB STREQUAL "mimalloc")
101+
# mimalloc (https://github.com/microsoft/mimalloc)
102+
find_library(MALLOC_LIBRARY mimalloc REQUIRED)
103+
elseif(MALLOC_LIB STREQUAL "tcmalloc")
104+
# tcmalloc (https://github.com/google/tcmalloc)
105+
find_library(MALLOC_LIBRARY tcmalloc REQUIRED)
106+
endif()
107+
endif()
108+
93109
#-----------------------------------------------------------------------------
94110
#
95111
# Set variables

src/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ set(RENDER_LIBRARIES
4141
${COMMON_LIBRARIES}
4242
${INIPARSER_LIBRARIES}
4343
${MATH_LIBRARY}
44-
Threads::Threads
4544
)
4645

4746
set(STORE_SRCS
@@ -61,6 +60,11 @@ set(STORE_LIBRARIES
6160
${LIBRADOS_LIBRARIES}
6261
)
6362

63+
if(NOT MALLOC_LIB STREQUAL "libc")
64+
message(STATUS "Prepending '${MALLOC_LIBRARY}' to RENDER_LIBRARIES")
65+
list(PREPEND RENDER_LIBRARIES ${MALLOC_LIBRARY})
66+
endif()
67+
6468
#-----------------------------------------------------------------------------
6569
#
6670
# Installed targets

0 commit comments

Comments
 (0)