Skip to content

Commit

Permalink
build: use the system provided backtrace if found
Browse files Browse the repository at this point in the history
e.g. buildroot has logic to build backtrace,
so if find_path/find_library can find a suitable version,
then use that one if -DFLB_PREFER_SYSTEM_LIBS=Yes.

Signed-off-by: Thomas Devoogdt <[email protected]>
  • Loading branch information
ThomasDevoogdt committed Jun 10, 2024
1 parent 0c86f56 commit e82979a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
48 changes: 30 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -987,26 +987,38 @@ endif()
# LibBacktrace (friendly stacktrace support)
# =========================================
if(FLB_BACKTRACE)
FLB_DEFINITION(FLB_HAVE_LIBBACKTRACE)
if (CMAKE_OSX_SYSROOT)
# From macOS Mojave, /usr/include does not store C SDK headers.
# For libbacktrace building on macOS, we have to tell C headers where they are located.
set(DEPS_C_COMPILER "${CMAKE_C_COMPILER} -isysroot ${CMAKE_OSX_SYSROOT}")
if(FLB_PREFER_SYSTEM_LIBS)
find_path(LIBBACKTRACE_INCLUDE_DIRS NAMES backtrace.h)
find_library(LIBBACKTRACE_LIBRARIES NAMES backtrace)
endif()
if(LIBBACKTRACE_INCLUDE_DIRS AND LIBBACKTRACE_LIBRARIES)
message(STATUS "libbacktrace found (${LIBBACKTRACE_LIBRARIES})")
include_directories(${LIBBACKTRACE_INCLUDE_DIRS})
link_directories(${LIBBACKTRACE_LIBRARY_DIRS})
else()
set(DEPS_C_COMPILER "${CMAKE_C_COMPILER}")
message(STATUS "libbacktrace not found, building ourselves")
if (CMAKE_OSX_SYSROOT)
# From macOS Mojave, /usr/include does not store C SDK headers.
# For libbacktrace building on macOS, we have to tell C headers where they are located.
set(DEPS_C_COMPILER "${CMAKE_C_COMPILER} -isysroot ${CMAKE_OSX_SYSROOT}")
else()
set(DEPS_C_COMPILER "${CMAKE_C_COMPILER}")
endif()
set(FLB_LIBBACKTRACE_PATH "${CMAKE_CURRENT_BINARY_DIR}/backtrace-prefix/lib/libbacktrace.a")
ExternalProject_Add(backtrace
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib/libbacktrace-8602fda/
CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/lib/libbacktrace-8602fda/configure ${AUTOCONF_HOST_OPT} --prefix=<INSTALL_DIR> --enable-shared=no --enable-static=yes
BUILD_COMMAND ${EXTERNAL_BUILD_TOOL}
BUILD_BYPRODUCTS ${FLB_LIBBACKTRACE_PATH}
INSTALL_COMMAND ${EXTERNAL_BUILD_TOOL} DESTDIR= install
)
add_library(libbacktrace STATIC IMPORTED GLOBAL)
set_target_properties(libbacktrace PROPERTIES IMPORTED_LOCATION ${FLB_LIBBACKTRACE_PATH})
add_dependencies(libbacktrace backtrace)
include_directories("${CMAKE_CURRENT_BINARY_DIR}/backtrace-prefix/include/")
set(LIBBACKTRACE_LIBRARIES "libbacktrace")
endif()
set(FLB_LIBBACKTRACE_PATH "${CMAKE_CURRENT_BINARY_DIR}/backtrace-prefix/lib/libbacktrace.a")
ExternalProject_Add(backtrace
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib/libbacktrace-8602fda/
CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/lib/libbacktrace-8602fda/configure ${AUTOCONF_HOST_OPT} --prefix=<INSTALL_DIR> --enable-shared=no --enable-static=yes
BUILD_COMMAND ${EXTERNAL_BUILD_TOOL}
BUILD_BYPRODUCTS ${FLB_LIBBACKTRACE_PATH}
INSTALL_COMMAND ${EXTERNAL_BUILD_TOOL} DESTDIR= install
)
add_library(libbacktrace STATIC IMPORTED GLOBAL)
set_target_properties(libbacktrace PROPERTIES IMPORTED_LOCATION ${FLB_LIBBACKTRACE_PATH})
add_dependencies(libbacktrace backtrace)
include_directories("${CMAKE_CURRENT_BINARY_DIR}/backtrace-prefix/include/")
FLB_DEFINITION(FLB_HAVE_LIBBACKTRACE)
endif()

if(FLB_IN_KAFKA OR FLB_OUT_KAFKA)
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ if(FLB_BINARY)

if(FLB_BACKTRACE)
add_definitions(-DFLB_DUMP_STACKTRACE=1)
target_link_libraries(fluent-bit-bin libbacktrace)
target_link_libraries(fluent-bit-bin ${LIBBACKTRACE_LIBRARIES})
endif()

target_link_libraries(fluent-bit-bin fluent-bit-static ${CMAKE_THREAD_LIBS_INIT})
Expand Down

0 comments on commit e82979a

Please sign in to comment.