diff options
author | gabime <gmelman1@gmail.com> | 2019-06-10 18:32:10 +0300 |
---|---|---|
committer | gabime <gmelman1@gmail.com> | 2019-06-10 18:32:10 +0300 |
commit | cf64f2baca27005037c3b962f78a519c38a6ab64 (patch) | |
tree | ccc4f1ab2484a35215a1e324393811ccb1101cf5 | |
parent | 68a0193d952eb0b39ccb54e3a8c60b72c3f189a9 (diff) |
Fixed CMake address sanitizer
-rw-r--r-- | CMakeLists.txt | 3 | ||||
-rw-r--r-- | cmake/utils.cmake | 38 | ||||
-rw-r--r-- | example/CMakeLists.txt | 4 | ||||
-rw-r--r-- | tests/CMakeLists.txt | 10 |
4 files changed, 28 insertions, 27 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 519233cb..e94a4e5f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -57,7 +58,7 @@ find_package(Threads REQUIRED) #--------------------------------------------------------------------------------------- add_library(spdlog STATIC src/spdlog.cpp ${SPDLOG_ALL_HEADERS}) add_library(spdlog::spdlog ALIAS spdlog) - + target_compile_definitions(spdlog PUBLIC SPDLOG_COMPILED_LIB) target_include_directories(spdlog PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>" diff --git a/cmake/utils.cmake b/cmake/utils.cmake index 5ed8f9ce..4d58de35 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -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()
\ No newline at end of file +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()
diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 1f22b990..ac738161 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -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") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b4192e79..110e2bbf 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -22,21 +22,21 @@ 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() - add_test(NAME spdlog-utests COMMAND spdlog-utests) - + add_test(NAME spdlog-utests COMMAND spdlog-utests) + endif() # The header-only library version tests 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() add_test(NAME spdlog-utests-ho COMMAND spdlog-utests-ho) -endif()
\ No newline at end of file +endif() |