Fixed CMake address sanitizer

This commit is contained in:
gabime
2019-06-10 18:32:10 +03:00
parent 68a0193d95
commit cf64f2baca
4 changed files with 28 additions and 27 deletions

View File

@@ -12,30 +12,30 @@ function(spdlog_extract_version)
if (NOT ver_major OR NOT ver_minor OR NOT ver_patch)
message(FATAL_ERROR "Could not extract valid version from spdlog/version.h")
endif()
set (SPDLOG_VERSION "${ver_major}.${ver_minor}.${ver_patch}" PARENT_SCOPE)
set (SPDLOG_VERSION "${ver_major}.${ver_minor}.${ver_patch}" PARENT_SCOPE)
endfunction()
# Turn on warnings on the given target
# Turn on warnings on the given target
function(spdlog_enable_warnings target_name)
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang")
target_compile_options(${target_name} PRIVATE -Wall -Wextra -Wconversion -pedantic -Wfatal-errors)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
target_compile_options(${target_name} PRIVATE /W4 /WX )
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang")
target_compile_options(${target_name} PRIVATE -Wall -Wextra -Wconversion -pedantic -Wfatal-errors)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
target_compile_options(${target_name} PRIVATE /W4 /WX )
endif()
endfunction()
# Enable address sanitizer (gcc/clang only)
function(spdlog_enable_sanitizer target_name)
if (NOT CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
message(FATAL_ERROR "Sanitizer supported only for gcc/clang")
endif()
message(STATUS "Address sanitizer enabled")
target_compile_options(${target_name} "-fsanitize=address,undefined")
target_compile_options(${target_name} "-fno-sanitize=signed-integer-overflow")
target_compile_options(${target_name} "-fno-sanitize-recover=all")
target_compile_options(${target_name} "-fno-omit-frame-pointer")
target_link_libraries(${target_name} "-fsanitize=address,undefined -fuse-ld=gold")
endfunction()
function(spdlog_enable_sanitizer target_name)
if (NOT CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
message(FATAL_ERROR "Sanitizer supported only for gcc/clang")
endif()
message(STATUS "Address sanitizer enabled")
target_compile_options(${target_name} PRIVATE -fsanitize=address,undefined)
target_compile_options(${target_name} PRIVATE -fno-sanitize=signed-integer-overflow)
target_compile_options(${target_name} PRIVATE -fno-sanitize-recover=all)
target_compile_options(${target_name} PRIVATE -fno-omit-frame-pointer)
target_link_libraries(${target_name} PRIVATE -fsanitize=address,undefined -fuse-ld=gold)
endfunction()