add static library (#189)

* add static library

* leave static library on by default

* fix 1mib layout

* code reviews
This commit is contained in:
SchrodingerZhu
2020-05-19 13:46:40 +08:00
committed by GitHub
parent 6dae830ea0
commit 497f9d9386
2 changed files with 17 additions and 2 deletions

View File

@@ -15,8 +15,10 @@ option(USE_MEASURE "Measure performance with histograms" OFF)
option(EXPOSE_EXTERNAL_PAGEMAP "Expose the global pagemap" OFF)
option(EXPOSE_EXTERNAL_RESERVE "Expose an interface to reserve memory using the default memory provider" OFF)
option(SNMALLOC_RUST_SUPPORT "Build static library for rust" OFF)
option(SNMALLOC_STATIC_LIBRARY "Build static libraries" ON)
option(SNMALLOC_QEMU_WORKAROUND "Disable using madvise(DONT_NEED) to zero memory on Linux" Off)
set(CACHE_FRIENDLY_OFFSET OFF CACHE STRING "Base offset to place linked-list nodes.")
set(SNMALLOC_STATIC_LIBRARY_PREFIX "sn_" CACHE STRING "Static library function prefix")
CHECK_C_SOURCE_COMPILES("
#include <malloc.h>
@@ -228,6 +230,15 @@ if(NOT DEFINED SNMALLOC_ONLY_HEADER_LIBRARY)
endmacro()
if (SNMALLOC_STATIC_LIBRARY)
add_shim(snmallocshim-static STATIC src/override/malloc.cc)
add_shim(snmallocshim-1mib-static STATIC src/override/malloc.cc)
target_compile_definitions(snmallocshim-1mib-static PRIVATE IS_ADDRESS_SPACE_CONSTRAINED
SNMALLOC_STATIC_LIBRARY_PREFIX=${SNMALLOC_STATIC_LIBRARY_PREFIX})
target_compile_definitions(snmallocshim-static PRIVATE
SNMALLOC_STATIC_LIBRARY_PREFIX=${SNMALLOC_STATIC_LIBRARY_PREFIX})
endif ()
if(NOT WIN32)
set(SHARED_FILES src/override/new.cc src/override/malloc.cc)
add_shim(snmallocshim SHARED ${SHARED_FILES})

View File

@@ -9,8 +9,12 @@ using namespace snmalloc;
#ifndef SNMALLOC_EXPORT
# define SNMALLOC_EXPORT
#endif
#ifndef SNMALLOC_NAME_MANGLE
#ifdef SNMALLOC_STATIC_LIBRARY_PREFIX
# define __SN_CONCAT(a, b) a##b
# define __SN_EVALUATE(a, b) __SN_CONCAT(a, b)
# define SNMALLOC_NAME_MANGLE(a) \
__SN_EVALUATE(SNMALLOC_STATIC_LIBRARY_PREFIX, a)
#elif !defined(SNMALLOC_NAME_MANGLE)
# define SNMALLOC_NAME_MANGLE(a) a
#endif