3

I'm looking at the documentation for the FindBacktrace module, and unlike with, say, FindThreads - I see no mention of a proper library target I can depend on, e.g. Backtrace::Backtrace. Is it really missing or just undocumented?

Also, when I use this module, I get:

//Library providing backtrace(3), empty for default set of libraries
Backtrace_LIBRARY:FILEPATH=

in my CMakeCache.txt (on a Devuan GNU/Linux machine). This is weird. I'm expecting to see -lbacktrace - because that's where I get backtrace_create_state and backtrace_pcinfo (which I need for using Boost stacktrace).

So, what is the "default set of libraries"? libbacktrace is certainly not linked against by default.

einpoklum
  • 118,144
  • 57
  • 340
  • 684

2 Answers2

1

If one of the CMake-provided Find Modules (e.g. FindBacktrace) provides an imported target, it will almost certainly be documented. You can inspect the source code of the Find Module to be sure. In your case, for FindBacktrace.cmake, just search the file for the :: syntax of the imported target it may provide. At the time of writing, FindBacktrace.cmake does not provide one.

Because many of the Find Modules pre-date the arrival of modern CMake, there are actually many of them that do not yet provide imported targets. I imagine the CMake maintainers are tackling this task as dictated by the need and popularity of each module, so writing a CMake issue for the FindBacktrace module might provoke some action.

If so inspired, you could also write your own modified FindBacktrace.cmake file, adding the requisite CMake code to define the imported target Backtrace::Backtrace.


If the system (e.g. libc) provides support for backtrace(3), it is expected that the Backtrace_LIBRARY variable will be empty. The FindBacktrace module will pick up the default library if available, and populate it in Backtrace_LIBRARIES.

The Backtrace_LIBRARY cache path should only be used if your backtrace is available on your system through some other external library or package, such as on non-glibc systems. In that case, you'll populate Backtrace_LIBRARY manually.

Kevin
  • 16,549
  • 8
  • 60
  • 74
  • 1
    Well, the thing is, it seems that some functionality is not within the system library: `backtrace_create_state`, `backtrace_pcinfo`. I'm trying to use the Boost stacktrace library with backtrace functionality, and it needs these functions. And to have them, I need to add `-lbacktrace` – einpoklum Jul 16 '20 at 22:17
  • @einpoklum If the functionality is not provided via the system library, you'll probably have to grab a different backtrace implementation elsewhere, install it, and then populate the `Backtrace_LIBRARY` cache entry (and potentially `Backtrace_INCLUDE_DIR`) to point CMake to this new installation instead. – Kevin Jul 16 '20 at 22:39
  • It seems it's part of libgcc, so it's kind of a system library; but you still need to link against it explicitly. A bit like libdl I guess, which is part of libc. – einpoklum Jul 16 '20 at 23:07
1

As @squareskittles suggests, this is just something the CMake developers should attend to.

I have filed a bug against CMake on this matter and will (hopefully remember to) update this question to indicate when the module gets updated.

Edit: CMake developers say "merge requests are welcome".

einpoklum
  • 118,144
  • 57
  • 340
  • 684