Navigation Menu

Skip to content

Commit

Permalink
Allow crash handler to be disabled through cmake
Browse files Browse the repository at this point in the history
It can cause issues with some environments, e.g. when building
through asan
  • Loading branch information
nyalldawson committed Dec 21, 2021
1 parent a357720 commit ffb12c7
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 1 deletion.
18 changes: 18 additions & 0 deletions CMakeLists.txt
Expand Up @@ -149,6 +149,24 @@ if(WITH_CORE)

set (WITH_DESKTOP TRUE CACHE BOOL "Determines whether QGIS desktop should be built")

if(WITH_DESKTOP)
if((WIN32 AND NOT MINGW) OR (UNIX AND NOT APPLE AND NOT ANDROID AND NOT IOS))
set (CRASH_HANDLER_AVAILABLE TRUE)
else()
set (CRASH_HANDLER_AVAILABLE FALSE)
endif()

set (WITH_CRASH_HANDLER ${CRASH_HANDLER_AVAILABLE} CACHE BOOL "Determines whether the QGIS crash handler application should be built")
if(WITH_CRASH_HANDLER AND NOT CRASH_HANDLER_AVAILABLE)
message(FATAL_ERROR "Crash handler cannot be built on this environment. Set WITH_CRASH_HANDLER to false.")
endif()
if(WITH_CRASH_HANDLER)
set (HAVE_CRASH_HANDLER TRUE) # used in qgsconfig.h
else()
set (HAVE_CRASH_HANDLER FALSE) # used in qgsconfig.h
endif()
endif()

set (WITH_3D FALSE CACHE BOOL "Determines whether QGIS 3D library should be built")

set (WITH_QUICK FALSE CACHE BOOL "Determines whether QGIS Quick library should be built")
Expand Down
2 changes: 2 additions & 0 deletions cmake_templates/qgsconfig.h.in
Expand Up @@ -112,5 +112,7 @@
#cmakedefine HAS_KDE_QT5_SMALL_CAPS_FIX
#cmakedefine HAS_KDE_QT5_FONT_STRETCH_FIX

#cmakedefine HAVE_CRASH_HANDLER

#endif

3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Expand Up @@ -19,9 +19,10 @@ if (NOT IOS)
add_subdirectory(crssync)
endif()

if ((WIN32 AND NOT MINGW) OR (UNIX AND NOT APPLE AND NOT ANDROID AND NOT IOS))
if (WITH_CRASH_HANDLER)
add_subdirectory(crashhandler)
endif()

add_subdirectory(test)

if (WITH_DESKTOP)
Expand Down
5 changes: 5 additions & 0 deletions src/app/main.cpp
Expand Up @@ -38,6 +38,7 @@
#include <cstdio>
#include <cstdlib>
#include <cstdarg>
#include "qgsconfig.h"

#if !defined(Q_OS_WIN)
#include "sigwatch.h"
Expand Down Expand Up @@ -75,6 +76,7 @@ typedef SInt32 SRefCon;
#include <sys/time.h>
#endif

#ifdef HAVE_CRASH_HANDLER
#if defined(__GLIBC__) || defined(__FreeBSD__)
#define QGIS_CRASH
#include <unistd.h>
Expand All @@ -83,6 +85,7 @@ typedef SInt32 SRefCon;
#include <sys/wait.h>
#include <cerrno>
#endif
#endif

#include "qgscustomization.h"
#include "qgssettings.h"
Expand All @@ -104,7 +107,9 @@ typedef SInt32 SRefCon;
#include "qgsmapthemes.h"
#include "qgsvectorlayer.h"
#include "qgis_app.h"
#ifdef HAVE_CRASH_HANDLER
#include "qgscrashhandler.h"
#endif
#include "qgsziputils.h"
#include "qgsversionmigration.h"
#include "qgsfirstrundialog.h"
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -17567,12 +17567,14 @@ void QgisApp::saveProjectToProjectStorage( const QString &uri )
}
}

#ifdef HAVE_CRASH_HANDLER
void QgisApp::triggerCrashHandler()
{
#ifdef Q_OS_WIN
RaiseException( 0x12345678, 0, 0, nullptr );
#endif
}
#endif

void QgisApp::addTabifiedDockWidget( Qt::DockWidgetArea area, QDockWidget *dockWidget, const QStringList &tabifyWith, bool raiseTab )
{
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -1252,11 +1252,14 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow

void setMapTipsDelay( int timerInterval );

#ifdef HAVE_CRASH_HANDLER

/**
* Abort application triggering the crash handler
* \since QGIS 3.4
*/
void triggerCrashHandler();
#endif

//! Create a new file from a template project
bool fileNewFromTemplate( const QString &fileName );
Expand Down

0 comments on commit ffb12c7

Please sign in to comment.