From 7b70109eeb8cf1cebb3720bc94120db64bc81e1d Mon Sep 17 00:00:00 2001 From: Razish Date: Fri, 2 Sep 2022 22:07:46 +1000 Subject: [PATCH] [Shared] provide option to use AddressSanitizer --- CMakeLists.txt | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bde16bb813..b1c25bac5a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 . #============================================================================ @@ -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) @@ -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") @@ -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") @@ -388,4 +394,4 @@ endif() if(BuildTests) enable_testing() add_subdirectory("tests") -endif() \ No newline at end of file +endif()