Skip to content

Commit efa65d8

Browse files
committed
build: fix CMake from always enabling address sanitizer on macos
1 parent cd18675 commit efa65d8

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

CMakeLists.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@ set(ARCH "x64" CACHE STRING "Arch")
55

66
option(BUILD_SHARED "Option to build shared library" ON)
77
option(BUILD_STATIC "Option to build static library" ON)
8+
option(ENABLE_SANITIZERS "Enable AddressSanitizer and UBSan for Debug builds" OFF)
89

910
message(STATUS "PLATFORM: ${PLATFORM}")
1011
message(STATUS "ARCH: ${ARCH}")
1112

1213
message(STATUS "BUILD_SHARED: ${BUILD_SHARED}")
1314
message(STATUS "BUILD_STATIC: ${BUILD_STATIC}")
1415

15-
if(PLATFORM STREQUAL "macos")
16-
set(CMAKE_OSX_DEPLOYMENT_TARGET 14.0)
17-
elseif(PLATFORM STREQUAL "ios" OR PLATFORM STREQUAL "ios-simulator")
16+
if(PLATFORM STREQUAL "ios" OR PLATFORM STREQUAL "ios-simulator")
1817
set(CMAKE_SYSTEM_NAME iOS)
1918
if (PLATFORM STREQUAL "ios-simulator")
2019
set(CMAKE_OSX_SYSROOT iphonesimulator)
@@ -65,6 +64,14 @@ set(CMAKE_C_STANDARD 99)
6564
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
6665
set(CMAKE_C_VISIBILITY_PRESET hidden)
6766

67+
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
68+
if(ENABLE_SANITIZERS AND (PLATFORM STREQUAL "macos" OR PLATFORM STREQUAL "linux"))
69+
set(SANITIZER_FLAGS -fsanitize=address,undefined)
70+
add_compile_options(${SANITIZER_FLAGS} -fno-omit-frame-pointer -g)
71+
add_link_options(${SANITIZER_FLAGS})
72+
endif()
73+
endif()
74+
6875
set(PUPDMD_SOURCES
6976
src/pupdmd.h
7077
src/pupdmd.cpp

0 commit comments

Comments
 (0)