Skip to content

Commit

Permalink
Rework libbacktrace locating.
Browse files Browse the repository at this point in the history
  • Loading branch information
clemahieu committed Dec 10, 2024
1 parent fe0e44a commit 07aa50f
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,24 @@ endif()
include_directories(${CMAKE_SOURCE_DIR})
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules")

# Find libbacktrace first (Unix/Linux only)
if(NOT WIN32)
find_path(BACKTRACE_INCLUDE_DIR
NAMES backtrace.h
PATHS
/usr/local/include
/usr/include
)

if(BACKTRACE_INCLUDE_DIR)
set(BACKTRACE_FOUND TRUE)
# Most systems just need -lbacktrace
set(BACKTRACE_LIBRARIES backtrace)
message(STATUS "Found backtrace.h at ${BACKTRACE_INCLUDE_DIR}")
endif()
endif()

# Then set up boost modules
set(Boost_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/submodules/boost/libs/config/include)
set(BOOST_MODULE_LIBS
algorithm
Expand Down Expand Up @@ -484,18 +502,22 @@ foreach(lib IN LISTS BOOST_MODULE_LIBS)
add_subdirectory(submodules/boost/libs/${lib} EXCLUDE_FROM_ALL)
endforeach()
include_directories(${BOOST_LIBRARY_INCLUDES})
add_library(Boost::stacktrace ALIAS boost_stacktrace_basic)
add_definitions(-DBOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED)

# Configure stacktrace with appropriate backend
if(WIN32)
# Windows-specific configuration
target_link_libraries(boost_stacktrace_basic PRIVATE dbghelp)
message(STATUS "Windows platform - Using WinDbg stacktrace")
add_definitions(-DBOOST_STACKTRACE_USE_WINDBG)
add_library(Boost::stacktrace ALIAS boost_stacktrace_windbg)
target_link_libraries(boost_stacktrace_windbg PRIVATE dbghelp)
elseif(BACKTRACE_FOUND)
message(STATUS "Found libbacktrace - enabling Boost stacktrace backtrace support")
add_definitions(-DBOOST_STACKTRACE_USE_BACKTRACE)
add_library(Boost::stacktrace ALIAS boost_stacktrace_backtrace)
target_link_libraries(boost_stacktrace_backtrace PRIVATE ${BACKTRACE_LIBRARIES})
else()
# Unix-like systems (Linux, macOS)
target_link_libraries(boost_stacktrace_basic PRIVATE dl)

# Add -rdynamic linker flag for better symbol resolution
target_link_options(boost_stacktrace_basic PRIVATE -rdynamic)
message(STATUS "Unix platform without libbacktrace - Using basic backtrace")
add_definitions(-DBOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED)
add_library(Boost::stacktrace ALIAS boost_stacktrace_basic)
endif()

# Workaround for missing reference errata in the boost property_tree module
Expand Down

0 comments on commit 07aa50f

Please sign in to comment.