From 84c15f6384c74538e5566e409b908cf0d9f3e90a Mon Sep 17 00:00:00 2001 From: James Turner Date: Fri, 14 Aug 2020 11:11:44 +0100 Subject: [PATCH] Enable ASan for clang --- CMakeLists.txt | 13 ++++++++++++- SimGearConfig.cmake.in | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f772e09..187b18ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,6 +108,8 @@ if (NOT MSVC) option(SIMGEAR_SHARED "Set to ON to build SimGear as a shared library/framework" OFF) option(SYSTEM_EXPAT "Set to ON to build SimGear using the system expat library" OFF) option(SYSTEM_UDNS "Set to ON to build SimGear using the system udns library" OFF) +option(ENABLE_ASAN "Set to ON to build SimGear with LLVM AddressSanitizer (ASan) support" OFF) + else() # Building SimGear DLLs is currently not supported for MSVC. set(SIMGEAR_SHARED OFF) @@ -408,12 +410,21 @@ if (CLANG) set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++") # fix Boost compilation :( set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") - # override CMake default RelWithDebInfo flags. set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g -DNDEBUG") set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -g -DNDEBUG") set(SIMD_COMPILER_FLAGS "-msse2 -mfpmath=sse -ftree-vectorize -ftree-slp-vectorize") + + if (ENABLE_ASAN) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address") + + # needed for check_cxx_source_compiles + set(CMAKE_REQUIRED_LINK_OPTIONS "-fsanitize=address") + endif() endif() if (ENABLE_OPENMP) diff --git a/SimGearConfig.cmake.in b/SimGearConfig.cmake.in index 8327cf9c..7382c13f 100644 --- a/SimGearConfig.cmake.in +++ b/SimGearConfig.cmake.in @@ -9,6 +9,7 @@ find_dependency(CURL) set(SIMGEAR_HEADLESS @SIMGEAR_HEADLESS@) set(SIMGEAR_SOUND @ENABLE_SOUND@) set(USE_AEONWAVE @USE_AEONWAVE@) +set(ENABLE_ASAN @ENABLE_ASAN@) # OpenAL isn't a public dependency, so maybe not needed #if (SIMGEAR_SOUND)