|
| 1 | +# This file is part of Desktop App Toolkit, |
| 2 | +# a set of libraries for developing nice desktop applications. |
| 3 | +# |
| 4 | +# For license and copyright information please follow this link: |
| 5 | +# https://github.com/desktop-app/legal/blob/master/LEGAL |
| 6 | + |
| 7 | +add_library(external_jemalloc INTERFACE IMPORTED GLOBAL) |
| 8 | +add_library(desktop-app::external_jemalloc ALIAS external_jemalloc) |
| 9 | + |
| 10 | +if (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") |
| 11 | + return() |
| 12 | +endif() |
| 13 | + |
| 14 | +if (DESKTOP_APP_USE_PACKAGED) |
| 15 | + find_package(PkgConfig REQUIRED) |
| 16 | + pkg_check_modules(JEMALLOC jemalloc) |
| 17 | + |
| 18 | + if (JEMALLOC_FOUND) |
| 19 | + target_include_directories(external_jemalloc SYSTEM |
| 20 | + INTERFACE |
| 21 | + ${JEMALLOC_INCLUDE_DIRS} |
| 22 | + ) |
| 23 | + |
| 24 | + target_link_libraries(external_jemalloc |
| 25 | + INTERFACE |
| 26 | + -Wl,--push-state,--no-as-needed,${JEMALLOC_LINK_LIBRARIES},--pop-state |
| 27 | + ) |
| 28 | + |
| 29 | + return() |
| 30 | + endif() |
| 31 | +endif() |
| 32 | + |
| 33 | +include(ProcessorCount) |
| 34 | +ProcessorCount(N) |
| 35 | + |
| 36 | +include(ExternalProject) |
| 37 | +ExternalProject_Add(jemalloc |
| 38 | + URL ${third_party_loc}/jemalloc |
| 39 | + CONFIGURE_COMMAND env |
| 40 | + "$<IF:$<OR:$<NOT:$<BOOL:${DESKTOP_APP_USE_PACKAGED}>>,$<BOOL:${DESKTOP_APP_SPECIAL_TARGET}>>,EXTRA_CFLAGS=-fno-omit-frame-pointer -fstack-protector-all -fstack-clash-protection -fcf-protection -DNDEBUG -D_FORTIFY_SOURCE=3 -D_GLIBCXX_ASSERTIONS,=>" |
| 41 | + "$<IF:$<OR:$<NOT:$<BOOL:${DESKTOP_APP_USE_PACKAGED}>>,$<BOOL:${DESKTOP_APP_SPECIAL_TARGET}>>,EXTRA_CXXFLAGS=-fno-omit-frame-pointer -fstack-protector-all -fstack-clash-protection -fcf-protection -DNDEBUG -D_FORTIFY_SOURCE=3 -D_GLIBCXX_ASSERTIONS,=>" |
| 42 | + ./autogen.sh --disable-shared |
| 43 | + BUILD_COMMAND make $<$<NOT:$<EQUAL:${N},0>>:-j${N}> |
| 44 | + BUILD_IN_SOURCE 1 |
| 45 | + STEP_TARGETS build |
| 46 | + EXCLUDE_FROM_ALL TRUE |
| 47 | + BUILD_BYPRODUCTS <SOURCE_DIR>/lib/libjemalloc_pic.a |
| 48 | +) |
| 49 | + |
| 50 | +ExternalProject_Get_property(jemalloc SOURCE_DIR) |
| 51 | +file(MAKE_DIRECTORY "${SOURCE_DIR}/include") |
| 52 | + |
| 53 | +target_include_directories(external_jemalloc SYSTEM |
| 54 | +INTERFACE |
| 55 | + ${SOURCE_DIR}/include |
| 56 | +) |
| 57 | + |
| 58 | +target_link_libraries(external_jemalloc |
| 59 | +INTERFACE |
| 60 | + -Wl,--push-state,--whole-archive,${SOURCE_DIR}/lib/libjemalloc_pic.a,--pop-state |
| 61 | +) |
| 62 | + |
| 63 | +add_dependencies(external_jemalloc jemalloc-build) |
0 commit comments