diff options
author | Rachel Powers <508861+Ryex@users.noreply.github.com> | 2023-07-03 17:42:57 -0700 |
---|---|---|
committer | Rachel Powers <508861+Ryex@users.noreply.github.com> | 2023-07-03 17:48:44 -0700 |
commit | 96c118779daff9ea099710957a62c83115c149ef (patch) | |
tree | 598cb6883f125ec39e79a0a1ca348d9a22becede /CMakeLists.txt | |
parent | c523765c197cf63d6830d205f1554cd73e38109e (diff) | |
download | PrismLauncher-96c118779daff9ea099710957a62c83115c149ef.tar.gz PrismLauncher-96c118779daff9ea099710957a62c83115c149ef.tar.bz2 PrismLauncher-96c118779daff9ea099710957a62c83115c149ef.zip |
build: enable address sanitiser in debug builds
Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 70a55319..dd84daf3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,6 +85,28 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTOML_ENABLE_FLOAT16=0") # set CXXFLAGS for build targets set(CMAKE_CXX_FLAGS_RELEASE "-O2 -D_FORTIFY_SOURCE=2 ${CMAKE_CXX_FLAGS_RELEASE}") +option(DEBUG_ADDRESS_SANITIZER "Enable Address Sanitizer in Debug builds" on) + +# If this is a Debug build turn on address sanitiser +if (CMAKE_BUILD_TYPE STREQUAL "Debug" AND DEBUG_ADDRESS_SANITIZER) + message(STATUS "Address Sanitizer enabeled for Debug builds, Turn it off with -DDEBUG_ADDRESS_SANITIZER=off") + if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") + # AppleClang and Clang + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address") + elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + # GCC + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address") + elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") + # Intell compiler ? why? + # no address sanitiser here though + message(STATUS "Address Sanitizer not available on Intell compilers") + elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fsanitize=address") + else() + message(STATUS "Address Sanitizer not available on unknown compiler ${CMAKE_CXX_COMPILER_ID}") + endif() +endif() + option(ENABLE_LTO "Enable Link Time Optimization" off) if(ENABLE_LTO) |