From: Manuel Nickschas Date: Tue, 31 Jul 2018 19:16:32 +0000 (+0200) Subject: cmake: Use official FindBacktrace rather than custom FindExecInfo X-Git-Tag: test-travis-01~177 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=222d0be6ffa0f6c63c3c8c5a303260b9aee10e68 cmake: Use official FindBacktrace rather than custom FindExecInfo Newer versions of CMake ship their own FindBacktrace.cmake module, which replaces the FindExecInfo.cmake module so far shipped by Quassel. The official module is also a bit more thorough in terms of cross-platform support. To avoid duplication, remove Quassel's custom find module and use the official one instead. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 542d362b..93e98fe8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -389,10 +389,10 @@ set_package_properties(ZLIB PROPERTIES TYPE REQUIRED ) if (NOT WIN32) - # Execinfo is needed for generating backtraces - find_package(ExecInfo QUIET) - set_package_properties(ExecInfo PROPERTIES TYPE OPTIONAL - DESCRIPTION "a library for inspecting backtraces" + # Needed for generating backtraces + find_package(Backtrace QUIET) + set_package_properties(Backtrace PROPERTIES TYPE RECOMMENDED + DESCRIPTION "a header (and possibly library) for inspecting backtraces" PURPOSE "Used for generating backtraces in case of a crash" ) endif() diff --git a/cmake/FindExecInfo.cmake b/cmake/FindExecInfo.cmake deleted file mode 100644 index f8599a6a..00000000 --- a/cmake/FindExecInfo.cmake +++ /dev/null @@ -1,27 +0,0 @@ -# Set up execinfo - -# The problem with this library is that it is built-in in the Linux glib, -# while on systems like FreeBSD, it is installed separately and thus needs to be linked to. -# Therefore, we search for the header to see if the it's available in the first place. -# If it is available, we try to locate the library to figure out whether it is built-in or not. - -find_path(EXECINFO_INCLUDES "execinfo.h") - -if(EXECINFO_INCLUDES) - # We found the header file's include dir. - - # Now determine if it's built-in or not, by searching the library file. - find_library(EXECINFO_LIBRARIES "execinfo") - - if(NOT EXECINFO_LIBRARIES) - # Built-in, no further action is needed - set(EXECINFO_LIBRARIES "") - message(STATUS "Found execinfo (built-in)") - else() - # It's an external library. - message(STATUS "Found execinfo: ${EXECINFO_LIBRARIES}") - endif() - - set(EXECINFO_FOUND true) - -endif() diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 737a42c8..caace32b 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -70,26 +70,28 @@ if (APPLE) set(SOURCES ${SOURCES} mac_utils.cpp) endif() -if (WIN32) - set(SOURCES ${SOURCES} logbacktrace_win.cpp windowssignalwatcher.cpp) -else() - if (EXECINFO_FOUND) - add_definitions(-DHAVE_EXECINFO) - include_directories(${EXECINFO_INCLUDES}) - endif() - set(SOURCES ${SOURCES} logbacktrace_unix.cpp posixsignalwatcher.cpp) -endif() - qt5_add_resources(SOURCES ${COMMON_RCS}) add_library(mod_common STATIC ${SOURCES}) qt5_use_modules(mod_common Core Network) +if (WIN32) + target_sources(mod_common PRIVATE logbacktrace_win.cpp windowssignalwatcher.cpp) +else() + if (Backtrace_FOUND) + configure_file(backtrace_config.h.in backtrace_config.h) + target_compile_definitions(mod_common PRIVATE -DHAVE_BACKTRACE) + target_include_directories(mod_common PRIVATE ${Backtrace_INCLUDE_DIRS}) + target_link_libraries(mod_common PRIVATE ${Backtrace_LIBRARIES}) + endif() + target_sources(mod_common PRIVATE logbacktrace_unix.cpp posixsignalwatcher.cpp) +endif() + if (APPLE) target_link_libraries(mod_common "-framework CoreServices" "-framework CoreFoundation") endif() -target_link_libraries(mod_common ${CMAKE_DL_LIBS} ${EXECINFO_LIBRARIES} ZLIB::ZLIB) +target_link_libraries(mod_common ${CMAKE_DL_LIBS} ZLIB::ZLIB) # This is needed so translations are generated before trying to build the qrc. # Should probably find a nicer solution with proper dependencies between the involved files, though... diff --git a/src/common/backtrace_config.h.in b/src/common/backtrace_config.h.in new file mode 100644 index 00000000..ad03ef75 --- /dev/null +++ b/src/common/backtrace_config.h.in @@ -0,0 +1,4 @@ +#cmakedefine01 Backtrace_FOUND +#if Backtrace_FOUND +# include <${Backtrace_HEADER}> +#endif diff --git a/src/common/logbacktrace_unix.cpp b/src/common/logbacktrace_unix.cpp index 3746ba77..9001c476 100644 --- a/src/common/logbacktrace_unix.cpp +++ b/src/common/logbacktrace_unix.cpp @@ -20,14 +20,14 @@ #include "quassel.h" -#if defined(HAVE_EXECINFO) && !defined(Q_OS_MAC) +#if defined(HAVE_BACKTRACE) && !defined(Q_OS_MAC) # define BUILD_CRASHHANDLER -# include # include # include # include # include # include +# include "backtrace_config.h" #endif void Quassel::logBacktrace(const QString &filename) diff --git a/src/common/posixsignalwatcher.cpp b/src/common/posixsignalwatcher.cpp index 0b678978..7de0e773 100644 --- a/src/common/posixsignalwatcher.cpp +++ b/src/common/posixsignalwatcher.cpp @@ -52,7 +52,7 @@ PosixSignalWatcher::PosixSignalWatcher(QObject *parent) registerSignal(SIGTERM); registerSignal(SIGHUP); -#ifdef HAVE_EXECINFO +#ifdef HAVE_BACKTRACE // we only handle crashes ourselves if coredumps are disabled struct rlimit *limit = (rlimit *)malloc(sizeof(struct rlimit)); int rc = getrlimit(RLIMIT_CORE, limit);