diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 166c4de4a..bafed6718 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -182,6 +182,9 @@ set(SRB2_CONFIG_STD23 OFF CACHE BOOL set(SRB2_CONFIG_COMPILEAPPIMAGE OFF CACHE BOOL "Compiles the game then attempts turning it into an appimage.") +set(SRB2_CONFIG_JEMALLOC OFF CACHE BOOL + "Links jemalloc Allocator to replace GLibc malloc.") + if(SRB2_CONFIG_COMPILEAPPIMAGE AND "${CMAKE_SYSTEM_NAME}" MATCHES "Linux") message("-- Generating Appimage at build time.") add_custom_command( @@ -204,6 +207,18 @@ else() set_property(TARGET BLANKART PROPERTY CXX_STANDARD 17) endif() +# Thanks https://stackoverflow.com/a/63320046 +if(SRB2_CONFIG_JEMALLOC) + message("-- Using JEMALLOC.") + find_package(PkgConfig REQUIRED) + pkg_check_modules(JEMALLOC jemalloc) + + pkg_search_module(JEMALLOC REQUIRED jemalloc) + include_directories(${JEMALLOC_INCLUDE_DIRS}) + + target_link_libraries(BLANKART PRIVATE ${JEMALLOC_LIBRARIES}) +endif() + ### Configuration set(SRB2_CONFIG_DEV_BUILD OFF CACHE BOOL "Compile a development build of SRB2Kart.")