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 libbacktrace package #174

Merged
merged 13 commits into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmake/configs/default.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ hunter_default_version(kbproto VERSION 1.0.7)
hunter_default_version(lcms VERSION 2.9-p0)
hunter_default_version(lehrfempp VERSION 0.7.21)
hunter_default_version(leveldb VERSION 1.22)
hunter_default_version(libbacktrace VERSION 1.0.0-ca0de051)
hunter_default_version(libcpuid VERSION 0.4.0)
hunter_default_version(libdaemon VERSION 0.14)
hunter_default_version(libdill VERSION 1.6)
Expand Down
71 changes: 71 additions & 0 deletions cmake/find/Findlibbacktrace.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.

#.rst:
# Findlibbacktrace
# -------
#
# Finds the libbacktrace library
#
# This will define the following variables::
#
# libbacktrace_FOUND - True if the system has the libbacktrace library
# libbacktrace_VERSION - The version of the libbacktrace library which was found
#
# and the following imported targets::
#
# libbacktrace::libbacktrace - The libbacktrace library

find_path(libbacktrace_INCLUDE_DIR
NAMES backtrace.h
PATHS "${libbacktrace_ROOT}/include"
)

if(WIN32)
set(_libbacktrace_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
set(_libbacktrace_ORIG_CMAKE_FIND_LIBRARY_PREFIXES ${CMAKE_FIND_LIBRARY_PREFIXES})
set(CMAKE_FIND_LIBRARY_SUFFIXES .so .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
set(CMAKE_FIND_LIBRARY_PREFIXES lib ${CMAKE_FIND_LIBRARY_PREFIXES})
endif()

find_library(libbacktrace_LIBRARY
NAMES backtrace
PATHS "${libbacktrace_ROOT}/lib"
)

if(WIN32)
# Restore the original find library ordering
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_libbacktrace_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the variable reset again. Could you explain?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be "reset" because other find_library() in other modules etc. shouldn't be affected ! See also FindBoost and other find modules. They all do it that way ... I added a comment.

set(CMAKE_FIND_LIBRARY_PREFIXES ${_libbacktrace_ORIG_CMAKE_FIND_LIBRARY_PREFIXES})
endif()

set(libbacktrace_VERSION ${PC_libbacktrace_VERSION})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(libbacktrace
FOUND_VAR libbacktrace_FOUND
REQUIRED_VARS
libbacktrace_LIBRARY
libbacktrace_INCLUDE_DIR
VERSION_VAR libbacktrace_VERSION
)

if(libbacktrace_FOUND)
set(libbacktrace_LIBRARIES ${libbacktrace_LIBRARY})
set(libbacktrace_INCLUDE_DIRS ${libbacktrace_INCLUDE_DIR})
set(libbacktrace_DEFINITIONS ${PC_libbacktrace_CFLAGS_OTHER})
endif()

if(libbacktrace_FOUND AND NOT TARGET libbacktrace::libbacktrace)
add_library(libbacktrace::libbacktrace UNKNOWN IMPORTED)
set_target_properties(libbacktrace::libbacktrace PROPERTIES
IMPORTED_LOCATION "${libbacktrace_LIBRARY}"
INTERFACE_COMPILE_OPTIONS "${PC_libbacktrace_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${libbacktrace_INCLUDE_DIR}"
)
endif()

mark_as_advanced(
libbacktrace_INCLUDE_DIR
libbacktrace_LIBRARY
)
28 changes: 28 additions & 0 deletions cmake/projects/libbacktrace/hunter.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# !!! DO NOT PLACE HEADER GUARDS HERE !!!

include(hunter_add_version)
include(hunter_cacheable)
include(hunter_configuration_types)
include(hunter_download)
include(hunter_pick_scheme)

hunter_add_version(
PACKAGE_NAME
libbacktrace
VERSION
1.0.0-ca0de051
URL
"https://github.com/ianlancetaylor/libbacktrace/archive/ca0de0517f3be44fedf5a2c01cfaf6437d4cae68.tar.gz"
SHA1
7c7db4d096d96f329c453fb97b7a456fe823e943
)

hunter_configuration_types(libbacktrace CONFIGURATION_TYPES Release)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why hard code the configutation types. If debug is not supportet please add a comment about the reasons

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it uses the autotools scheme and this can only build one build type. If you remove this it will show an error:

[hunter ** FATAL ERROR **] Autotools PACKAGE_CONFIGURATION_TYPES has 2 elements: Release                                                                                                     
[hunter ** FATAL ERROR **] Debug. Only 1 is allowed                                                                                                                                          
[hunter ** FATAL ERROR **] [Directory:/source/hunter/_testing/Hunter/_Base/4ed7980/0fca6e7/2f6b703/Build/libbacktrace]                                                                       
                                                                                                                                                                                             
------------------------------ ERROR -----------------------------                                                                                                                           
    https://hunter.readthedocs.io/en/latest/reference/errors/autools.package.configuration.types.html                                                                                        
------------------------------------------------------------------                                                                                                                           
                                                                                                                                                                                             
CMake Error at /source/hunter/_testing/Hunter/_Base/Download/Hunter/unknown/4ed7980/Unpacked/cmake/modules/hunter_error_page.cmake:12 (message):                                             
Call Stack (most recent call first):                                                                                                                                                         
  /source/hunter/_testing/Hunter/_Base/Download/Hunter/unknown/4ed7980/Unpacked/cmake/modules/hunter_fatal_error.cmake:20 (hunter_error_page)                                                
  /source/hunter/_testing/Hunter/_Base/Download/Hunter/unknown/4ed7980/Unpacked/cmake/modules/hunter_autotools_configure_command.cmake:164 (hunter_fatal_error)                              
  /source/hunter/_testing/Hunter/_Base/Download/Hunter/unknown/4ed7980/Unpacked/cmake/modules/hunter_autotools_project.cmake:158 (hunter_autotools_configure_command)                        
  CMakeLists.txt:40 (hunter_autotools_project)

hunter_pick_scheme(DEFAULT url_sha1_autotools)
hunter_cacheable(libbacktrace)
hunter_download(
PACKAGE_NAME libbacktrace
PACKAGE_INTERNAL_DEPS_ID "1"
PACKAGE_UNRELOCATABLE_TEXT_FILES
"lib/libbacktrace.la"
)
20 changes: 20 additions & 0 deletions docs/packages/pkg/libbacktrace.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.. spelling::

libbacktrace

.. index::
single: Logging ; libbacktrace

.. _pkg.libbacktrace:

libbacktrace
============

- `Official <https://github.com/ianlancetaylor/libbacktrace>`__
- `Example <https://github.com/cpp-pm/hunter/blob/master/examples/libbacktrace/CMakeLists.txt>`__
- Added by `Joerg-Christian Boehme <https://github.com/Bjoe>`__ (`pr-174 <https://github.com/cpp-pm/hunter/pull/174>`__)

.. literalinclude:: /../examples/libbacktrace/CMakeLists.txt
:language: cmake
:start-after: # DOCUMENTATION_START {
:end-before: # DOCUMENTATION_END }
18 changes: 18 additions & 0 deletions examples/libbacktrace/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c)
# All rights reserved.

cmake_minimum_required(VERSION 3.2)

# Emulate HunterGate:
# * https://github.com/cpp-pm/gate
include("../common.cmake")

project(download-libbacktrace)

# DOCUMENTATION_START {
hunter_add_package(libbacktrace)
find_package(libbacktrace REQUIRED)

add_executable(boo boo.cpp)
target_link_libraries(boo PUBLIC libbacktrace::libbacktrace)
# DOCUMENTATION_END }
6 changes: 6 additions & 0 deletions examples/libbacktrace/boo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <backtrace.h>

int main() {
backtrace_state* state = nullptr;
return 0;
}