cmakebacktracecmake-modules

find_package(Backtrace) behaves strangely


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.


Solution

  • 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.