2019-06-20 02:52:36 +03:00
|
|
|
cmake_minimum_required(VERSION 3.0)
|
2019-07-08 04:11:21 +03:00
|
|
|
project(libmimalloc C CXX)
|
2019-11-02 08:01:52 +03:00
|
|
|
|
2019-06-20 02:52:36 +03:00
|
|
|
set(CMAKE_C_STANDARD 11)
|
2019-07-08 04:11:21 +03:00
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
2019-06-20 02:52:36 +03:00
|
|
|
|
2019-11-22 02:21:23 +03:00
|
|
|
option(MI_SECURE "Use full security mitigations (like guard pages, allocation randomization, double-free mitigation, and free-list corruption detection)" OFF)
|
2020-05-04 21:01:11 +03:00
|
|
|
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_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_USE_CXX "Use the C++ compiler to compile the library (instead of the C compiler)" OFF)
|
2019-11-14 22:01:05 +03:00
|
|
|
option(MI_SEE_ASM "Generate assembly files" OFF)
|
2020-02-09 07:08:52 +03:00
|
|
|
option(MI_INTERPOSE "Use interpose to override standard malloc on macOS" ON)
|
|
|
|
option(MI_OSX_ZONE "Use malloc zone to override standard malloc on macOS" OFF) # enables interpose as well
|
2019-09-04 13:02:16 +03:00
|
|
|
option(MI_LOCAL_DYNAMIC_TLS "Use slightly slower, dlopen-compatible TLS mechanism (Unix)" OFF)
|
2020-04-28 18:12:43 +03:00
|
|
|
option(MI_BUILD_SHARED "Build shared library" ON)
|
|
|
|
option(MI_BUILD_STATIC "Build static library" ON)
|
2020-05-04 21:01:11 +03:00
|
|
|
option(MI_BUILD_OBJECT "Build object library" ON)
|
|
|
|
option(MI_BUILD_TESTS "Build test executables" ON)
|
|
|
|
option(MI_CHECK_FULL "Use full internal invariant checking in DEBUG mode (deprecated, use MI_DEBUG_FULL instead)" OFF)
|
2019-06-20 02:52:36 +03:00
|
|
|
|
2019-11-04 00:34:54 +03:00
|
|
|
include("cmake/mimalloc-config-version.cmake")
|
|
|
|
|
2019-06-20 02:52:36 +03:00
|
|
|
set(mi_sources
|
|
|
|
src/stats.c
|
2019-12-23 04:07:01 +03:00
|
|
|
src/random.c
|
2019-06-20 02:52:36 +03:00
|
|
|
src/os.c
|
2019-11-02 06:19:00 +03:00
|
|
|
src/arena.c
|
2020-01-26 00:28:49 +03:00
|
|
|
src/region.c
|
2019-06-20 02:52:36 +03:00
|
|
|
src/segment.c
|
|
|
|
src/page.c
|
|
|
|
src/alloc.c
|
|
|
|
src/alloc-aligned.c
|
2019-07-07 23:44:33 +03:00
|
|
|
src/alloc-posix.c
|
2019-06-20 02:52:36 +03:00
|
|
|
src/heap.c
|
|
|
|
src/options.c
|
|
|
|
src/init.c)
|
|
|
|
|
2019-11-14 22:01:05 +03:00
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# Converience: set default build type depending on the build directory
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
2019-06-20 02:52:36 +03:00
|
|
|
if (NOT CMAKE_BUILD_TYPE)
|
2019-11-14 22:01:05 +03:00
|
|
|
if ("${CMAKE_BINARY_DIR}" MATCHES ".*(D|d)ebug$" OR MI_DEBUG_FULL MATCHES "ON")
|
|
|
|
message(STATUS "No build type selected, default to: Debug")
|
2019-06-20 02:52:36 +03:00
|
|
|
set(CMAKE_BUILD_TYPE "Debug")
|
|
|
|
else()
|
2019-11-14 22:01:05 +03:00
|
|
|
message(STATUS "No build type selected, default to: Release")
|
2019-06-20 02:52:36 +03:00
|
|
|
set(CMAKE_BUILD_TYPE "Release")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if("${CMAKE_BINARY_DIR}" MATCHES ".*(S|s)ecure$")
|
2019-11-14 22:01:05 +03:00
|
|
|
message(STATUS "Default to secure build")
|
2019-06-25 04:54:03 +03:00
|
|
|
set(MI_SECURE "ON")
|
2019-06-20 02:52:36 +03:00
|
|
|
endif()
|
|
|
|
|
2019-11-14 22:01:05 +03:00
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# Process options
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
2020-01-20 05:35:45 +03:00
|
|
|
if(CMAKE_C_COMPILER_ID MATCHES "MSVC|Intel")
|
2019-07-23 19:59:20 +03:00
|
|
|
set(MI_USE_CXX "ON")
|
|
|
|
endif()
|
|
|
|
|
2019-06-25 04:54:03 +03:00
|
|
|
if(MI_OVERRIDE MATCHES "ON")
|
|
|
|
message(STATUS "Override standard malloc (MI_OVERRIDE=ON)")
|
2019-06-20 02:52:36 +03:00
|
|
|
if(APPLE)
|
2020-02-09 07:08:52 +03:00
|
|
|
if(MI_OSX_ZONE MATCHES "ON")
|
|
|
|
# use zone's on macOS
|
|
|
|
message(STATUS " Use malloc zone to override malloc (MI_OSX_ZONE=ON)")
|
|
|
|
list(APPEND mi_sources src/alloc-override-osx.c)
|
2020-04-21 15:08:27 +03:00
|
|
|
list(APPEND mi_defines MI_OSX_ZONE=1)
|
2020-02-09 07:08:52 +03:00
|
|
|
if(NOT MI_INTERPOSE MATCHES "ON")
|
|
|
|
message(STATUS " (enabling INTERPOSE as well since zone's require this)")
|
|
|
|
set(MI_INTERPOSE "ON")
|
|
|
|
endif()
|
|
|
|
endif()
|
2019-06-25 04:54:03 +03:00
|
|
|
if(MI_INTERPOSE MATCHES "ON")
|
2019-06-23 10:29:41 +03:00
|
|
|
# use interpose on macOS
|
2019-06-25 04:54:03 +03:00
|
|
|
message(STATUS " Use interpose to override malloc (MI_INTERPOSE=ON)")
|
2019-06-20 02:52:36 +03:00
|
|
|
list(APPEND mi_defines MI_INTERPOSE)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2019-11-22 02:21:23 +03:00
|
|
|
if(MI_SECURE MATCHES "ON")
|
|
|
|
message(STATUS "Set full secure build (MI_SECURE=ON)")
|
2019-11-07 21:26:52 +03:00
|
|
|
list(APPEND mi_defines MI_SECURE=4)
|
2019-06-20 02:52:36 +03:00
|
|
|
endif()
|
|
|
|
|
2019-06-25 04:54:03 +03:00
|
|
|
if(MI_SEE_ASM MATCHES "ON")
|
|
|
|
message(STATUS "Generate assembly listings (MI_SEE_ASM=ON)")
|
2019-06-20 02:52:36 +03:00
|
|
|
list(APPEND mi_cflags -save-temps)
|
|
|
|
endif()
|
|
|
|
|
2019-06-25 04:54:03 +03:00
|
|
|
if(MI_CHECK_FULL MATCHES "ON")
|
2019-11-14 22:01:05 +03:00
|
|
|
message(STATUS "The MI_CHECK_FULL option is deprecated, use MI_DEBUG_FULL instead")
|
|
|
|
set(MI_DEBUG_FULL "ON")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(MI_DEBUG_FULL MATCHES "ON")
|
2019-11-22 02:21:23 +03:00
|
|
|
message(STATUS "Set debug level to full internal invariant checking (MI_DEBUG_FULL=ON)")
|
2019-06-20 02:52:36 +03:00
|
|
|
list(APPEND mi_defines MI_DEBUG=3) # full invariant checking
|
|
|
|
endif()
|
|
|
|
|
2020-04-07 20:01:18 +03:00
|
|
|
if(MI_PADDING MATCHES "OFF")
|
|
|
|
message(STATUS "Disable padding of heap blocks in debug mode (MI_PADDING=OFF)")
|
|
|
|
list(APPEND mi_defines MI_PADDING=0)
|
|
|
|
endif()
|
|
|
|
|
2020-04-21 11:39:57 +03:00
|
|
|
if(MI_XMALLOC MATCHES "ON")
|
|
|
|
message(STATUS "Enable abort() calls on memory allocation failure (MI_XMALLOC=ON)")
|
|
|
|
list(APPEND mi_defines MI_XMALLOC=1)
|
|
|
|
endif()
|
|
|
|
|
2020-04-21 10:27:42 +03:00
|
|
|
if(MI_SHOW_ERRORS MATCHES "ON")
|
|
|
|
message(STATUS "Enable printing of error and warning messages by default (MI_SHOW_ERRORS=ON)")
|
|
|
|
list(APPEND mi_defines MI_SHOW_ERRORS=1)
|
|
|
|
endif()
|
|
|
|
|
2019-06-25 04:54:03 +03:00
|
|
|
if(MI_USE_CXX MATCHES "ON")
|
|
|
|
message(STATUS "Use the C++ compiler to compile (MI_USE_CXX=ON)")
|
2019-06-20 02:52:36 +03:00
|
|
|
set_source_files_properties(${mi_sources} PROPERTIES LANGUAGE CXX )
|
2020-01-20 05:35:45 +03:00
|
|
|
set_source_files_properties(src/static.c test/test-api.c test/test-stress PROPERTIES LANGUAGE CXX )
|
2020-01-18 02:39:41 +03:00
|
|
|
if(CMAKE_CXX_COMPILER_ID MATCHES "AppleClang|Clang")
|
|
|
|
list(APPEND mi_cflags -Wno-deprecated)
|
|
|
|
endif()
|
2020-01-20 05:35:45 +03:00
|
|
|
if(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
|
|
|
|
list(APPEND mi_cflags -Kc++)
|
|
|
|
endif()
|
2019-06-20 02:52:36 +03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Compiler flags
|
|
|
|
if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang|GNU")
|
2020-01-23 21:31:47 +03:00
|
|
|
list(APPEND mi_cflags -Wall -Wextra -Wno-unknown-pragmas -fvisibility=hidden)
|
2020-01-20 05:35:45 +03:00
|
|
|
if(CMAKE_C_COMPILER_ID MATCHES "GNU")
|
|
|
|
list(APPEND mi_cflags -Wno-invalid-memory-model)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CMAKE_C_COMPILER_ID MATCHES "Intel")
|
|
|
|
list(APPEND mi_cflags -Wall -fvisibility=hidden)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang|GNU|Intel")
|
2019-09-04 13:02:16 +03:00
|
|
|
if(MI_LOCAL_DYNAMIC_TLS MATCHES "ON")
|
|
|
|
list(APPEND mi_cflags -ftls-model=local-dynamic)
|
|
|
|
else()
|
|
|
|
list(APPEND mi_cflags -ftls-model=initial-exec)
|
|
|
|
endif()
|
2019-06-20 02:52:36 +03:00
|
|
|
endif()
|
|
|
|
|
2020-03-07 12:18:45 +03:00
|
|
|
# Architecture flags
|
2020-03-07 15:19:48 +03:00
|
|
|
if(${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "arm")
|
2020-03-07 12:18:45 +03:00
|
|
|
list(APPEND mi_cflags -march=native)
|
|
|
|
endif()
|
|
|
|
|
2019-06-20 02:52:36 +03:00
|
|
|
# extra needed libraries
|
|
|
|
if(WIN32)
|
2019-12-23 04:07:01 +03:00
|
|
|
list(APPEND mi_libraries psapi shell32 user32 bcrypt)
|
2019-06-20 02:52:36 +03:00
|
|
|
else()
|
2020-04-15 07:34:07 +03:00
|
|
|
if(NOT ${CMAKE_C_COMPILER} MATCHES "android")
|
2020-04-14 16:20:56 +03:00
|
|
|
list(APPEND mi_libraries pthread)
|
|
|
|
find_library(LIBRT rt)
|
|
|
|
if(LIBRT)
|
|
|
|
list(APPEND mi_libraries ${LIBRT})
|
|
|
|
endif()
|
2019-08-24 16:24:56 +03:00
|
|
|
endif()
|
2019-06-20 02:52:36 +03:00
|
|
|
endif()
|
|
|
|
|
2019-06-27 23:36:19 +03:00
|
|
|
# -----------------------------------------------------------------------------
|
2019-11-14 22:01:05 +03:00
|
|
|
# Install and output names
|
2019-06-27 23:36:19 +03:00
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
2019-11-14 22:01:05 +03:00
|
|
|
set(mi_install_dir "${CMAKE_INSTALL_PREFIX}/lib/mimalloc-${mi_version}")
|
|
|
|
if(MI_SECURE MATCHES "ON")
|
|
|
|
set(mi_basename "mimalloc-secure")
|
|
|
|
else()
|
|
|
|
set(mi_basename "mimalloc")
|
|
|
|
endif()
|
|
|
|
string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LC)
|
|
|
|
if(NOT(CMAKE_BUILD_TYPE_LC MATCHES "^(release|relwithdebinfo|minsizerel)$"))
|
|
|
|
set(mi_basename "${mi_basename}-${CMAKE_BUILD_TYPE_LC}") #append build type (e.g. -debug) if not a release version
|
|
|
|
endif()
|
2020-05-04 21:01:11 +03:00
|
|
|
if(MI_BUILD_SHARED)
|
|
|
|
list(APPEND mi_build_targets "shared")
|
|
|
|
endif()
|
|
|
|
if(MI_BUILD_STATIC)
|
|
|
|
list(APPEND mi_build_targets "static")
|
|
|
|
endif()
|
|
|
|
if(MI_BUILD_OBJECT)
|
|
|
|
list(APPEND mi_build_targets "object")
|
|
|
|
endif()
|
|
|
|
if(MI_BUILD_TESTS)
|
|
|
|
list(APPEND mi_build_targets "tests")
|
|
|
|
endif()
|
2019-11-14 22:01:05 +03:00
|
|
|
message(STATUS "")
|
|
|
|
message(STATUS "Library base name: ${mi_basename}")
|
|
|
|
message(STATUS "Build type : ${CMAKE_BUILD_TYPE_LC}")
|
|
|
|
message(STATUS "Install directory: ${mi_install_dir}")
|
2020-05-04 21:01:11 +03:00
|
|
|
message(STATUS "Build targets : ${mi_build_targets}")
|
2019-11-14 22:01:05 +03:00
|
|
|
message(STATUS "")
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# Main targets
|
|
|
|
# -----------------------------------------------------------------------------
|
2019-06-20 02:52:36 +03:00
|
|
|
|
|
|
|
# shared library
|
2020-04-28 18:12:43 +03:00
|
|
|
if(MI_BUILD_SHARED)
|
|
|
|
add_library(mimalloc SHARED ${mi_sources})
|
|
|
|
set_target_properties(mimalloc PROPERTIES VERSION ${mi_version} OUTPUT_NAME ${mi_basename} )
|
|
|
|
target_compile_definitions(mimalloc PRIVATE ${mi_defines} MI_SHARED_LIB MI_SHARED_LIB_EXPORT)
|
|
|
|
target_compile_options(mimalloc PRIVATE ${mi_cflags})
|
|
|
|
target_link_libraries(mimalloc PUBLIC ${mi_libraries})
|
|
|
|
target_include_directories(mimalloc PUBLIC
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
|
|
|
$<INSTALL_INTERFACE:${mi_install_dir}/include>
|
|
|
|
)
|
|
|
|
if(WIN32)
|
|
|
|
# On windows copy the mimalloc redirection dll too.
|
|
|
|
target_link_libraries(mimalloc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/bin/mimalloc-redirect.lib)
|
|
|
|
add_custom_command(TARGET mimalloc POST_BUILD
|
|
|
|
COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/bin/mimalloc-redirect.dll" $<TARGET_FILE_DIR:mimalloc>
|
|
|
|
COMMENT "Copy mimalloc-redirect.dll to output directory")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
install(TARGETS mimalloc EXPORT mimalloc DESTINATION ${mi_install_dir} LIBRARY)
|
|
|
|
install(EXPORT mimalloc DESTINATION ${mi_install_dir}/cmake)
|
2019-07-23 19:36:58 +03:00
|
|
|
endif()
|
2019-06-20 02:52:36 +03:00
|
|
|
|
|
|
|
# static library
|
2020-04-28 18:12:43 +03:00
|
|
|
if (MI_BUILD_STATIC)
|
|
|
|
add_library(mimalloc-static STATIC ${mi_sources})
|
2020-05-04 19:51:09 +03:00
|
|
|
set_property(TARGET mimalloc-static PROPERTY POSITION_INDEPENDENT_CODE ON)
|
2020-04-28 18:12:43 +03:00
|
|
|
target_compile_definitions(mimalloc-static PRIVATE ${mi_defines} MI_STATIC_LIB)
|
|
|
|
target_compile_options(mimalloc-static PRIVATE ${mi_cflags})
|
|
|
|
target_link_libraries(mimalloc-static PUBLIC ${mi_libraries})
|
|
|
|
target_include_directories(mimalloc-static PUBLIC
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
|
|
|
$<INSTALL_INTERFACE:${mi_install_dir}/include>
|
|
|
|
)
|
2020-05-04 19:51:09 +03:00
|
|
|
if(WIN32)
|
2020-04-28 18:12:43 +03:00
|
|
|
# When building both static and shared libraries on Windows, a static library should use a
|
|
|
|
# different output name to avoid the conflict with the import library of a shared one.
|
|
|
|
string(REPLACE "mimalloc" "mimalloc-static" mi_output_name ${mi_basename})
|
|
|
|
set_target_properties(mimalloc-static PROPERTIES OUTPUT_NAME ${mi_output_name})
|
|
|
|
else()
|
|
|
|
set_target_properties(mimalloc-static PROPERTIES OUTPUT_NAME ${mi_basename})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
install(TARGETS mimalloc-static EXPORT mimalloc DESTINATION ${mi_install_dir})
|
2019-06-23 12:26:40 +03:00
|
|
|
endif()
|
2019-06-20 02:52:36 +03:00
|
|
|
|
2020-04-28 18:12:43 +03:00
|
|
|
# install include files
|
2019-06-20 02:52:36 +03:00
|
|
|
install(FILES include/mimalloc.h DESTINATION ${mi_install_dir}/include)
|
2019-07-19 05:52:29 +03:00
|
|
|
install(FILES include/mimalloc-override.h DESTINATION ${mi_install_dir}/include)
|
2019-09-16 05:19:00 +03:00
|
|
|
install(FILES include/mimalloc-new-delete.h DESTINATION ${mi_install_dir}/include)
|
2019-06-20 02:52:36 +03:00
|
|
|
install(FILES cmake/mimalloc-config.cmake DESTINATION ${mi_install_dir}/cmake)
|
|
|
|
install(FILES cmake/mimalloc-config-version.cmake DESTINATION ${mi_install_dir}/cmake)
|
2019-09-16 06:26:30 +03:00
|
|
|
|
2020-04-28 18:12:43 +03:00
|
|
|
if(NOT WIN32 AND MI_BUILD_SHARED)
|
2019-09-16 06:26:30 +03:00
|
|
|
# install a symlink in the /usr/local/lib to the versioned library
|
|
|
|
set(mi_symlink "${CMAKE_SHARED_MODULE_PREFIX}${mi_basename}${CMAKE_SHARED_LIBRARY_SUFFIX}")
|
|
|
|
set(mi_soname "mimalloc-${mi_version}/${mi_symlink}.${mi_version}")
|
2020-03-05 04:45:20 +03:00
|
|
|
install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${mi_soname} ${mi_symlink} WORKING_DIRECTORY ${mi_install_dir}/..)")
|
2019-09-16 06:26:30 +03:00
|
|
|
install(CODE "MESSAGE(\"-- Symbolic link: ${CMAKE_INSTALL_PREFIX}/lib/${mi_symlink} -> ${mi_soname}\")")
|
|
|
|
endif()
|
2019-06-20 02:52:36 +03:00
|
|
|
|
|
|
|
# single object file for more predictable static overriding
|
2020-04-28 18:12:43 +03:00
|
|
|
if (MI_BUILD_OBJECT)
|
|
|
|
add_library(mimalloc-obj OBJECT src/static.c)
|
2020-05-04 19:51:09 +03:00
|
|
|
set_property(TARGET mimalloc-obj PROPERTY POSITION_INDEPENDENT_CODE ON)
|
2020-04-28 18:12:43 +03:00
|
|
|
target_compile_definitions(mimalloc-obj PRIVATE ${mi_defines})
|
|
|
|
target_compile_options(mimalloc-obj PRIVATE ${mi_cflags})
|
|
|
|
target_include_directories(mimalloc-obj PUBLIC
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
|
|
|
$<INSTALL_INTERFACE:${mi_install_dir}/include>
|
|
|
|
)
|
|
|
|
|
|
|
|
# the following seems to lead to cmake warnings/errors on some systems, disable for now :-(
|
|
|
|
# install(TARGETS mimalloc-obj EXPORT mimalloc DESTINATION ${mi_install_dir})
|
|
|
|
|
|
|
|
# the FILES expression can also be: $<TARGET_OBJECTS:mimalloc-obj>
|
|
|
|
# but that fails cmake versions less than 3.10 so we leave it as is for now
|
|
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/mimalloc-obj.dir/src/static.c${CMAKE_C_OUTPUT_EXTENSION}
|
2020-05-04 21:01:11 +03:00
|
|
|
DESTINATION ${mi_install_dir}
|
2020-04-28 18:12:43 +03:00
|
|
|
RENAME ${mi_basename}${CMAKE_C_OUTPUT_EXTENSION} )
|
|
|
|
endif()
|
2019-06-27 23:36:19 +03:00
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# API surface testing
|
|
|
|
# -----------------------------------------------------------------------------
|
2019-08-28 18:26:56 +03:00
|
|
|
|
|
|
|
if (MI_BUILD_TESTS MATCHES "ON")
|
|
|
|
add_executable(mimalloc-test-api test/test-api.c)
|
|
|
|
target_compile_definitions(mimalloc-test-api PRIVATE ${mi_defines})
|
|
|
|
target_compile_options(mimalloc-test-api PRIVATE ${mi_cflags})
|
|
|
|
target_include_directories(mimalloc-test-api PRIVATE include)
|
|
|
|
target_link_libraries(mimalloc-test-api PRIVATE mimalloc-static ${mi_libraries})
|
|
|
|
|
|
|
|
add_executable(mimalloc-test-stress test/test-stress.c)
|
|
|
|
target_compile_definitions(mimalloc-test-stress PRIVATE ${mi_defines})
|
|
|
|
target_compile_options(mimalloc-test-stress PRIVATE ${mi_cflags})
|
|
|
|
target_include_directories(mimalloc-test-stress PRIVATE include)
|
2020-01-30 09:46:44 +03:00
|
|
|
target_link_libraries(mimalloc-test-stress PRIVATE mimalloc ${mi_libraries})
|
2019-08-28 18:26:56 +03:00
|
|
|
|
|
|
|
enable_testing()
|
|
|
|
add_test(test_api, mimalloc-test-api)
|
|
|
|
add_test(test_stress, mimalloc-test-stress)
|
|
|
|
endif()
|
2019-06-27 23:36:19 +03:00
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# Set override properties
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
if (MI_OVERRIDE MATCHES "ON")
|
2020-04-28 18:12:43 +03:00
|
|
|
if (MI_BUILD_SHARED)
|
|
|
|
target_compile_definitions(mimalloc PRIVATE MI_MALLOC_OVERRIDE)
|
|
|
|
endif()
|
2019-06-27 23:36:19 +03:00
|
|
|
if(NOT WIN32)
|
2019-11-14 22:01:05 +03:00
|
|
|
# It is only possible to override malloc on Windows when building as a DLL.
|
2020-04-28 18:12:43 +03:00
|
|
|
if (MI_BUILD_STATIC)
|
|
|
|
target_compile_definitions(mimalloc-static PRIVATE MI_MALLOC_OVERRIDE)
|
|
|
|
endif()
|
|
|
|
if (MI_BUILD_OBJECT)
|
|
|
|
target_compile_definitions(mimalloc-obj PRIVATE MI_MALLOC_OVERRIDE)
|
|
|
|
endif()
|
2019-06-27 23:36:19 +03:00
|
|
|
endif()
|
|
|
|
endif()
|