Skip to content

Commit

Permalink
build: add address/thread/memory sanitizers as option (#792)
Browse files Browse the repository at this point in the history
See [sanitizers-cmake](https://github.com/arsenm/sanitizers-cmake)
for reference.

This allows e.g. building with -DSANITIZE_ADDRESS=On and then
running the unit tests.

Signed-off-by: Don Bowman <[email protected]>
  • Loading branch information
donbowman authored and edsiper committed Sep 25, 2018
1 parent 75d3f90 commit 69eee3f
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "cmake/sanitizers-cmake"]
path = cmake/sanitizers-cmake
url = git://github.com/arsenm/sanitizers-cmake.git
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ include(GNUInstallDirs)
include(ExternalProject)
include(cmake/FindJournald.cmake)
include(cmake/FindMonkey.cmake)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/sanitizers-cmake/cmake" ${CMAKE_MODULE_PATH})
find_package(Sanitizers)

# Output paths
set(FLB_ROOT "${CMAKE_CURRENT_SOURCE_DIR}")
Expand Down
1 change: 1 addition & 0 deletions cmake/sanitizers-cmake
Submodule sanitizers-cmake added at aab694
1 change: 1 addition & 0 deletions plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ endmacro()
macro(FLB_PLUGIN name src deps)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
add_library(flb-plugin-${name} STATIC ${src})
add_sanitizers(flb-plugin-${name})
target_link_libraries(flb-plugin-${name} fluent-bit-static msgpackc-static ${deps})
endmacro()

Expand Down
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ set(FLB_DEPS
# Shared Library
if(FLB_SHARED_LIB)
add_library(fluent-bit-shared SHARED ${src})
add_sanitizers(fluent-bit-shared)
target_link_libraries(fluent-bit-shared ${FLB_DEPS} -lpthread)
set_target_properties(fluent-bit-shared
PROPERTIES OUTPUT_NAME fluent-bit)
Expand All @@ -221,6 +222,7 @@ endif()

# Static Library
add_library(fluent-bit-static STATIC ${src})
add_sanitizers(fluent-bit-static)
target_link_libraries(fluent-bit-static ${FLB_DEPS})

if(MSVC)
Expand All @@ -242,6 +244,7 @@ endif()
if(FLB_BINARY)
find_package (Threads)
add_executable(fluent-bit-bin fluent-bit.c)
add_sanitizers(fluent-bit-bin)

if(FLB_STATIC_CONF)
add_dependencies(fluent-bit-bin flb-static-conf)
Expand Down
1 change: 1 addition & 0 deletions tests/internal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ foreach(source_file ${UNIT_TESTS_FILES})
${source_file_we}
${source_file}
)
add_sanitizers(${source_file_we})

if(FLB_JEMALLOC)
target_link_libraries(${source_file_we} libjemalloc ${CMAKE_THREAD_LIBS_INIT})
Expand Down
1 change: 1 addition & 0 deletions tests/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ foreach(source_file ${CHECK_PROGRAMS})
${source_file_we}
${source_file}
)
add_sanitizers(${source_file_we})
target_link_libraries(${source_file_we}
fluent-bit-static
${CMAKE_THREAD_LIBS_INIT}
Expand Down

0 comments on commit 69eee3f

Please sign in to comment.