1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| find_library(JEMALLOC_LIBRARY NAMES libjemalloc.a NAMES_PER_DIR)
if(JEMALLOC_LIBRARY) message(STATUS "Found static jemalloc: ${JEMALLOC_LIBRARY}") else() message(WARNING "Static jemalloc (libjemalloc.a) not found! Will fall back to standard libc allocator.") endif()
if(JEMALLOC_LIBRARY AND CMAKE_BUILD_TYPE STREQUAL "Release") message(STATUS "Statically linking jemalloc for performance optimization.")
target_link_libraries(${PROJECT_NAME} PRIVATE ${JEMALLOC_LIBRARY})
target_link_libraries(${PROJECT_NAME} PRIVATE ${CMAKE_DL_LIBS}) elseif(JEMALLOC_LIBRARY AND CMAKE_BUILD_TYPE STREQUAL "Debug") message(STATUS "Skipping jemalloc link in Debug mode to avoid conflict with AddressSanitizer/Valgrind.") endif()
|