Skip to content

Add cmake option to disable the stacktrace functionality. #3777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
2 changes: 2 additions & 0 deletions src/cmake/externalpackages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ endif ()
include_directories (SYSTEM "${Boost_INCLUDE_DIRS}")
link_directories ("${Boost_LIBRARY_DIRS}")

option (OIIO_DISABLE_BOOST_STACKTRACE "Disable use of Boost stacktrace." OFF)

# end Boost setup
###########################################################################

Expand Down
4 changes: 4 additions & 0 deletions src/libutil/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ if (NOT BUILD_SHARED_LIBS)
target_compile_definitions (OpenImageIO_Util PUBLIC OIIO_STATIC_DEFINE=1)
endif ()

if (OIIO_DISABLE_BOOST_STACKTRACE)
target_compile_definitions (OpenImageIO_Util PRIVATE OIIO_DISABLE_BOOST_STACKTRACE)
endif ()

# Propagate C++ minimum to downstream consumers
target_compile_features (OpenImageIO_Util
INTERFACE cxx_std_${DOWNSTREAM_CXX_STANDARD})
Expand Down
12 changes: 7 additions & 5 deletions src/libutil/sysutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@
# ifndef _GNU_SOURCE
# define _GNU_SOURCE
# endif
# include <boost/stacktrace.hpp>
# if !defined(OIIO_DISABLE_BOOST_STACKTRACE)
# include <boost/stacktrace.hpp>
# endif
#endif

// clang 7.0 (rc2) has errors when including boost thread!
Expand Down Expand Up @@ -662,7 +664,7 @@ aligned_free(void* ptr)
std::string
Sysutil::stacktrace()
{
#if BOOST_VERSION >= 106500
#if BOOST_VERSION >= 106500 && !defined(OIIO_DISABLE_BOOST_STACKTRACE)
std::stringstream out;
out << boost::stacktrace::stacktrace();
return out.str();
Expand All @@ -673,7 +675,7 @@ Sysutil::stacktrace()



#if BOOST_VERSION >= 106500
#if BOOST_VERSION >= 106500 && !defined(OIIO_DISABLE_BOOST_STACKTRACE)

static std::string stacktrace_filename;
static std::mutex stacktrace_filename_mutex;
Expand All @@ -688,7 +690,7 @@ stacktrace_signal_handler(int signum)
else if (stacktrace_filename == "stderr")
std::cerr << Sysutil::stacktrace();
else {
# if BOOST_VERSION >= 106500
# if BOOST_VERSION >= 106500 && !defined(OIIO_DISABLE_BOOST_STACKTRACE)
boost::stacktrace::safe_dump_to(stacktrace_filename.c_str());
# endif
}
Expand All @@ -703,7 +705,7 @@ stacktrace_signal_handler(int signum)
bool
Sysutil::setup_crash_stacktrace(string_view filename)
{
#if BOOST_VERSION >= 106500
#if BOOST_VERSION >= 106500 && !defined(OIIO_DISABLE_BOOST_STACKTRACE)
std::lock_guard<std::mutex> lock(stacktrace_filename_mutex);
stacktrace_filename = filename;
::signal(SIGSEGV, &stacktrace_signal_handler);
Expand Down