CMake options and C preprocessor definitions to configure the library at build time.
CMake options and C preprocessor definitions to configure the library at build time.
CMake options are set at configuration time as cmake -D<option>=<value> (use cmake -LH to list them with their current value). Most options set a C preprocessor definition that can also be defined directly when building without CMake, for example when compiling the single src/static.c file (see Building). A DEFAULT value is resolved based on the platform and build type.
| CMake option | C define | Description |
|---|---|---|
| MI_OVERRIDE | MI_MALLOC_OVERRIDE | Override the standard Basic Allocation interface (ON); see Overriding Standard Malloc. |
| MI_OVERRIDE_CXX | MI_NO_OVERRIDE_CXX | Also override the C++ new and delete operators (ON); disable if the program defines its own. |
| MI_SECURE | MI_SECURE=0..5 | Security mitigations: OFF (0), BASIC (1), CHECKED (2), ON (4), or FULL (5, guard pages after each mimalloc page). DEFAULT is CHECKED with MI_MTE or MI_PAC, level 3 on CHERI, and OFF otherwise. See secure_mode. |
| MI_SECURE_ENV | MI_SECURE_ENV=0,1 | Only accept the show_stats, verbose, show_errors, and allow_thp environment options. DEFAULT is ON with MI_SECURE, MI_MTE, or MI_PAC. See security_environment. |
| MI_DEBUG | MI_DEBUG=0..3 | Assertion checks: OFF (0, defines NDEBUG), ON (1), INTERNAL (2, internal invariants), or FULL (3, expensive heap invariants). DEFAULT is INTERNAL in debug builds and OFF otherwise. |
| MI_NO_DEBUG | NDEBUG | Disable all assertion checks, even in debug builds. |
| MI_STATS | MI_STATS=0..2 | Statistics: OFF, ON, or FULL (also tracks the precise requested bytes). DEFAULT is FULL in debug builds and ON otherwise. See Statistics. |
| MI_PROFILE | MI_PROFILE=0..2 | Sampled heap profiling: OFF, ON, or FULL (fine-grained sampling). DEFAULT is FULL in debug builds and ON otherwise. See Heap Profiling. |
| MI_GUARDED | MI_GUARDED=0..2 | Support guard pages behind sampled allocations: OFF, ON, or FULL (fine-grained sampling). DEFAULT is FULL in debug builds and OFF otherwise. See Guarded Mode. |
| MI_PADDING | MI_PADDING=1 | Pad each block to detect heap block overflows. Always enabled in debug builds, with MI_SECURE=ON, and with VALGRIND, ASAN, or ETW tracking. |
| MI_NO_PADDING | MI_PADDING=0 | Never pad blocks, even in debug builds. |
| MI_FREE_IS_CHECKED | MI_FREE_IS_CHECKED=1 | Check for invalid pointers in mi_free: OFF, ON, or SHARED (only in the shared library with MI_OVERRIDE). Implied by MI_SECURE (CHECKED or higher), MI_MTE, and MI_PAC. |
| MI_TRACK | MI_TRACK_<tool>=1 | Track allocations with VALGRIND, ASAN (address sanitizer), ETW (Windows event tracing), or CUSTOM, where the application defines mi_track_malloc_hook(p,reqsize,size,zero) and mi_track_free_hook(p,size). Adds a small overhead. |
| MI_XMALLOC | MI_XMALLOC=1 | Call abort() when an allocation fails. |
| MI_SHOW_ERRORS | MI_SHOW_ERRORS=1 | Show error and warning messages by default (as in debug builds). |
| MI_ENV_PREFIX | MI_ENV_PREFIX="<prefix>" | Read environment options as <prefix>_MIMALLOC_<option>. See Runtime Options and Environment Variables. |
| MI_ALLOW_THP | MI_DEFAULT_ALLOW_THP=0..2 | Default for mi_option_allow_thp on Linux and Android: OFF, ON, or FULL. DEFAULT is FULL on Linux and OFF on Android. |
| MI_NO_THP | MI_DEFAULT_ALLOW_THP=0 | Same as MI_ALLOW_THP=OFF. |
| MI_SKIP_COLLECT_ON_EXIT | MI_SKIP_COLLECT_ON_EXIT=1 | Skip collecting memory on program exit. |
| MI_FREE_USE_PAGEMAP | MI_FREE_USE_PAGEMAP=1 | Always use the page map in mi_free; only for systems that do not support large aligned OS allocations well. |
| MI_OPT_FREE_SMALL | MI_OPT_FREE_SMALL=0,1 | Use mi_free_small() without a page map lookup; set to OFF if mi_free_sized() can be called with a wrong size. Not available in secure or guarded builds. |
| MI_MTE | MI_MTE=1,2 | Memory tagging on arm64 (experimental): PREFER (1, if available at runtime) or ON (2, required at runtime). See memory_tagging. |
| MI_PAC | MI_PAC=0..2 | Sign internal pointers: WEAK (1, software process key) or ON (2, arm64 pointer authentication, required at runtime). DEFAULT is ON with MI_MTE=ON. See pointer_authentication. |
| MI_SECURE_NO_STATIC_GUARD | MI_SECURE_NO_STATIC_GUARD=1 | No guard pages around the static process data in secure mode (for example with a conservative garbage collector); the sealed data stays read-only. |
| MI_OSX_INTERPOSE | MI_OSX_INTERPOSE=1 | Use interposing to override Basic Allocation on macOS (ON). |
| MI_OSX_ZONE | MI_OSX_ZONE=1 | Use a malloc zone to override Basic Allocation on macOS (ON). |
| MI_WIN_REDIRECT | MI_WIN_NOREDIRECT | Use the mimalloc-redirect module to override Basic Allocation with the DLL on Windows (ON). See override_on_windows. |
| MI_WIN_INIT | MI_WIN_INIT_USE_<mode>=1 | Windows initialization: CRT_TLS (default), RAW_DLLMAIN, TLS_DLLMAIN, or FLS (legacy). |
| MI_TLS_MODEL | MI_TLS_MODEL_<model>=1 | Thread-local storage model: LOCAL, LOCAL_DYNAMIC (dlopen compatible), PTHREADS, WIN32, or FIXED. DEFAULT selects the best model for the platform. |
| MI_TLS_RECURSE_GUARD | MI_TLS_RECURSE_GUARD=1 | Check for recursion on thread-local access (with MI_TLS_MODEL=LOCAL). |
| MI_LIBC_MUSL | MI_LIBC_MUSL=1 | Enable when linking with musl libc. |
| MI_OPT_ARCH | Architecture specific optimizations in release builds: ON (x64: haswell with avx2, arm64: armv8.1-a, riscv: rv64gcb_zacas), or one of avx2, armv8.1, armv8.3, rva22, rva23, rv64gcb_zacas, and rv64gcb_zacas_zalasr. DEFAULT is ON on arm64. | |
| MI_OPT_SIMD | MI_OPT_SIMD=1 | Use SIMD instructions (requires MI_OPT_ARCH). |
| MI_USE_CXX | Compile as C++. DEFAULT is ON for MSVC, clang-cl, and Intel compilers. | |
| MI_DEBUG_TSAN | MI_TSAN=1 | Build with the thread sanitizer (clang). |
| MI_DEBUG_UBSAN | MI_UBSAN=1 | Build with the undefined-behavior sanitizer (clang++, debug builds). |
| MI_DEBUG_FUZZ | Build with fuzzing instrumentation and the libFuzzer test (clang). | |
| MI_EXTRA_CPPDEFS | Extra preprocessor definitions, as -DMI_EXTRA_CPPDEFS="opt1=val1;opt2=val2". | |
| MI_SEE_ASM | Generate assembly listings. | |
| MI_BUILD_SHARED | Build the shared library (ON). | |
| MI_BUILD_STATIC | Build the static library (ON). | |
| MI_BUILD_OBJECT | Build the single object file (ON). | |
| MI_BUILD_TESTS | Build the tests (ON). | |
| MI_INSTALL_TOPLEVEL | Install the headers, static library, and CMake files directly in the install prefix instead of versioned mimalloc-<version> directories. | |
| MI_NO_LIB_SUFFIX | Do not add suffixes like -debug, -secure, or -mte to the library name. | |
| MI_NO_USE_CXX, MI_NO_OPT_ARCH | Negated MI_USE_CXX and MI_OPT_ARCH (for vcpkg features); these take priority. |
Other options, like MI_SECURE_FULL or MI_TRACK_VALGRIND, are deprecated and map onto the options above.
Further C preprocessor definitions that can be useful:
| C define | Description |
|---|---|
| MI_PROCESS_INIT_HOOK=<fun> | Call extern "C" void <fun>(void) at the end of process initialization, before reserving huge OS pages or OS memory. The hook can set options, reserve arenas, and allocate. |
| MI_DEFAULT_<OPTION>=<n> | Set the default of a runtime option, for example MI_DEFAULT_ARENA_RESERVE (in KiB) or MI_DEFAULT_VERBOSE. Supported for a subset of options (see src/util/options.c). |
| mi_decl_export | Export attribute of the API, for example __attribute__((visibility("default"))) to export the API from a static library built with -fvisibility=hidden. |
These can be passed through CMake with MI_EXTRA_CPPDEFS, for example -DMI_EXTRA_CPPDEFS="MI_PROCESS_INIT_HOOK=my_init".