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.

Signed-off-by: Thomas Devoogdt <[email protected]>
  • Loading branch information
ThomasDevoogdt committed Jun 8, 2024
1 parent 32f839b commit 4c6da55
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
43 changes: 26 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -998,25 +998,34 @@ endif()
# =========================================
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}")
find_path(LIBBACKTRACE_INCLUDE_DIRS NAMES backtrace.h)
find_library(LIBBACKTRACE_LIBRARIES NAMES backtrace)
if(LIBBACKTRACE_INCLUDE_DIRS_NOTFOUND OR LIBBACKTRACE_LIBRARIES_NOTFOUND)
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")
else()
set(DEPS_C_COMPILER "${CMAKE_C_COMPILER}")
message(STATUS "libbacktrace found (${LIBBACKTRACE_LIBRARIES})")
include_directories(${LIBBACKTRACE_INCLUDE_DIRS})
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/")
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 4c6da55

Please sign in to comment.