diff --git a/CMakeLists.txt b/CMakeLists.txt index c21597f6179..69094b38e1b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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= --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= --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) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 17d4db17aca..6b81f517175 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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})