Skip to content
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

Add support for CMake #12

Open
ArekPiekarz opened this issue Mar 4, 2018 · 13 comments · May be fixed by #19
Open

Add support for CMake #12

ArekPiekarz opened this issue Mar 4, 2018 · 13 comments · May be fixed by #19

Comments

@ArekPiekarz
Copy link

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.

@ianlancetaylor
Copy link
Owner

This is not something I expect to work on myself.

@thanm
Copy link
Contributor

thanm commented Mar 7, 2018

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

@ArekPiekarz
Copy link
Author

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

@tehKaiN
Copy link

tehKaiN commented Jul 13, 2018

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?

@thanm
Copy link
Contributor

thanm commented Jul 13, 2018

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

@tehKaiN tehKaiN linked a pull request Jul 16, 2018 that will close this issue
@dbskccc
Copy link

dbskccc commented Nov 7, 2018

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

@advancedwebdeveloper
Copy link

+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
Copy link

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.

@alex-tee
Copy link

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

@advancedwebdeveloper
Copy link

That's interesting.

@advancedwebdeveloper
Copy link

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.

@rsms
Copy link

rsms commented May 31, 2021

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

Caveats:

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

@sc0rp10n-py
Copy link

sc0rp10n-py commented Feb 4, 2024

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

hey @alex-tee
can you please tell me exact steps to use this?

see this issue for reference

{EDIT}
for anyone who comes and face this later on follow this

git clone https://github.com/ianlancetaylor/libbacktrace.git
cd libbacktrace 
mkdir build 
cd build 
./configure 
sudo make 
sudo make install

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants