From c2a557ee8566fb65667c9365b3091101eb32f5e7 Mon Sep 17 00:00:00 2001 From: ur4t <46435411+ur4t@users.noreply.github.com> Date: Fri, 19 Apr 2024 15:52:43 +0800 Subject: [PATCH 1/2] Fix JEMALLOC_PREFIX when `--with-jemalloc-prefix=` is absent. Output of `jemalloc-config` is arguments of the configuration script. This commit adds compatibility for `jemalloc`s which are configured with no `--with-jemalloc-prefix=` flag. --- src/CMakeLists.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 01a866e..763a973 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -131,9 +131,10 @@ function(jemalloc_config_run) OUTPUT_VARIABLE output OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL ANY) - string(REGEX REPLACE ".*--with-jemalloc-prefix=([^ ]*).*" "\\1" JEMALLOC_PREFIX ${output}) - if(${JEMALLOC_PREFIX} STREQUAL "") - set(${JEMALLOC_PREFIX} "${NONE}") + string(REGEX MATCH "--with-jemalloc-prefix=[^ ]*" JEMALLOC_PREFIX "${output}") + string(REPLACE "--with-jemalloc-prefix=" "" JEMALLOC_PREFIX "${JEMALLOC_PREFIX}") + if("${JEMALLOC_PREFIX}" STREQUAL "") + set(JEMALLOC_PREFIX "${NONE}") endif() # "Fun" quirk of CMake: a cache setting can't be straightforwardly modified from within a function. From c27a00ba1876d155ceece5a8e22598de138d1854 Mon Sep 17 00:00:00 2001 From: ur4t <46435411+ur4t@users.noreply.github.com> Date: Fri, 19 Apr 2024 16:05:21 +0800 Subject: [PATCH 2/2] Use `pkg-config` to find `jemalloc` if available. --- src/CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 763a973..44cbe1d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -54,6 +54,14 @@ set(DEP_LIBS_PKG_ARG_LISTS "IpcShm ${DEP_IPC_SHM_VERSION} CONFIG") # (TODO: but look into the jemalloc/jemalloc-cmake GitHub repo -- what's that all about?) # Hence we must ensure 2 things more manually: the lib location and the include-path. +# Try pkg-config if available +pkg_check_modules(JEMALLOC REQUIRED jemalloc) +if(JEMALLOC_FOUND) + set(JEMALLOC_LIB "${JEMALLOC_LIBRARIES}") + set(JEMALLOC_INCLUDE_PATH "${JEMALLOC_INCLUDEDIR}") + unset(JEMALLOC_PREFIX CACHE) +endif() + # Firstly: Finding the (static) library. This approach is recommended by FlowLikeLib.cmake docs. if(NOT JEMALLOC_LIB) block()