Skip to content

Commit 4b8d64d

Browse files
RazishSomaZ
authored andcommitted
[Shared] provide option to use AddressSanitizer
1 parent b6094d6 commit 4b8d64d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ option(BuildJK2SPGame "Whether to create projects for the jk2 sp gamecode mod (j
5050
option(BuildJK2SPRdVanilla "Whether to create projects for the jk2 sp renderer (rdjosp-vanilla_x86.dll)" OFF)
5151

5252
option(BuildTests "Whether to build automatic unit tests (requires Boost)" OFF)
53+
option(UseSanitizer "Whether to enable runtime sanitizers (e.g. AddressSanitizer)" OFF)
5354

5455
include(CMakeDependentOption)
5556
cmake_dependent_option(BuildSymbolServer "Build WIP Windows Symbol Server (experimental and unused)" OFF "NOT WIN32 OR NOT MSVC" OFF)
@@ -244,6 +245,11 @@ elseif (("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") OR ("${CMAKE_C_COMPILER_ID}" M
244245
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
245246
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
246247

248+
if(CMAKE_BUILD_TYPE MATCHES "DEBUG" OR CMAKE_BUILD_TYPE MATCHES "Debug" AND UseSanitizer)
249+
add_compile_options(-fsanitize=address)
250+
add_link_options(-fsanitize=address)
251+
endif()
252+
247253
# additional flags for debug configuration
248254
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb")
249255
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb")

0 commit comments

Comments
 (0)