Skip to content

Commit 7b70109

Browse files
committed
[Shared] provide option to use AddressSanitizer
1 parent 034057e commit 7b70109

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

CMakeLists.txt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
#============================================================================
22
# Copyright (C) 2013 - 2018, OpenJK contributors
3-
#
3+
#
44
# This file is part of the OpenJK source code.
5-
#
5+
#
66
# OpenJK is free software; you can redistribute it and/or modify it
77
# under the terms of the GNU General Public License version 2 as
88
# published by the Free Software Foundation.
9-
#
9+
#
1010
# This program is distributed in the hope that it will be useful,
1111
# but WITHOUT ANY WARRANTY; without even the implied warranty of
1212
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1313
# GNU General Public License for more details.
14-
#
14+
#
1515
# You should have received a copy of the GNU General Public License
1616
# along with this program; if not, see <http://www.gnu.org/licenses/>.
1717
#============================================================================
@@ -48,6 +48,7 @@ option(BuildJK2SPGame "Whether to create projects for the jk2 sp gamecode mod (j
4848
option(BuildJK2SPRdVanilla "Whether to create projects for the jk2 sp renderer (rdjosp-vanilla_x86.dll)" OFF)
4949

5050
option(BuildTests "Whether to build automatic unit tests (requires Boost)" OFF)
51+
option(UseSanitizer "Whether to enable runtime sanitizers (e.g. AddressSanitizer)" OFF)
5152

5253
include(CMakeDependentOption)
5354
cmake_dependent_option(BuildSymbolServer "Build WIP Windows Symbol Server (experimental and unused)" OFF "NOT WIN32 OR NOT MSVC" OFF)
@@ -229,6 +230,11 @@ elseif (("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") OR ("${CMAKE_C_COMPILER_ID}" M
229230
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
230231
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
231232

233+
if(CMAKE_BUILD_TYPE MATCHES "DEBUG" OR CMAKE_BUILD_TYPE MATCHES "Debug" AND UseSanitizer)
234+
add_compile_options(-fsanitize=address)
235+
add_link_options(-fsanitize=address)
236+
endif()
237+
232238
# additional flags for debug configuration
233239
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb")
234240
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb")
@@ -243,7 +249,7 @@ elseif (("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") OR ("${CMAKE_C_COMPILER_ID}" M
243249

244250
# enable somewhat modern C++
245251
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
246-
252+
247253
if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
248254
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
249255
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-comment")
@@ -388,4 +394,4 @@ endif()
388394
if(BuildTests)
389395
enable_testing()
390396
add_subdirectory("tests")
391-
endif()
397+
endif()

0 commit comments

Comments
 (0)