Support the Windows CMake build for the mimalloc redirect#6173
Merged
Conversation
Add an mr_enable_mimalloc_redirect() helper and apply it to MeshViewer and MRTest so the CMake build links mimalloc and engages mimalloc-redirect.dll, matching the MSBuild setup. Linking the imported mimalloc target lets CMake resolve the right import library, so also drop the hardcoded import-lib name from those .vcxproj files (it varies by mimalloc version - 2.x mimalloc.lib vs 3.x mimalloc.dll.lib); vcpkg's auto-link plus the mi_version anchor already pull it in. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Fedr
approved these changes
May 27, 2026
oitel
reviewed
May 27, 2026
Contributor
There was a problem hiding this comment.
The comments are now obsolete, I believe.
Contributor
There was a problem hiding this comment.
The comments are now obsolete, I believe.
| # on every other platform (Emscripten links mimalloc via -sMALLOC=mimalloc, see | ||
| # ConfigureEmscripten.cmake). Linking the imported mimalloc target lets CMake | ||
| # resolve the version-specific import library name for us. | ||
| function(mr_enable_mimalloc_redirect target) |
Contributor
There was a problem hiding this comment.
The function name is confusing since it, in fact, doesn't enable anything on any platform other than Windows. I suggest renaming it to mr_win32_enable_mimalloc_redirect and putting the WIN32 check before its calls explicitly, like:
if(WIN32)
include(MimallocRedirect)
mr_win32_enable_mimalloc_redirect(${PROJECT_NAME})
endif()… comments Rename mr_enable_mimalloc_redirect -> mr_win32_enable_mimalloc_redirect and move the if(WIN32) guard to the call sites so the helper no longer silently no-ops off-Windows. Trim the .vcxproj comments to just why mi_version is force-referenced, dropping the obsolete import-lib rationale. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
Author
|
Thanks @oitel — both addressed in 3836d62:
|
oitel
approved these changes
May 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cmake/Modules/MimallocRedirect.cmakewithmr_enable_mimalloc_redirect(target): on Windows itfind_package(mimalloc), links the imported target, and forces/INCLUDE:mi_versionsomimalloc.dllloads early enough formimalloc-redirect.dllto take over the CRT allocator process-wide. No-op on other platforms (Emscripten already links mimalloc via-sMALLOC=mimalloc)..vcxprojpath had it.MRViewerApp.vcxproj/MRTest.vcxproj. The name differs across versions (2.xmimalloc.lib, 3.xmimalloc.dll.lib); vcpkg'slib\*.libauto-link plus themi_versionanchor already pull it in, so naming it explicitly only riskedLNK1181on toolchains resolving a different mimalloc version.Test plan
mi_is_redirected()returns 1 at runtime.