libbacktrace icon indicating copy to clipboard operation
libbacktrace copied to clipboard

Add support for CMake

Open ArekPiekarz opened this issue 7 years ago • 13 comments

CMake is one of the most popular portable build systems for C++. Adding support for it to libbacktrace would greatly simplify integration with other projects and increase the popularity of this library.

There is a standalone fork of libbacktrace with CMake support, but it hasn't been updated in a long time. - https://github.com/ErwanLegrand/libbacktrace. Perhaps it could be used as an inspiration for this project.

ArekPiekarz avatar Mar 04 '18 11:03 ArekPiekarz

This is not something I expect to work on myself.

ianlancetaylor avatar Mar 07 '18 15:03 ianlancetaylor

@ArekPiekar what are some of the use cases that you have in mind? I can take a stab at contributing CMake rules, but without knowing how people embed libbacktrace it's hard to know how to set things up.

thanm avatar Mar 07 '18 17:03 thanm

@thanm I would like to use it together with Boost.Stacktrace, a library for printing stack traces on demand or at application crash. Libbacktrace is one of many backends that Boost.Stacktrace supports, but this one works great for POSIX platforms and MinGW/MinGW-w64.

It recently started working properly in Msys2 environment, so it would make sense to make the library easier for consuming.

Personally I would like to add it as Git submodule in my project and then in CMake use add_subdirectory(), include_directories() and target_link_libraries() with it. But if it gets packaged in Conan, Msys2 repository and/or Ubuntu one, I would rather get it from there and use find_package().

Thanks for the offer and let me know if you need more info.

ArekPiekarz avatar Mar 07 '18 18:03 ArekPiekarz

Hi there,

I also need CMake for my infrastructure and I'm willing to contribute CMakeLists.txt file which I'm working on right now. It's kinda incomplete since I've cheated and used automake to generate backtrace-supported.h.

I'm a noob when it comes to autotools, so can you guide me how backtrace-supported.h is created, so that I can recreate same behavior in CMake?

tehKaiN avatar Jul 13 '18 09:07 tehKaiN

@tehKaiN For creation of backtrace-supported.h I'd suggest looking at the code here -- that should provide a model for how to go about it.

thanm avatar Jul 13 '18 12:07 thanm

+1 for cmake script, it's convenient than auto tools, especaily on windows

dbskccc avatar Nov 07 '18 04:11 dbskccc

+1 for cmake script, it's convenient than auto tools, especially on windows

There is a bug, on Windows 10, which disallows to track the path of libbacktrace, during CMake's execution:

cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS=-stdlib=libc++ -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DGOLLVM_DEFAULT_LINKER=lld -G Ninja ../llvm-project/llvm

-- The C compiler identification is Clang 10.0.0 with GNU-like command-line -- The CXX compiler identification is Clang 10.0.0 with GNU-like command-line -- The ASM compiler identification is Clang -- Found assembler: C:/Program Files/LLVM/bin/clang.exe -- Check for working C compiler: C:/Program Files/LLVM/bin/clang.exe -- Check for working C compiler: C:/Program Files/LLVM/bin/clang.exe -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang++.exe -- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang++.exe -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done (...Checking headers...)

-- Looking for backtrace -- Looking for backtrace - not found -- Could NOT find Backtrace (missing: Backtrace_LIBRARY Backtrace_INCLUDE_DIR)

The above tells me that I have to modify my list of args, for CMake - but I am not sure what should I pass.

Ivan

advancedwebdeveloper avatar Jul 31 '20 18:07 advancedwebdeveloper

CMake is one of the most popular portable build systems for C++. Adding support for it to libbacktrace would greatly simplify integration with other projects and increase the popularity of this library.

There is a standalone fork of libbacktrace with CMake support, but it hasn't been updated in a long time. - https://github.com/ErwanLegrand/libbacktrace. Perhaps it could be used as an inspiration for this project.

@ArekPiekarz , and would indeed would normally integrate this project with https://go.googlesource.com/gollvm/ , where libbacktrace appears to be a dependancy. Same for https://git-scm.com/book/en/v2/Git-Tools-Submodules and hierarchical relations, for the DevOps and version control.

advancedwebdeveloper avatar Aug 09 '20 07:08 advancedwebdeveloper

FWIW this works as a meson subproject with just this

project('libbacktrace', 'c', version: '1.0.0',
  meson_version : '>=0.56.0',
)

mod = import('unstable_external_project')

p = mod.add_project (
  'configure',
  configure_options: [
    '--prefix=@PREFIX@',
    '--libdir=@PREFIX@/@LIBDIR@',
    '--includedir=@PREFIX@/@INCLUDEDIR@',
    ],
  env: {
    'CFLAGS': '-fPIC',
    }
)

libbacktrace_dep = p.dependency('backtrace')

repo here https://github.com/alex-tee/libbacktrace

alex-tee avatar Mar 11 '21 17:03 alex-tee

That's interesting.

advancedwebdeveloper avatar Mar 11 '21 19:03 advancedwebdeveloper

Could anyone tell if it is possible to cross-compile libbacktrace, on Windows 10 host, to target x86_64 Linux?

Considering Clang, as a compiler.

advancedwebdeveloper avatar Mar 11 '21 19:03 advancedwebdeveloper

If anyone is interested, I've partially ported the build to cmake.

  • https://github.com/rsms/ckit/blob/main/pkg/rbase/backtrace/cmakelists.txt
  • https://github.com/rsms/ckit/blob/main/pkg/rbase/backtrace/config.h.in.cmake

Caveats:

  • So far only tested on macOS.
  • No COFF.
  • No BACKTRACE_ELF_SIZE or BACKTRACE_XCOFF_SIZE.
  • No tests (I run them separately)

rsms avatar May 31 '21 01:05 rsms