boostorg / stacktrace

C++ library for storing and printing backtraces.
https://boost.org/libs/stacktrace
433 stars 74 forks source link

Please explain how to detect this library with cmake #66

Closed mquinson closed 6 years ago

mquinson commented 6 years ago

Hello,

detecting this library with cmake is a bit challenging and could deserve some words in the documentation. This is due to two facts.

First, stacktrace is not a library on its own, but it proposes several libraries. So the line in CMakeFiles.txt should not read find_package(Boost COMPONENTS stacktrace) but for example find_package(Boost COMPONENTS stacktrace_backtrace) This should really be said in the documentation of this library, IMHO.

The second problem is that modern cmake don't know about this library. See bug 17297. What is missing is the header files associated with each sublibraries. On my Debian system, I need to add the following lines before my call to find_ package(Boost ....)

set(_Boost_STACKTRACE_BASIC_HEADERS     "boost/stacktrace.hpp")
set(_Boost_STACKTRACE_BACKTRACE_HEADERS "boost/stacktrace.hpp")
set(_Boost_STACKTRACE_ADDR2LINE_HEADERS "boost/stacktrace.hpp")
set(_Boost_STACKTRACE_NOOP_HEADERS      "boost/stacktrace.hpp")

These values are not perfect, and we should use a header file that is only available when this sublibrary is available, but I don't know boost enough... Do you have a better list to be included in cmake, maybe?

apolukhin commented 6 years ago

Boost does not have a CMake integration right now. We are working to change that fact, but it would not happen in this year.

If you wish to do the detection on your own, then detect that header boost/stacktrace.hpp is available and make separate targets for each of the stacktrce libraries from here: http://boostorg.github.io/stacktrace/stacktrace/configuration_and_build.html . Do not forget to add a public macro definition BOOST_STACKTRACE_LINK to each of those targets.

Make a target boost_stacktrace that chooses the best available library. Order of usefulness (from the most usefull one): boost_stacktrace_windbg_cached, boost_stacktrace_windbg, boost_stacktrace_backtrace, [boost_stacktrace_addr2line,] boost_stacktrace_basic, boost_stacktrace_noop.

Done. Now users could use target boost_stacktrace if they need some stacktracing, target boost_stacktrace_noop if they do not need one. Advanced users could manually choose stacktrace libraries. Changing a target would not cause project recompilation.

mquinson commented 6 years ago

Hello,

it was not really a question, but a request for documentation. But you decide.

Thanks for the library anyway. Mt