summaryrefslogtreecommitdiff
path: root/source/luametatex/source/libraries/mimalloc/CMakeLists.txt
diff options
context:
space:
mode:
Diffstat (limited to 'source/luametatex/source/libraries/mimalloc/CMakeLists.txt')
-rw-r--r--source/luametatex/source/libraries/mimalloc/CMakeLists.txt70
1 files changed, 60 insertions, 10 deletions
diff --git a/source/luametatex/source/libraries/mimalloc/CMakeLists.txt b/source/luametatex/source/libraries/mimalloc/CMakeLists.txt
index 8127e0965..6cd826650 100644
--- a/source/luametatex/source/libraries/mimalloc/CMakeLists.txt
+++ b/source/luametatex/source/libraries/mimalloc/CMakeLists.txt
@@ -6,14 +6,16 @@ set(CMAKE_CXX_STANDARD 17)
option(MI_SECURE "Use full security mitigations (like guard pages, allocation randomization, double-free mitigation, and free-list corruption detection)" OFF)
option(MI_DEBUG_FULL "Use full internal heap invariant checking in DEBUG mode (expensive)" OFF)
-option(MI_PADDING "Enable padding to detect heap block overflow (used only in DEBUG mode)" ON)
+option(MI_PADDING "Enable padding to detect heap block overflow (used only in DEBUG mode or with Valgrind)" ON)
option(MI_OVERRIDE "Override the standard malloc interface (e.g. define entry points for malloc() etc)" ON)
option(MI_XMALLOC "Enable abort() call on memory allocation failure by default" OFF)
option(MI_SHOW_ERRORS "Show error and warning messages by default (only enabled by default in DEBUG mode)" OFF)
+option(MI_VALGRIND "Compile with Valgrind support (adds a small overhead)" OFF)
option(MI_USE_CXX "Use the C++ compiler to compile the library (instead of the C compiler)" OFF)
option(MI_SEE_ASM "Generate assembly files" OFF)
option(MI_OSX_INTERPOSE "Use interpose to override standard malloc on macOS" ON)
option(MI_OSX_ZONE "Use malloc zone to override standard malloc on macOS" ON)
+option(MI_WIN_REDIRECT "Use redirection module ('mimalloc-redirect') on Windows if compiling mimalloc as a DLL" ON)
option(MI_LOCAL_DYNAMIC_TLS "Use slightly slower, dlopen-compatible TLS mechanism (Unix)" OFF)
option(MI_BUILD_SHARED "Build shared library" ON)
option(MI_BUILD_STATIC "Build static library" ON)
@@ -28,6 +30,7 @@ option(MI_CHECK_FULL "Use full internal invariant checking in DEBUG mode
option(MI_INSTALL_TOPLEVEL "Install directly into $CMAKE_INSTALL_PREFIX instead of PREFIX/lib/mimalloc-version (deprecated)" OFF)
option(MI_USE_LIBATOMIC "Explicitly link with -latomic (on older systems) (deprecated and detected automatically)" OFF)
+include(CheckIncludeFiles)
include(GNUInstallDirs)
include("cmake/mimalloc-config-version.cmake")
@@ -103,9 +106,37 @@ if(MI_OVERRIDE)
endif()
endif()
+if(WIN32)
+ if (MI_WIN_REDIRECT)
+ if (MSVC_C_ARCHITECTURE_ID MATCHES "ARM")
+ message(STATUS "Cannot use redirection on Windows ARM (MI_WIN_REDIRECT=OFF)")
+ set(MI_WIN_REDIRECT OFF)
+ endif()
+ endif()
+ if (NOT MI_WIN_REDIRECT)
+ # use a negative define for backward compatibility
+ list(APPEND mi_defines MI_WIN_NOREDIRECT=1)
+ endif()
+endif()
+
if(MI_SECURE)
message(STATUS "Set full secure build (MI_SECURE=ON)")
list(APPEND mi_defines MI_SECURE=4)
+ #if (MI_VALGRIND)
+ # message(WARNING "Secure mode is a bit weakened when compiling with Valgrind support as buffer overflow detection is no longer byte-precise (if running without valgrind)")
+ #endif()
+endif()
+
+if(MI_VALGRIND)
+ CHECK_INCLUDE_FILES("valgrind/valgrind.h;valgrind/memcheck.h" MI_HAS_VALGRINDH)
+ if (NOT MI_HAS_VALGRINDH)
+ set(MI_VALGRIND OFF)
+ message(WARNING "Cannot find the 'valgrind/valgrind.h' and 'valgrind/memcheck.h' -- install valgrind first")
+ message(STATUS "Compile **without** Valgrind support (MI_VALGRIND=OFF)")
+ else()
+ message(STATUS "Compile with Valgrind support (MI_VALGRIND=ON)")
+ list(APPEND mi_defines MI_VALGRIND=1)
+ endif()
endif()
if(MI_SEE_ASM)
@@ -179,7 +210,7 @@ if(MI_USE_CXX)
if(CMAKE_CXX_COMPILER_ID MATCHES "AppleClang|Clang")
list(APPEND mi_cflags -Wno-deprecated)
endif()
- if(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
+ if(CMAKE_CXX_COMPILER_ID MATCHES "Intel" AND NOT CMAKE_CXX_COMPILER_ID MATCHES "IntelLLVM")
list(APPEND mi_cflags -Kc++)
endif()
endif()
@@ -217,18 +248,26 @@ endif()
# extra needed libraries
if(WIN32)
list(APPEND mi_libraries psapi shell32 user32 advapi32 bcrypt)
+ set(pc_libraries "-lpsapi -lshell32 -luser32 -ladvapi32 -lbcrypt")
else()
+ set(pc_libraries "")
find_library(MI_LIBPTHREAD pthread)
if (MI_LIBPTHREAD)
list(APPEND mi_libraries ${MI_LIBPTHREAD})
+ set(pc_libraries "${pc_libraries} -pthread")
endif()
find_library(MI_LIBRT rt)
if(MI_LIBRT)
list(APPEND mi_libraries ${MI_LIBRT})
+ set(pc_libraries "${pc_libraries} -lrt")
endif()
find_library(MI_LIBATOMIC atomic)
- if (MI_LIBATOMIC OR MI_USE_LIBATOMIC)
- list(APPEND mi_libraries atomic)
+ if (NOT MI_LIBATOMIC AND MI_USE_LIBATOMIC)
+ set(MI_LIBATOMIC atomic)
+ endif()
+ if (MI_LIBATOMIC)
+ list(APPEND mi_libraries ${MI_LIBATOMIC})
+ set(pc_libraries "${pc_libraries} -latomic")
endif()
endif()
@@ -251,16 +290,18 @@ else()
set(mi_install_cmakedir "${CMAKE_INSTALL_LIBDIR}/cmake/mimalloc-${mi_version}") # for cmake package info
endif()
-if(MI_SECURE)
- set(mi_basename "mimalloc-secure")
-else()
set(mi_basename "mimalloc")
+if(MI_SECURE)
+ set(mi_basename "${mi_basename}-secure")
+endif()
+if(MI_VALGRIND)
+ set(mi_basename "${mi_basename}-valgrind")
endif()
-
string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LC)
if(NOT(CMAKE_BUILD_TYPE_LC MATCHES "^(release|relwithdebinfo|minsizerel|none)$"))
set(mi_basename "${mi_basename}-${CMAKE_BUILD_TYPE_LC}") #append build type (e.g. -debug) if not a release version
endif()
+
if(MI_BUILD_SHARED)
list(APPEND mi_build_targets "shared")
endif()
@@ -304,8 +345,8 @@ if(MI_BUILD_SHARED)
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${mi_install_incdir}>
)
- if(WIN32)
- # On windows copy the mimalloc redirection dll too.
+ if(WIN32 AND MI_WIN_REDIRECT)
+ # On windows, link and copy the mimalloc redirection dll too.
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(MIMALLOC_REDIRECT_SUFFIX "32")
else()
@@ -376,6 +417,15 @@ if (MI_BUILD_OBJECT)
RENAME ${mi_basename}${CMAKE_C_OUTPUT_EXTENSION} )
endif()
+# pkg-config file support
+include("cmake/JoinPaths.cmake")
+join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
+join_paths(libdir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_LIBDIR}")
+
+configure_file(mimalloc.pc.in mimalloc.pc @ONLY)
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/mimalloc.pc"
+ DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/")
+
# -----------------------------------------------------------------------------
# API surface testing
# -----------------------------------------------------------------------------