cmake: Use official FindBacktrace rather than custom FindExecInfo
authorManuel Nickschas <sputnick@quassel-irc.org>
Tue, 31 Jul 2018 19:16:32 +0000 (21:16 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sun, 18 Nov 2018 10:06:43 +0000 (11:06 +0100)
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.

CMakeLists.txt
cmake/FindExecInfo.cmake [deleted file]
src/common/CMakeLists.txt
src/common/backtrace_config.h.in [new file with mode: 0644]
src/common/logbacktrace_unix.cpp
src/common/posixsignalwatcher.cpp

index 542d362..93e98fe 100644 (file)
@@ -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 (file)
index f8599a6..0000000
+++ /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()
index 737a42c..caace32 100644 (file)
@@ -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 (file)
index 0000000..ad03ef7
--- /dev/null
@@ -0,0 +1,4 @@
+#cmakedefine01 Backtrace_FOUND
+#if Backtrace_FOUND
+# include <${Backtrace_HEADER}>
+#endif
index 3746ba7..9001c47 100644 (file)
 
 #include "quassel.h"
 
-#if defined(HAVE_EXECINFO) && !defined(Q_OS_MAC)
+#if defined(HAVE_BACKTRACE) && !defined(Q_OS_MAC)
 #  define BUILD_CRASHHANDLER
-#  include <execinfo.h>
 #  include <dlfcn.h>
 #  include <cxxabi.h>
 #  include <QFile>
 #  include <QTextStream>
 #  include <QDebug>
+#  include "backtrace_config.h"
 #endif
 
 void Quassel::logBacktrace(const QString &filename)
index 0b67897..7de0e77 100644 (file)
@@ -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);