Skip to content

Commit

Permalink
[Shared] provide option to use AddressSanitizer
Browse files Browse the repository at this point in the history
  • Loading branch information
Razish committed Sep 2, 2022
1 parent 034057e commit 7b70109
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#============================================================================
# Copyright (C) 2013 - 2018, OpenJK contributors
#
#
# This file is part of the OpenJK source code.
#
#
# OpenJK is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#============================================================================
Expand Down Expand Up @@ -48,6 +48,7 @@ option(BuildJK2SPGame "Whether to create projects for the jk2 sp gamecode mod (j
option(BuildJK2SPRdVanilla "Whether to create projects for the jk2 sp renderer (rdjosp-vanilla_x86.dll)" OFF)

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

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

if(CMAKE_BUILD_TYPE MATCHES "DEBUG" OR CMAKE_BUILD_TYPE MATCHES "Debug" AND UseSanitizer)
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)
endif()

# additional flags for debug configuration
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb")
Expand All @@ -243,7 +249,7 @@ elseif (("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") OR ("${CMAKE_C_COMPILER_ID}" M

# enable somewhat modern C++
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-comment")
Expand Down Expand Up @@ -388,4 +394,4 @@ endif()
if(BuildTests)
enable_testing()
add_subdirectory("tests")
endif()
endif()

0 comments on commit 7b70109

Please sign in to comment.