diff --git a/CMakeLists.txt b/CMakeLists.txt index f288646c6..e741adccf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,6 +66,7 @@ endif () find_package(PkgConfig REQUIRED) find_package(Boost REQUIRED) find_package(Threads) +find_package(Backtrace) find_package(GnuTLS) find_package(Protobuf REQUIRED) find_library(PROTOBUF_STATIC_LIBRARY libprotobuf.a libprotobuf) diff --git a/ext/libstrawberry-common/CMakeLists.txt b/ext/libstrawberry-common/CMakeLists.txt index 93ce3fb39..a459bfbb8 100644 --- a/ext/libstrawberry-common/CMakeLists.txt +++ b/ext/libstrawberry-common/CMakeLists.txt @@ -1,8 +1,14 @@ +if (Backtrace_FOUND) + include_directories(${Backtrace_INCLUDE_DIRS}) +endif (Backtrace_FOUND) + include_directories(${PROTOBUF_INCLUDE_DIRS}) include_directories(${CMAKE_CURRENT_BINARY_DIR}) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories(${CMAKE_SOURCE_DIR}/src) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/backtrace_inc.h.in ${CMAKE_CURRENT_BINARY_DIR}/backtrace_inc.h) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11 -U__STRICT_ANSI__ -Wall -Wextra -Wpedantic -Woverloaded-virtual -fpermissive") @@ -38,6 +44,10 @@ add_library(libstrawberry-common STATIC ${MOC} ) +if (Backtrace_FOUND) + target_link_libraries(libstrawberry-common ${Backtrace_LIBRARIES}) +endif (Backtrace_FOUND) + target_link_libraries(libstrawberry-common #${PROTOBUF_LIBRARY} ${TAGLIB_LIBRARIES} diff --git a/ext/libstrawberry-common/backtrace_inc.h.in b/ext/libstrawberry-common/backtrace_inc.h.in new file mode 100644 index 000000000..80e4f4af5 --- /dev/null +++ b/ext/libstrawberry-common/backtrace_inc.h.in @@ -0,0 +1,25 @@ +/* + * Strawberry Music Player + * Copyright 2013, Jonas Kvinge + * + * Strawberry is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Strawberry 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 Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Strawberry. If not, see . + * + */ + +#cmakedefine01 Backtrace_FOUND + +#if Backtrace_FOUND +# define HAVE_BACKTRACE 1 +# include <${Backtrace_HEADER}> +#endif diff --git a/ext/libstrawberry-common/core/logging.cpp b/ext/libstrawberry-common/core/logging.cpp index 9553ed8b0..e5a410943 100644 --- a/ext/libstrawberry-common/core/logging.cpp +++ b/ext/libstrawberry-common/core/logging.cpp @@ -14,6 +14,8 @@ limitations under the License. */ +#include "backtrace_inc.h" + #include #include #include @@ -32,9 +34,6 @@ #include #include #include -#ifdef Q_OS_UNIX - #include -#endif #include "logging.h" @@ -255,7 +254,7 @@ QString DemangleSymbol(const QString &symbol) { } void DumpStackTrace() { -#ifdef Q_OS_UNIX +#ifdef HAVE_BACKTRACE void* callstack[128]; int callstack_size = backtrace(reinterpret_cast(&callstack), sizeof(callstack)); char** symbols = backtrace_symbols(reinterpret_cast(&callstack), callstack_size);