Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions M2/Macaulay2/bin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ target_link_libraries(M2-binary
${Boost_stacktrace_lib}
M2-supervisor M2-engine M2-interpreter ${CMAKE_DL_LIBS})

#if we have a usable link time stacktrace library, force boost to use it
if(NOT Boost_stacktrace_header_only)
target_compile_definitions(M2-binary PUBLIC BOOST_STACKTRACE_LINK)
endif()
target_compile_definitions(M2-binary PUBLIC ${Boost_stacktrace_definitions})

# Set where the executable should be store and get its RPATH
set_target_properties(M2-binary PROPERTIES
Expand Down
3 changes: 0 additions & 3 deletions M2/Macaulay2/bin/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#define BOOST_STACKTRACE_USE_ADDR2LINE /* show source file and line number */
// #define BOOST_STACKTRACE_USE_NOOP /* disable stacktrace */

#include <M2/gc-include.h>

#include "interp-exports.h"
Expand Down
32 changes: 17 additions & 15 deletions M2/cmake/check-libraries.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,25 @@ if(STATIC_BOOST)
message(STATUS "Using static Boost, if Boost is installed but not found, try setting STATIC_BOOST to OFF")
endif()
set(Boost_USE_STATIC_LIBS ${STATIC_BOOST})
if(UNIX)
cmake_policy(SET CMP0167 OLD) # load CMake's FindBoost module
find_package(Boost REQUIRED QUIET COMPONENTS regex OPTIONAL_COMPONENTS stacktrace_addr2line)
else()
find_package(Boost REQUIRED QUIET COMPONENTS regex OPTIONAL_COMPONENTS stacktrace_backtrace)
endif()
if(Boost_STACKTRACE_BACKTRACE_FOUND)
set(Boost_stacktrace_lib "Boost::stacktrace_backtrace")
elseif(Boost_STACKTRACE_ADDR2LINE_FOUND)
set(Boost_stacktrace_lib "Boost::stacktrace_addr2line")
else()
#fallback to header only mode
set(Boost_stacktrace_header_only YES)
find_package(Boost REQUIRED QUIET COMPONENTS regex
OPTIONAL_COMPONENTS stacktrace_backtrace)

# Finding a component only proves the Boost library exists, not that its backend can work.
check_library_exists(backtrace backtrace_create_state "" LIBBACKTRACE)
find_program(ADDR2LINE NAMES addr2line llvm-addr2line)

if(Boost_STACKTRACE_BACKTRACE_FOUND AND LIBBACKTRACE)
set(Boost_stacktrace_lib Boost::stacktrace_backtrace backtrace)
set(Boost_stacktrace_definitions BOOST_STACKTRACE_LINK)
elseif(ADDR2LINE)
# only header-only mode reads BOOST_STACKTRACE_USE_* and lets us set the addr2line path
set(Boost_stacktrace_definitions BOOST_STACKTRACE_USE_ADDR2LINE
BOOST_STACKTRACE_ADDR2LINE_LOCATION=${ADDR2LINE})
endif()
set(CMAKE_REQUIRED_INCLUDES "${Boost_INCLUDE_DIR}")

set(CMAKE_REQUIRED_INCLUDES "${Boost_INCLUDE_DIRS}")
check_include_files(boost/math/tools/atomic.hpp
HAVE_BOOST_MATH_TOOLS_ATOMIC_HPP)
HAVE_BOOST_MATH_TOOLS_ATOMIC_HPP LANGUAGE CXX) # C++ only header

# TODO: replace gdbm, see https://github.com/Macaulay2/M2/issues/594
find_package(GDBM REQUIRED QUIET) # See FindGDBM.cmake
Expand Down
37 changes: 18 additions & 19 deletions M2/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1411,28 +1411,27 @@ AX_BOOST_BASE([1.65],,
CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"

AC_MSG_CHECKING([whether the Boost::Stacktrace library is available])
AC_LANG(C++)
dnl the addr2line backend execs this, and boost's default of /usr/bin/addr2line is absent on macOS
AC_PATH_PROGS([ADDR2LINE], [addr2line llvm-addr2line])
dnl the backtrace backend needs libbacktrace, which the boost library may not carry itself
AC_CHECK_LIB([backtrace], [backtrace_create_state], [LIBS="-lbacktrace $LIBS"])

AC_MSG_CHECKING([which Boost::Stacktrace backend is usable])
SAVECPPFLAGS=$CPPFLAGS
CPPFLAGS="$CPPFLAGS -DBOOST_STACKTRACE_LINK"
SAVELIBS=$LIBS
FOUND_stacktrace_library=no
for stacktrace_library in backtrace addr2line
do
LIBS="$SAVELIBS -lboost_stacktrace_${stacktrace_library}"
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([#include <boost/stacktrace.hpp>
], [boost::stacktrace::stacktrace();])],
[AC_MSG_RESULT([yes, boost_stacktrace_${stacktrace_library}])
FOUND_stacktrace_library=yes
break],)
done
if test $FOUND_stacktrace_library = no
then
AC_MSG_RESULT([no, will use header-only library])
CPPFLAGS=$SAVECPPFLAGS
LIBS=$SAVELIBS
fi
CPPFLAGS="$CPPFLAGS -DBOOST_STACKTRACE_LINK"
LIBS="$LIBS -lboost_stacktrace_backtrace"
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([#include <boost/stacktrace.hpp>
], [boost::stacktrace::stacktrace();])],
[AC_MSG_RESULT([boost_stacktrace_backtrace])],
dnl only header-only mode reads BOOST_STACKTRACE_USE_* and lets us set the addr2line path
[AC_MSG_RESULT([header-only${ADDR2LINE:+ with $ADDR2LINE}])
CPPFLAGS=$SAVECPPFLAGS
LIBS=$SAVELIBS
AS_IF([test -n "$ADDR2LINE"],
[CPPFLAGS="$CPPFLAGS -DBOOST_STACKTRACE_USE_ADDR2LINE -DBOOST_STACKTRACE_ADDR2LINE_LOCATION=$ADDR2LINE"])])

AX_BOOST_REGEX
LIBS="$LIBS $BOOST_REGEX_LIB"
Expand Down
Loading