From 8d7772ab33f2b04efde728decd8ae265a461b185 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Wed, 30 Jun 2021 05:13:44 +0400 Subject: [PATCH] Switch from mallocng to jemalloc --- external/CMakeLists.txt | 6 ++-- external/jemalloc/CMakeLists.txt | 51 ++++++++++++++++++++++++++++++++ external/mallocng/CMakeLists.txt | 46 ---------------------------- options_linux.cmake | 5 ++++ 4 files changed, 59 insertions(+), 49 deletions(-) create mode 100644 external/jemalloc/CMakeLists.txt delete mode 100644 external/mallocng/CMakeLists.txt diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 91a7806..24b7a9a 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -36,14 +36,14 @@ if (add_hunspell_library) add_checked_subdirectory(hunspell) endif() add_checked_subdirectory(iconv) +if (LINUX) + add_checked_subdirectory(jemalloc) +endif() add_checked_subdirectory(jpeg) if (LINUX AND NOT DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION) add_checked_subdirectory(kwayland) endif() add_checked_subdirectory(lz4) -if (LINUX) - add_checked_subdirectory(mallocng) -endif() add_checked_subdirectory(minizip) if (LINUX) add_checked_subdirectory(nimf_qt5) diff --git a/external/jemalloc/CMakeLists.txt b/external/jemalloc/CMakeLists.txt new file mode 100644 index 0000000..084b79d --- /dev/null +++ b/external/jemalloc/CMakeLists.txt @@ -0,0 +1,51 @@ +# This file is part of Desktop App Toolkit, +# a set of libraries for developing nice desktop applications. +# +# For license and copyright information please follow this link: +# https://github.com/desktop-app/legal/blob/master/LEGAL + +add_library(external_jemalloc INTERFACE IMPORTED GLOBAL) +add_library(desktop-app::external_jemalloc ALIAS external_jemalloc) + +if (DESKTOP_APP_USE_PACKAGED) + find_package(PkgConfig REQUIRED) + pkg_check_modules(JEMALLOC IMPORTED_TARGET jemalloc) + + if (JEMALLOC_FOUND) + target_link_libraries(external_jemalloc INTERFACE PkgConfig::JEMALLOC) + endif() +endif() + +if (NOT JEMALLOC_FOUND) + add_library(external_jemalloc_bundled STATIC IMPORTED GLOBAL) + + include(ExternalProject) + ExternalProject_Add(jemalloc + URL https://github.com/jemalloc/jemalloc/releases/download/5.2.1/jemalloc-5.2.1.tar.bz2 + CONFIGURE_COMMAND cd "${CMAKE_CURRENT_BINARY_DIR}/jemalloc-prefix/src/jemalloc" && ./configure + BUILD_IN_SOURCE 1 + ) + + ExternalProject_Get_property(jemalloc SOURCE_DIR) + ExternalProject_Get_property(jemalloc BINARY_DIR) + + file(MAKE_DIRECTORY "${SOURCE_DIR}/include") + + set_target_properties(external_jemalloc_bundled PROPERTIES + IMPORTED_LOCATION "${BINARY_DIR}/lib/libjemalloc.a" + ) + + target_include_directories(external_jemalloc_bundled + INTERFACE + ${SOURCE_DIR}/include + ) + + add_dependencies(external_jemalloc_bundled jemalloc) + + target_link_libraries(external_jemalloc + INTERFACE + -Wl,--whole-archive + external_jemalloc_bundled + -Wl,--no-whole-archive + ) +endif() diff --git a/external/mallocng/CMakeLists.txt b/external/mallocng/CMakeLists.txt deleted file mode 100644 index c3d2422..0000000 --- a/external/mallocng/CMakeLists.txt +++ /dev/null @@ -1,46 +0,0 @@ -# This file is part of Desktop App Toolkit, -# a set of libraries for developing nice desktop applications. -# -# For license and copyright information please follow this link: -# https://github.com/desktop-app/legal/blob/master/LEGAL - -add_library(external_mallocng INTERFACE IMPORTED GLOBAL) -add_library(desktop-app::external_mallocng ALIAS external_mallocng) - -add_library(external_mallocng_bundled STATIC) -init_target(external_mallocng_bundled "(external)") - -set(mallocng_loc ${third_party_loc}/mallocng) - -nice_target_sources(external_mallocng_bundled ${mallocng_loc} -PRIVATE - malloc.c - calloc.c - free.c - realloc.c - aligned_alloc.c - posix_memalign.c - memalign.c - malloc_usable_size.c - meta.h - glue.h - valloc.c - pvalloc.c -) - -target_compile_options(external_mallocng_bundled -PRIVATE - -Wno-unused-value -) - -target_include_directories(external_mallocng_bundled -PRIVATE - ${mallocng_loc} -) - -target_link_libraries(external_mallocng -INTERFACE - -Wl,--whole-archive - external_mallocng_bundled - -Wl,--no-whole-archive -) diff --git a/options_linux.cmake b/options_linux.cmake index d586e79..ae687ff 100644 --- a/options_linux.cmake +++ b/options_linux.cmake @@ -48,6 +48,11 @@ if (DESKTOP_APP_SPECIAL_TARGET) endif() endif() +target_link_libraries(common_options +INTERFACE + desktop-app::external_jemalloc +) + if (DESKTOP_APP_USE_PACKAGED) find_library(ATOMIC_LIBRARY atomic) else()