| 1 |
#.rst: |
| 2 |
# FindBacktrace |
| 3 |
# ------------- |
| 4 |
# |
| 5 |
# Find provider for backtrace(3). |
| 6 |
# |
| 7 |
# Checks if OS supports backtrace(3) via either libc or custom library. |
| 8 |
# This module defines the following variables: |
| 9 |
# |
| 10 |
# ``Backtrace_HEADER`` |
| 11 |
# The header file needed for backtrace(3). Cached. |
| 12 |
# Could be forcibly set by user. |
| 13 |
# ``Backtrace_INCLUDE_DIRS`` |
| 14 |
# The include directories needed to use backtrace(3) header. |
| 15 |
# ``Backtrace_LIBRARIES`` |
| 16 |
# The libraries (linker flags) needed to use backtrace(3), if any. |
| 17 |
# ``Backtrace_FOUND`` |
| 18 |
# Is set if and only if backtrace(3) support detected. |
| 19 |
# |
| 20 |
# The following cache variables are also available to set or use: |
| 21 |
# |
| 22 |
# ``Backtrace_LIBRARY`` |
| 23 |
# The external library providing backtrace, if any. |
| 24 |
# ``Backtrace_INCLUDE_DIR`` |
| 25 |
# The directory holding the backtrace(3) header. |
| 26 |
# |
| 27 |
# Typical usage is to generate of header file using configure_file() with the |
| 28 |
# contents like the following:: |
| 29 |
# |
| 30 |
# #cmakedefine01 Backtrace_FOUND |
| 31 |
# #if Backtrace_FOUND |
| 32 |
# # include <${Backtrace_HEADER}> |
| 33 |
# #endif |
| 34 |
# |
| 35 |
# And then reference that generated header file in actual source. |
| 36 |
|
| 37 |
#============================================================================= |
| 38 |
# Copyright 2013 Vadim Zhukov |
| 39 |
# Copyright 2000-2016 Kitware, Inc. |
| 40 |
# Copyright 2000-2011 Insight Software Consortium |
| 41 |
# All rights reserved. |
| 42 |
# |
| 43 |
# Redistribution and use in source and binary forms, with or without |
| 44 |
# modification, are permitted provided that the following conditions |
| 45 |
# are met: |
| 46 |
# |
| 47 |
# * Redistributions of source code must retain the above copyright |
| 48 |
# notice, this list of conditions and the following disclaimer. |
| 49 |
# |
| 50 |
# * Redistributions in binary form must reproduce the above copyright |
| 51 |
# notice, this list of conditions and the following disclaimer in the |
| 52 |
# documentation and/or other materials provided with the distribution. |
| 53 |
# |
| 54 |
# * Neither the names of Kitware, Inc., the Insight Software Consortium, |
| 55 |
# nor the names of their contributors may be used to endorse or promote |
| 56 |
# products derived from this software without specific prior written |
| 57 |
# permission. |
| 58 |
# |
| 59 |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 60 |
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 61 |
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 62 |
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 63 |
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 64 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 65 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 66 |
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 67 |
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 68 |
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 69 |
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 70 |
#============================================================================= |
| 71 |
|
| 72 |
include(CMakePushCheckState) |
| 73 |
include(CheckSymbolExists) |
| 74 |
include(FindPackageHandleStandardArgs) |
| 75 |
|
| 76 |
# List of variables to be provided to find_package_handle_standard_args() |
| 77 |
set(_Backtrace_STD_ARGS Backtrace_INCLUDE_DIR) |
| 78 |
|
| 79 |
if(Backtrace_HEADER) |
| 80 |
set(_Backtrace_HEADER_TRY "${Backtrace_HEADER}") |
| 81 |
else(Backtrace_HEADER) |
| 82 |
set(_Backtrace_HEADER_TRY "execinfo.h") |
| 83 |
endif(Backtrace_HEADER) |
| 84 |
|
| 85 |
find_path(Backtrace_INCLUDE_DIR "${_Backtrace_HEADER_TRY}") |
| 86 |
set(Backtrace_INCLUDE_DIRS ${Backtrace_INCLUDE_DIR}) |
| 87 |
|
| 88 |
if (NOT DEFINED Backtrace_LIBRARY) |
| 89 |
# First, check if we already have backtrace(), e.g., in libc |
| 90 |
cmake_push_check_state(RESET) |
| 91 |
set(CMAKE_REQUIRED_INCLUDES ${Backtrace_INCLUDE_DIRS}) |
| 92 |
set(CMAKE_REQUIRED_QUIET ${Backtrace_FIND_QUIETLY}) |
| 93 |
check_symbol_exists("backtrace" "${_Backtrace_HEADER_TRY}" _Backtrace_SYM_FOUND) |
| 94 |
cmake_pop_check_state() |
| 95 |
endif() |
| 96 |
|
| 97 |
if(_Backtrace_SYM_FOUND) |
| 98 |
# Avoid repeating the message() call below each time CMake is run. |
| 99 |
if(NOT Backtrace_FIND_QUIETLY AND NOT DEFINED Backtrace_LIBRARY) |
| 100 |
message(STATUS "backtrace facility detected in default set of libraries") |
| 101 |
endif() |
| 102 |
set(Backtrace_LIBRARY "" CACHE FILEPATH "Library providing backtrace(3), empty for default set of libraries") |
| 103 |
else() |
| 104 |
# Check for external library, for non-glibc systems |
| 105 |
if(Backtrace_INCLUDE_DIR) |
| 106 |
# OpenBSD has libbacktrace renamed to libexecinfo |
| 107 |
find_library(Backtrace_LIBRARY "execinfo") |
| 108 |
elseif() # respect user wishes |
| 109 |
set(_Backtrace_HEADER_TRY "backtrace.h") |
| 110 |
find_path(Backtrace_INCLUDE_DIR ${_Backtrace_HEADER_TRY}) |
| 111 |
find_library(Backtrace_LIBRARY "backtrace") |
| 112 |
endif() |
| 113 |
|
| 114 |
# Prepend list with library path as it's more common practice |
| 115 |
set(_Backtrace_STD_ARGS Backtrace_LIBRARY ${_Backtrace_STD_ARGS}) |
| 116 |
endif() |
| 117 |
|
| 118 |
set(Backtrace_LIBRARIES ${Backtrace_LIBRARY}) |
| 119 |
set(Backtrace_HEADER "${_Backtrace_HEADER_TRY}" CACHE STRING "Header providing backtrace(3) facility") |
| 120 |
|
| 121 |
find_package_handle_standard_args(Backtrace FOUND_VAR Backtrace_FOUND REQUIRED_VARS ${_Backtrace_STD_ARGS}) |
| 122 |
mark_as_advanced(Backtrace_HEADER Backtrace_INCLUDE_DIR Backtrace_LIBRARY) |