diff --git a/CMakeLists.txt b/CMakeLists.txt index c0b942e..465f5f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,9 @@ # https://github.com/desktop-app/legal/blob/master/LEGAL add_subdirectory(external) +if (LINUX) + add_subdirectory(linux_jemalloc_helper) +endif() if (LINUX AND NOT DESKTOP_APP_USE_PACKAGED) add_subdirectory(linux_xcb_helper) endif() diff --git a/external/jemalloc/CMakeLists.txt b/external/jemalloc/CMakeLists.txt index 7b96e6e..39e1909 100644 --- a/external/jemalloc/CMakeLists.txt +++ b/external/jemalloc/CMakeLists.txt @@ -21,7 +21,7 @@ if (DESKTOP_APP_USE_PACKAGED) ${JEMALLOC_INCLUDE_DIRS} ) - target_link_options(external_jemalloc + target_link_libraries(external_jemalloc INTERFACE -Wl,--push-state,--no-as-needed,${JEMALLOC_LINK_LIBRARIES},--pop-state ) @@ -48,7 +48,7 @@ INTERFACE ${SOURCE_DIR}/include ) -target_link_options(external_jemalloc +target_link_libraries(external_jemalloc INTERFACE -Wl,--push-state,--whole-archive,${SOURCE_DIR}/lib/libjemalloc.a,--pop-state ) diff --git a/linux_jemalloc_helper/CMakeLists.txt b/linux_jemalloc_helper/CMakeLists.txt new file mode 100644 index 0000000..0466d8a --- /dev/null +++ b/linux_jemalloc_helper/CMakeLists.txt @@ -0,0 +1,19 @@ +# 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(linux_jemalloc_helper OBJECT) +init_target(linux_jemalloc_helper "(external)") +add_library(desktop-app::linux_jemalloc_helper ALIAS linux_jemalloc_helper) + +nice_target_sources(linux_jemalloc_helper ${CMAKE_CURRENT_SOURCE_DIR} +PRIVATE + linux_jemalloc_helper.cpp +) + +target_link_libraries(linux_jemalloc_helper +PRIVATE + desktop-app::external_jemalloc +) diff --git a/linux_jemalloc_helper/linux_jemalloc_helper.cpp b/linux_jemalloc_helper/linux_jemalloc_helper.cpp new file mode 100644 index 0000000..b6c0ad3 --- /dev/null +++ b/linux_jemalloc_helper/linux_jemalloc_helper.cpp @@ -0,0 +1,25 @@ +// 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 +// +#ifdef __FREEBSD__ +#include +#else // __FREEBSD__ +#include +#endif // !__FREEBSD__ + +namespace { + +class JemallocInitializer { +public: + JemallocInitializer() { + auto backgroundThread = true; + mallctl("background_thread", nullptr, nullptr, &backgroundThread, sizeof(bool)); + } +}; + +static const JemallocInitializer initializer; + +} // namespace diff --git a/options_linux.cmake b/options_linux.cmake index 65bd94a..ced5f8e 100644 --- a/options_linux.cmake +++ b/options_linux.cmake @@ -64,7 +64,8 @@ endif() target_link_libraries(common_options INTERFACE - desktop-app::external_jemalloc + desktop-app::linux_jemalloc_helper + $ ${CMAKE_DL_LIBS} )