Skip to content

Build(presets): Adding CMake presets for compilation with ASan/MSan#398

Merged
riebl merged 3 commits intoriebl:masterfrom
mill1m:master
Feb 20, 2026
Merged

Build(presets): Adding CMake presets for compilation with ASan/MSan#398
riebl merged 3 commits intoriebl:masterfrom
mill1m:master

Conversation

@mill1m
Copy link
Contributor

@mill1m mill1m commented Feb 12, 2026

I am adding two presets for Debug builds along with AddressSanitizer/MemorySanitizer.

Commands for building:

cmake -B <./path/to/build/dir> --preset asan
cmake --build <./path/to/build/dir> --preset asan

or

cmake -B <./path/to/build/dir> --preset msan
cmake --build <./path/to/build/dir> --preset msan

To work with ASan, you need to run executable with LD_PRELOAD=path/to/libasan

export LD_PRELOAD="/path/to/libasan"

The path to the libasan dynamic library can be found using

ldconfig -p | grep libasan

It is possible to build with a dynamic library connection (no need to mess with LD_PRELOAD), but in this case, performance issues may arise. This can even lead to compilation problems if flags for static linking are used.

Building MSan ‘out of the box’ is only possible when using certain compilers, such as Clang. Unfortunately, GCC does not have this functionality by default.
When building a project with MSan, it is recommended to specify the compiler

Also i included --preset flag to tools/build.py which use correspond presets from CMakePresets.json or CMakeUserPresets.json

resolves #393

Copy link
Owner

@riebl riebl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR @mill1m!
Can you please explain the reason for overriding the build director when a preset is requested by the user?

Copy link
Owner

@riebl riebl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, you just need to correct the formatting of the JSON file to make clang-format happy. Then we are ready to merge.

@riebl riebl merged commit 835a6c1 into riebl:master Feb 20, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Option for compilation with ASan/MSan

3 participants