mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2024-12-05 00:38:00 +01:00
cmake: support memory sanitizer
This commit is contained in:
parent
356cb6c2e8
commit
b8d44792f1
1 changed files with 18 additions and 15 deletions
|
@ -87,10 +87,9 @@ if (NOT LIBSUPERDERPY_CONFIG_INCLUDED)
|
|||
endif(ANDROID)
|
||||
|
||||
set(SANITIZERS "address,undefined" CACHE STRING "List of code sanitizers enabled for Debug builds")
|
||||
set_property(CACHE SANITIZERS PROPERTY STRINGS "" address undefined leak thread address,undefined leak,undefined thread,undefined)
|
||||
set_property(CACHE SANITIZERS PROPERTY STRINGS "" address undefined leak thread address,undefined leak,undefined thread,undefined memory memory,undefined)
|
||||
# leak sanitizer is a subset of address sanitizer
|
||||
# address/leak, memory and thread sanitizers are mutually exclusive (there can be only one at once)
|
||||
# memory sanitizer is available only as a static library so far, which breaks -Wl,--no-undefined
|
||||
# there's also fuzzer, but it doesn't seem particularly interesting for us
|
||||
|
||||
if (SANITIZERS)
|
||||
|
@ -101,6 +100,14 @@ if (NOT LIBSUPERDERPY_CONFIG_INCLUDED)
|
|||
if ("${SANITIZERS}" MATCHES "address")
|
||||
set(SANITIZERS_ARGS "${SANITIZERS_ARGS} -fsanitize-address-use-after-scope")
|
||||
endif()
|
||||
if (NOT "${SANITIZERS}" MATCHES "memory")
|
||||
if ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -shared-libsan")
|
||||
endif()
|
||||
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -shared-libsan")
|
||||
endif()
|
||||
endif()
|
||||
endif(SANITIZERS)
|
||||
|
||||
if (EMSCRIPTEN)
|
||||
|
@ -126,20 +133,16 @@ if (NOT LIBSUPERDERPY_CONFIG_INCLUDED)
|
|||
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -D_FORTIFY_SOURCE=2")
|
||||
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -D_FORTIFY_SOURCE=2")
|
||||
|
||||
if ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -shared-libsan")
|
||||
endif()
|
||||
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -shared-libsan")
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-undefined,error")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-undefined,error")
|
||||
else(APPLE)
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-undefined")
|
||||
endif(APPLE)
|
||||
if (NOT "${SANITIZERS}" MATCHES "memory")
|
||||
if(APPLE)
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-undefined,error")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-undefined,error")
|
||||
else(APPLE)
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-undefined")
|
||||
endif(APPLE)
|
||||
endif()
|
||||
|
||||
option(USE_CLANG_TIDY "Analyze the code with clang-tidy" OFF)
|
||||
if(USE_CLANG_TIDY AND NOT MINGW)
|
||||
|
|
Loading…
Reference in a new issue