mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-15 08:25:43 +08:00
Fixed CMake address sanitizer
This commit is contained in:
parent
68a0193d95
commit
cf64f2baca
@ -45,6 +45,7 @@ option(SPDLOG_BUILD_EXAMPLES "Build examples" ON)
|
||||
option(SPDLOG_BUILD_BENCH "Build benchmarks (Requires https://github.com/google/benchmark.git to be installed)" OFF)
|
||||
option(SPDLOG_BUILD_TESTS "Build tests" OFF)
|
||||
option(SPDLOG_BUILD_HO_TESTS "Build tests using the header only version" OFF)
|
||||
option(SPDLOG_SANITIZE_ADDRESS "Enable address sanitizer in tests" OFF)
|
||||
option(SPDLOG_INSTALL "Generate the install target." ${SPDLOG_MASTER_PROJECT})
|
||||
option(SPDLOG_FMT_EXTERNAL "Use external fmt library instead of bundled" OFF)
|
||||
|
||||
|
@ -33,9 +33,9 @@ function(spdlog_enable_sanitizer target_name)
|
||||
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")
|
||||
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()
|
@ -14,14 +14,14 @@ endif()
|
||||
#---------------------------------------------------------------------------------------
|
||||
add_executable(example example.cpp)
|
||||
spdlog_enable_warnings(example)
|
||||
target_link_libraries(example spdlog::spdlog)
|
||||
target_link_libraries(example PRIVATE spdlog::spdlog)
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
# Example of using header-only library
|
||||
#---------------------------------------------------------------------------------------
|
||||
add_executable(example_header_only example.cpp)
|
||||
spdlog_enable_warnings(example_header_only)
|
||||
target_link_libraries(example_header_only spdlog::spdlog_header_only)
|
||||
target_link_libraries(example_header_only PRIVATE spdlog::spdlog_header_only)
|
||||
|
||||
# Create logs directory
|
||||
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs")
|
||||
|
@ -22,7 +22,7 @@ enable_testing()
|
||||
if(SPDLOG_BUILD_TESTS)
|
||||
add_executable(spdlog-utests ${SPDLOG_UTESTS_SOURCES})
|
||||
spdlog_enable_warnings(spdlog-utests)
|
||||
target_link_libraries(spdlog-utests spdlog)
|
||||
target_link_libraries(spdlog-utests PRIVATE spdlog)
|
||||
if(SPDLOG_SANITIZE_ADDRESS)
|
||||
spdlog_enable_sanitizer(spdlog-utests)
|
||||
endif()
|
||||
@ -34,7 +34,7 @@ endif()
|
||||
if(SPDLOG_BUILD_HO_TESTS)
|
||||
add_executable(spdlog-utests-ho ${SPDLOG_UTESTS_SOURCES})
|
||||
spdlog_enable_warnings(spdlog-utests-ho)
|
||||
target_link_libraries(spdlog-utests-ho spdlog::spdlog_header_only)
|
||||
target_link_libraries(spdlog-utests-ho PRIVATE spdlog::spdlog_header_only)
|
||||
if(SPDLOG_SANITIZE_ADDRESS)
|
||||
spdlog_set_address_sanitizer(spdlog-utests-ho)
|
||||
endif()
|
||||
|
Loading…
Reference in New Issue
Block a user