From afbad440b84befb5f34543959503b4ef7e792479 Mon Sep 17 00:00:00 2001 From: Vladimir Stackov Date: Wed, 31 Dec 2014 06:49:06 +0300 Subject: [PATCH] Added libunwind to build process But it's not used anywhere yet --- CMakeLists.txt | 9 +++ cmake/FindLibUnwind.cmake | 77 +++++++++++++++++++++ debug.cc | 7 ++ debug.hh | 10 +++ LICENSE => licenses/LICENSE | 4 ++ licenses/LICENSE-CMAKE | 57 +++++++++++++++ LICENSE-GPLV2 => licenses/LICENSE-GPLV2 | 0 LICENSE-GPLV3 => licenses/LICENSE-GPLV3 | 0 LICENSE-OPENSSL => licenses/LICENSE-OPENSSL | 0 9 files changed, 164 insertions(+) create mode 100644 cmake/FindLibUnwind.cmake rename LICENSE => licenses/LICENSE (93%) create mode 100644 licenses/LICENSE-CMAKE rename LICENSE-GPLV2 => licenses/LICENSE-GPLV2 (100%) rename LICENSE-GPLV3 => licenses/LICENSE-GPLV3 (100%) rename LICENSE-OPENSSL => licenses/LICENSE-OPENSSL (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index efd8178..2922a2a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,14 @@ else ( LIBLZO_FOUND ) set( LIBLZO_LIBRARIES ) endif( LIBLZO_FOUND ) +find_package( LibUnwind COMPONENTS LIBUNWIND_HAS_UNW_GETCONTEXT LIBUNWIND_HAS_INIT_LOCAL ) +if ( LIBUNWIND_FOUND ) + ADD_DEFINITIONS( -DHAVE_LIBUNWIND ) + include_directories( ${LIBUNWIND_INCLUDE_DIRS} ) +else ( LIBUNWIND_FOUND ) + set( LIBUNWIND_LIBRARIES ) +endif( LIBUNWIND_FOUND ) + file( GLOB sourceFiles "*.cc" ) add_executable( zbackup ${sourceFiles} ${protoSrcs} ${protoHdrs} ) @@ -51,6 +59,7 @@ target_link_libraries( zbackup ${ZLIB_LIBRARIES} ${LIBLZMA_LIBRARIES} ${LIBLZO_LIBRARIES} + ${LIBUNWIND_LIBRARIES} ) install( TARGETS zbackup DESTINATION bin ) diff --git a/cmake/FindLibUnwind.cmake b/cmake/FindLibUnwind.cmake new file mode 100644 index 0000000..9830965 --- /dev/null +++ b/cmake/FindLibUnwind.cmake @@ -0,0 +1,77 @@ +#.rst: +# FindLibUnwind +# ----------- +# +# Find LibUnwind +# +# Find LibUnwind headers and library +# +# :: +# +# LIBUNWIND_FOUND - True if libunwind is found. +# LIBUNWIND_INCLUDE_DIRS - Directory where libunwind headers are located. +# LIBUNWIND_LIBRARIES - Unwind libraries to link against. +# LIBUNWIND_HAS_UNW_GETCONTEXT - True if unw_getcontext() is found (required). +# LIBUNWIND_HAS_UNW_INIT_LOCAL - True if unw_init_local() is found (required). +# LIBUNWIND_VERSION_STRING - version number as a string (ex: "5.0.3") + +#============================================================================= +# Copyright 2014 ZBackup contributors +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + + +find_path(LIBUNWIND_INCLUDE_DIR libunwind.h ) +if(NOT EXISTS "${LIBUNWIND_INCLUDE_DIR}/unwind.h") + MESSAGE(FATAL_ERROR "found libunwind.h but corresponding unwind.h is absent!") + SET(LIBUNWIND_INCLUDE_DIR "") +endif() + +find_library(LIBUNWIND_LIBRARY unwind) + +if(LIBUNWIND_INCLUDE_DIR AND EXISTS "${LIBUNWIND_INCLUDE_DIR}/libunwind-common.h") + file(STRINGS "${LIBUNWIND_INCLUDE_DIR}/libunwind-common.h" LIBUNWIND_HEADER_CONTENTS REGEX "#define UNW_VERSION_[A-Z]+\t[0-9]*") + + string(REGEX REPLACE ".*#define UNW_VERSION_MAJOR\t([0-9]*).*" "\\1" LIBUNWIND_VERSION_MAJOR "${LIBUNWIND_HEADER_CONTENTS}") + string(REGEX REPLACE ".*#define UNW_VERSION_MINOR\t([0-9]*).*" "\\1" LIBUNWIND_VERSION_MINOR "${LIBUNWIND_HEADER_CONTENTS}") + string(REGEX REPLACE ".*#define UNW_VERSION_EXTRA\t([0-9]*).*" "\\1" LIBUNWIND_VERSION_EXTRA "${LIBUNWIND_HEADER_CONTENTS}") + + if(LIBUNWIND_VERSION_EXTRA) + set(LIBUNWIND_VERSION_STRING "${LIBUNWIND_VERSION_MAJOR}.${LIBUNWIND_VERSION_MINOR}.${LIBUNWIND_VERSION_EXTRA}") + else(not LIBUNWIND_VERSION_EXTRA) + set(LIBUNWIND_VERSION_STRING "${LIBUNWIND_VERSION_MAJOR}.${LIBUNWIND_VERSION_MINOR}") + endif() + unset(LIBUNWIND_HEADER_CONTENTS) +endif() + +if (LIBUNWIND_LIBRARY) + include(CheckSymbolExists) + set(CMAKE_REQUIRED_QUIET_SAVE ${CMAKE_REQUIRED_QUIET}) + set(CMAKE_REQUIRED_QUIET ${LibUnwind_FIND_QUIETLY}) + CHECK_SYMBOL_EXISTS(unw_getcontext "${LIBUNWIND_INCLUDE_DIR}/libunwind.h" LIBUNWIND_HAS_UNW_GETCONTEXT) + CHECK_SYMBOL_EXISTS(unw_init_local "${LIBUNWIND_INCLUDE_DIR}/libunwind.h" LIBUNWIND_HAS_UNW_INIT_LOCAL) + set(CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET_SAVE}) +endif () + +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibUnwind REQUIRED_VARS LIBUNWIND_INCLUDE_DIR + LIBUNWIND_LIBRARY + LIBUNWIND_HAS_UNW_GETCONTEXT + LIBUNWIND_HAS_UNW_INIT_LOCAL + VERSION_VAR LIBUNWIND_VERSION_STRING + ) + +if (LIBUNWIND_FOUND) + set(LIBUNWIND_LIBRARIES ${LIBUNWIND_LIBRARY}) + set(LIBUNWIND_INCLUDE_DIRS ${LIBUNWIND_INCLUDE_DIR}) +endif () + +mark_as_advanced( LIBUNWIND_INCLUDE_DIR LIBUNWIND_LIBRARY ) diff --git a/debug.cc b/debug.cc index 409ca1b..5beff5f 100644 --- a/debug.cc +++ b/debug.cc @@ -2,3 +2,10 @@ // Part of ZBackup. Licensed under GNU GPLv2 or later + OpenSSL, see LICENSE bool verboseMode = true; + +#ifndef NDEBUG +#ifdef HAVE_LIBUNWIND +#include "debug.hh" + +#endif +#endif diff --git a/debug.hh b/debug.hh index bd80a9f..e4ae22e 100644 --- a/debug.hh +++ b/debug.hh @@ -12,9 +12,19 @@ #define dPrintf( ... ) (fprintf( stderr, __VA_ARGS__ )) +#ifdef HAVE_LIBUNWIND +#define UNW_LOCAL_ONLY +#include + +#define dPrintBacktrace( ... ) () +#else +#define dPrintBacktrace( ... ) () +#endif + #else #define dPrintf( ... ) +#define dPrintBacktrace( ... ) () #endif diff --git a/LICENSE b/licenses/LICENSE similarity index 93% rename from LICENSE rename to licenses/LICENSE index 812eca6..5471a8e 100644 --- a/LICENSE +++ b/licenses/LICENSE @@ -12,6 +12,10 @@ LICENSE-GPLV3. EXCEPTION: This distribution of ZBackup may be linked against OpenSSL according to the terms of the section below entitled "OpenSSL Exception." +ADDITION: This distribution of ZBackup uses sources from CMake project +which is distributed under the OSI-approved BSD 3-clause License. +See LICENSE-CMAKE for details. + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General diff --git a/licenses/LICENSE-CMAKE b/licenses/LICENSE-CMAKE new file mode 100644 index 0000000..214d7de --- /dev/null +++ b/licenses/LICENSE-CMAKE @@ -0,0 +1,57 @@ +CMake - Cross Platform Makefile Generator +Copyright 2000-2014 Kitware, Inc. +Copyright 2000-2011 Insight Software Consortium +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +* Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +* Neither the names of Kitware, Inc., the Insight Software Consortium, + nor the names of their contributors may be used to endorse or promote + products derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +------------------------------------------------------------------------------ + +The above copyright and license notice applies to distributions of +CMake in source and binary form. Some source files contain additional +notices of original copyright by their contributors; see each source +for details. Third-party software packages supplied with CMake under +compatible licenses provide their own copyright notices documented in +corresponding subdirectories. + +------------------------------------------------------------------------------ + +CMake was initially developed by Kitware with the following sponsorship: + + * National Library of Medicine at the National Institutes of Health + as part of the Insight Segmentation and Registration Toolkit (ITK). + + * US National Labs (Los Alamos, Livermore, Sandia) ASC Parallel + Visualization Initiative. + + * National Alliance for Medical Image Computing (NAMIC) is funded by the + National Institutes of Health through the NIH Roadmap for Medical Research, + Grant U54 EB005149. + + * Kitware, Inc. diff --git a/LICENSE-GPLV2 b/licenses/LICENSE-GPLV2 similarity index 100% rename from LICENSE-GPLV2 rename to licenses/LICENSE-GPLV2 diff --git a/LICENSE-GPLV3 b/licenses/LICENSE-GPLV3 similarity index 100% rename from LICENSE-GPLV3 rename to licenses/LICENSE-GPLV3 diff --git a/LICENSE-OPENSSL b/licenses/LICENSE-OPENSSL similarity index 100% rename from LICENSE-OPENSSL rename to licenses/LICENSE-OPENSSL