@@ -74,9 +74,11 @@ endmacro ()
7474macro (valkey_build_and_install_bin target sources ld_flags libs link_name)
7575 add_executable (${target} ${sources} )
7676
77- if (USE_JEMALLOC)
78- # Using jemalloc
79- target_link_libraries (${target} jemalloc)
77+ if (USE_JEMALLOC
78+ OR USE_TCMALLOC
79+ OR USE_TCMALLOC_MINIMAL)
80+ # Using custom allocator
81+ target_link_libraries (${target} ${ALLOCATOR_LIB} )
8082 endif ()
8183
8284 # Place this line last to ensure that ${ld_flags} is placed last on the linker line
@@ -151,16 +153,23 @@ endif ()
151153if (BUILD_MALLOC)
152154 if ("${BUILD_MALLOC} " STREQUAL "jemalloc" )
153155 set (MALLOC_LIB "jemalloc" )
156+ set (ALLOCATOR_LIB "jemalloc" )
154157 add_valkey_server_compiler_options("-DUSE_JEMALLOC" )
155158 set (USE_JEMALLOC 1)
156159 elseif ("${BUILD_MALLOC} " STREQUAL "libc" )
157160 set (MALLOC_LIB "libc" )
158161 elseif ("${BUILD_MALLOC} " STREQUAL "tcmalloc" )
159162 set (MALLOC_LIB "tcmalloc" )
163+ valkey_pkg_config(libtcmalloc ALLOCATOR_LIB)
164+
160165 add_valkey_server_compiler_options("-DUSE_TCMALLOC" )
166+ set (USE_TCMALLOC 1)
161167 elseif ("${BUILD_MALLOC} " STREQUAL "tcmalloc_minimal" )
162168 set (MALLOC_LIB "tcmalloc_minimal" )
169+ valkey_pkg_config(libtcmalloc_minimal ALLOCATOR_LIB)
170+
163171 add_valkey_server_compiler_options("-DUSE_TCMALLOC" )
172+ set (USE_TCMALLOC_MINIMAL 1)
164173 else ()
165174 message (FATAL_ERROR "BUILD_MALLOC can be one of: jemalloc, libc, tcmalloc or tcmalloc_minimal" )
166175 endif ()
@@ -202,16 +211,12 @@ if (BUILD_RDMA)
202211 if (USE_RDMA EQUAL 2) # Module
203212 message (STATUS "Building RDMA as module" )
204213 add_valkey_server_compiler_options("-DUSE_RDMA=2" )
205- find_package (PkgConfig REQUIRED)
206214
207215 # Locate librdmacm & libibverbs, fail if we can't find them
208- pkg_check_modules(RDMACM REQUIRED librdmacm)
209- pkg_check_modules(IBVERBS REQUIRED libibverbs)
216+ valkey_pkg_config( librdmacm RDMACM_LIBS )
217+ valkey_pkg_config( libibverbs IBVERBS_LIBS )
210218
211- message (STATUS "${RDMACM_LINK_LIBRARIES} ;${IBVERBS_LINK_LIBRARIES} " )
212- list (APPEND RDMA_LIBS "${RDMACM_LIBRARIES} ;${IBVERBS_LIBRARIES} " )
213- unset (RDMACM_LINK_LIBRARIES CACHE )
214- unset (IBVERBS_LINK_LIBRARIES CACHE )
219+ list (APPEND RDMA_LIBS "${RDMACM_LIBS} ;${IBVERBS_LIBS} " )
215220 set (BUILD_RDMA_MODULE 1)
216221 elseif (USE_RDMA EQUAL 1)
217222 # RDMA can only be built as a module. So disable it
@@ -266,17 +271,18 @@ endif ()
266271
267272# Sanitizer
268273if (BUILD_SANITIZER)
269- # For best results, force libc
270- set (MALLOC_LIB, "libc" )
274+ # Common CFLAGS
275+ list (APPEND VALKEY_SANITAIZER_CFLAGS "-fno-sanitize-recover=all" )
276+ list (APPEND VALKEY_SANITAIZER_CFLAGS "-fno-omit-frame-pointer" )
271277 if ("${BUILD_SANITIZER} " STREQUAL "address" )
272- add_valkey_server_compiler_options( "-fsanitize=address -fno-sanitize-recover=all -fno-omit-frame-pointer " )
273- add_valkey_server_linker_option( "-fsanitize=address" )
278+ list ( APPEND VALKEY_SANITAIZER_CFLAGS "-fsanitize=address" )
279+ list ( APPEND VALKEY_SANITAIZER_LDFLAGS "-fsanitize=address" )
274280 elseif ("${BUILD_SANITIZER} " STREQUAL "thread" )
275- add_valkey_server_compiler_options( "-fsanitize=thread -fno-sanitize-recover=all -fno-omit-frame-pointer " )
276- add_valkey_server_linker_option( "-fsanitize=thread" )
281+ list ( APPEND VALKEY_SANITAIZER_CFLAGS "-fsanitize=thread" )
282+ list ( APPEND VALKEY_SANITAIZER_LDFLAGS "-fsanitize=thread" )
277283 elseif ("${BUILD_SANITIZER} " STREQUAL "undefined" )
278- add_valkey_server_compiler_options( "-fsanitize=undefined -fno-sanitize-recover=all -fno-omit-frame-pointer " )
279- add_valkey_server_linker_option( "-fsanitize=undefined" )
284+ list ( APPEND VALKEY_SANITAIZER_CFLAGS "-fsanitize=undefined" )
285+ list ( APPEND VALKEY_SANITAIZER_LDFLAGS "-fsanitize=undefined" )
280286 else ()
281287 message (FATAL_ERROR "Unknown sanitizer: ${BUILD_SANITIZER} " )
282288 endif ()
@@ -366,7 +372,6 @@ include(SourceFiles)
366372
367373# Clear the below variables from the cache
368374unset (CMAKE_C_FLAGS CACHE )
369- unset (BUILD_SANITIZER CACHE )
370375unset (VALKEY_SERVER_LDFLAGS CACHE )
371376unset (VALKEY_SERVER_CFLAGS CACHE )
372377unset (PYTHON_EXE CACHE )
0 commit comments