1
0
Fork 0
cmake_helpers/external/jemalloc/CMakeLists.txt
Ilya Fedin 10108ea237 Move libdl/libpthread handling to common_options
Setting -pthread makes linking libatomic manually unneeded
2022-01-05 12:54:40 +03:00

62 lines
1.8 KiB
CMake

# 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 (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
return()
endif()
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
-Wl,--push-state,--no-as-needed
PkgConfig::JEMALLOC
${JEMALLOC_LINK_LIBRARIES}
-Wl,--pop-state
)
return()
endif()
endif()
add_library(external_jemalloc_bundled STATIC IMPORTED)
include(ExternalProject)
ExternalProject_Add(jemalloc
URL ${third_party_loc}/jemalloc
CONFIGURE_COMMAND cd "<SOURCE_DIR>" && export EXTRA_CFLAGS=-fstack-protector-all\ -fPIC\ -D_FORTIFY_SOURCE=2 && export EXTRA_CXXFLAGS=-fstack-protector-all\ -fPIC\ -D_FORTIFY_SOURCE=2 && CC=clang CXX=clang++ ./autogen.sh
BUILD_IN_SOURCE 1
STEP_TARGETS build
EXCLUDE_FROM_ALL TRUE
BUILD_BYPRODUCTS <SOURCE_DIR>/lib/libjemalloc.a
)
ExternalProject_Get_property(jemalloc SOURCE_DIR)
file(MAKE_DIRECTORY "${SOURCE_DIR}/include")
set_target_properties(external_jemalloc_bundled PROPERTIES
IMPORTED_LOCATION "${SOURCE_DIR}/lib/libjemalloc.a"
)
target_include_directories(external_jemalloc_bundled SYSTEM
INTERFACE
${SOURCE_DIR}/include
)
add_dependencies(external_jemalloc_bundled jemalloc-build)
target_link_libraries(external_jemalloc
INTERFACE
-Wl,--push-state,--whole-archive
$<TARGET_FILE:external_jemalloc_bundled>
-Wl,--pop-state
external_jemalloc_bundled
)