From 91596d8ab4864519fd3d0abe95b488e7afdab14c Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Tue, 22 Mar 2022 18:35:00 +0100 Subject: [PATCH] Support Address Sanitizer --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4182a73..cf62034 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,7 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) option(WINDOWS "Whether the build target is Windows or not." OFF) option(SHARED "Whether we should build a shared library, instead of a static one." ON) option(PKMNLIB_TESTS "Whether the test executable should be build as well." OFF) +option(SANITIZER_TESTS "Whether the test executable should be built using address sanitizer." ON) option(STATICC "Whether gcc and stdc++ should be linked statically to the library." OFF) option(ANGELSCRIPT_DEBUGGER "Include the angelscript debug server in the build." OFF) set(SCRIPT_PROVIDER "angelscript" CACHE STRING "Which script provider to use.") @@ -226,6 +227,10 @@ if (PKMNLIB_TESTS) # Add a definition for the test library target_compile_definitions(pkmnLibTests PRIVATE TESTS_BUILD) + if (SANITIZER_TESTS AND NOT WINDOWS) + target_compile_options(pkmnLibTests PRIVATE -fsanitize=address) + target_link_options(pkmnLibTests PRIVATE -fsanitize=address) + endif() endif () if (ANGELSCRIPT_DEBUGGER)