Files
source/CMakePresets.json
T
1bed0047ea Add AddressSanitizer support for clang-cl builds
Select the clang-cl-asan CMake preset (RelWithDebInfo, clang-cl,
ADDRESS_SANITIZER=ON) to instrument first-party code with AddressSanitizer.
The wiring lives in cmake/AddressSanitizer.cmake; SANITIZERS.md tells how to
add the clang-cl tools, build, and read the report.

Details:
- Add the clang-cl-asan preset so the asan build is one selection in Visual
  Studio, and a base for a CMakeUserPresets.json to inherit.
- Instrument first-party code only; the vendored libraries keep default flags.
- Use the release CRT and disable MSVC-STL container annotations, so
  instrumented and un-instrumented TUs stay compatible.
- Pass /bigobj to the TUs asan inflates past the COFF section cap.
- Link the asan runtime for clang-cl (lld-link does not infer it).
- Stub Bink into the exe: retail binkw32.dll cannot load in an asan process
  (its image base is the 32-bit shadow), so compile no-op exports instead.
- Route the asan report to gamedir/asan.report.<pid>, since every app is a
  WIN32 GUI app with no console to receive the default stderr report.
- Opt functions with 32-bit inline __asm out of instrumentation with
  cmake/asan-ignorelist.txt, one function at a time (asan reserves a register
  the asm needs). The rest of each translation unit stays instrumented.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-20 23:22:38 -03:00

81 lines
2.2 KiB
JSON

{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 20,
"patch": 0
},
"configurePresets": [
{
"name": "base",
"hidden": true,
"description": "Applications is JA2|JA2MAPEDITOR|JA2UB|JA2UBMAPEDITOR|empty(all 4); override CMAKE_RUNTIME_OUTPUT_DIRECTORY in CMakeUserPresets.json to debug another install.",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/${presetName}",
"architecture": {
"value": "x86",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_RUNTIME_OUTPUT_DIRECTORY": "${sourceDir}/gamedir"
}
},
{
"name": "msvc",
"hidden": true,
"inherits": "base",
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
"hostOS": [ "Windows" ],
"intelliSenseMode": "windows-msvc-x86"
}
}
},
{
"name": "msvc-relwithdebinfo",
"inherits": "msvc",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
}
},
{
"name": "msvc-debug",
"inherits": "msvc",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "msvc-release",
"inherits": "msvc",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "clang-cl-asan",
"inherits": "base",
"displayName": "clang-cl RelWithDebInfo (AddressSanitizer)",
"description": "AddressSanitizer build. Needs the C++ Clang tools for Windows component; see SANITIZERS.md.",
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
"hostOS": [ "Windows" ],
"intelliSenseMode": "windows-clang-x86"
}
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"CMAKE_C_COMPILER": "clang-cl",
"CMAKE_CXX_COMPILER": "clang-cl",
"ADDRESS_SANITIZER": "ON"
}
}
],
"buildPresets": [
{ "name": "msvc-relwithdebinfo", "configurePreset": "msvc-relwithdebinfo" },
{ "name": "msvc-debug", "configurePreset": "msvc-debug" },
{ "name": "msvc-release", "configurePreset": "msvc-release" },
{ "name": "clang-cl-asan", "configurePreset": "clang-cl-asan" }
]
}