From 498a2e349b26bb692c23bad50e0be71d730e29b5 Mon Sep 17 00:00:00 2001 From: mrmbernardi Date: Tue, 15 Oct 2024 20:11:47 +1100 Subject: [PATCH] CMake option to turn on the AddressSanitizer (#22985) --- CMakeLists.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e83b17257..4ff2d55734 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -110,6 +110,8 @@ option(DISABLE_HTTP "Disable HTTP support.") option(DISABLE_NETWORK "Disable multiplayer functionality. Mainly for testing.") option(DISABLE_TTF "Disable support for TTF provided by freetype2.") option(ENABLE_SCRIPTING "Enable script / plugin support." ON) +option(ENABLE_ASAN "Enable the AddressSanitizer.") +option(ENABLE_UBSAN "Enable the UndefinedBehaviourSanitizer.") option(DISABLE_GUI "Don't build GUI. (Headless only.)") @@ -396,6 +398,14 @@ endif () if (ENABLE_SCRIPTING) target_compile_options(libopenrct2 PUBLIC -DENABLE_SCRIPTING) endif () +if (ENABLE_ASAN) + target_compile_options(libopenrct2 PUBLIC -fsanitize=address) + target_link_options(libopenrct2 PUBLIC -fsanitize=address) +endif () +if (ENABLE_UBSAN) + target_compile_options(libopenrct2 PUBLIC -fsanitize=undefined) + target_link_options(libopenrct2 PUBLIC -fsanitize=undefined) +endif () # g2