Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cmake build system #1

Merged
merged 5 commits into from Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions CMakeLists.txt
@@ -0,0 +1,29 @@
cmake_minimum_required(VERSION 3.1)

project(KDHockeyApp LANGUAGES C CXX)

option(KDHOCKEYAPP_QMLSUPPORT_ENABLED "Build code that supports QML applications" ON)
option(KDHOCKEYAPP_SKIP_EXAMPLES "Do not build example code")

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

find_package(Qt5 COMPONENTS Core Network REQUIRED)

if(CMAKE_SYSTEM_NAME STREQUAL "Android")
find_package(Qt5 COMPONENTS AndroidExtras REQUIRED)
endif()

if(KDHOCKEYAPP_QMLSUPPORT_ENABLED)
find_package(Qt5 COMPONENTS Qml REQUIRED)
endif()

if(NOT KDHOCKEYAPP_SKIP_EXAMPLES)
find_package(Qt5 COMPONENTS QuickWidgets REQUIRED)
add_subdirectory(examples)
endif()

add_subdirectory(src)
3 changes: 3 additions & 0 deletions cmake/android.toolchain.cmake
@@ -0,0 +1,3 @@
set(ANDROID_PLATFORM "android-23")
include("$ENV{ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake")
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
@@ -0,0 +1 @@
add_subdirectory(crashreports)
2 changes: 2 additions & 0 deletions examples/crashreports/CMakeLists.txt
@@ -0,0 +1,2 @@
add_executable(crashreports crashreports.cpp crashreports.qrc)
target_link_libraries(crashreports Qt5::QuickWidgets KDHockeyApp)
1 change: 1 addition & 0 deletions src/3rdparty/CMakeLists.txt
@@ -0,0 +1 @@
add_subdirectory(breakpad)
150 changes: 150 additions & 0 deletions src/3rdparty/breakpad/CMakeLists.txt
@@ -0,0 +1,150 @@
add_library(GoogleBreakpadCommon STATIC) # =============================================================================

target_compile_definitions(GoogleBreakpadCommon PRIVATE -D__STDC_LIMIT_MACROS)
target_compile_definitions(GoogleBreakpadCommon PRIVATE -DUNICODE)

target_include_directories(GoogleBreakpadCommon PUBLIC src/src)

if (CMAKE_SYSTEM_NAME MATCHES "Android|Linux")
target_sources(GoogleBreakpadCommon PRIVATE src/src/common/convert_UTF.c)
target_sources(GoogleBreakpadCommon PRIVATE src/src/common/convert_UTF.h)
target_sources(GoogleBreakpadCommon PRIVATE src/src/common/md5.cc)
target_sources(GoogleBreakpadCommon PRIVATE src/src/common/md5.h)
target_sources(GoogleBreakpadCommon PRIVATE src/src/common/string_conversion.cc)
target_sources(GoogleBreakpadCommon PRIVATE src/src/common/string_conversion.h)
target_sources(GoogleBreakpadCommon PRIVATE src/src/common/linux/elfutils.cc)
target_sources(GoogleBreakpadCommon PRIVATE src/src/common/linux/elfutils.h)
target_sources(GoogleBreakpadCommon PRIVATE src/src/common/linux/file_id.cc)
target_sources(GoogleBreakpadCommon PRIVATE src/src/common/linux/file_id.h)
target_sources(GoogleBreakpadCommon PRIVATE src/src/common/linux/guid_creator.cc)
target_sources(GoogleBreakpadCommon PRIVATE src/src/common/linux/guid_creator.h)
target_sources(GoogleBreakpadCommon PRIVATE src/src/common/linux/linux_libc_support.cc)
target_sources(GoogleBreakpadCommon PRIVATE src/src/common/linux/linux_libc_support.h)
target_sources(GoogleBreakpadCommon PRIVATE src/src/common/linux/memory_mapped_file.cc)
target_sources(GoogleBreakpadCommon PRIVATE src/src/common/linux/memory_mapped_file.h)
target_sources(GoogleBreakpadCommon PRIVATE src/src/common/linux/safe_readlink.cc)
target_sources(GoogleBreakpadCommon PRIVATE src/src/common/linux/safe_readlink.h)
elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
target_sources(GoogleBreakpadCommon PRIVATE src/src/common/windows/guid_string.cc)
target_sources(GoogleBreakpadCommon PRIVATE src/src/common/windows/guid_string.h)
endif()

add_library(GoogleBreakpadClient STATIC) # =============================================================================

target_compile_definitions(GoogleBreakpadClient PRIVATE -D__STDC_LIMIT_MACROS)
target_compile_definitions(GoogleBreakpadClient PRIVATE -DUNICODE)

target_link_libraries(GoogleBreakpadClient PUBLIC GoogleBreakpadCommon)

if (CMAKE_SYSTEM_NAME MATCHES "Android|Linux")
target_sources(GoogleBreakpadCommon PRIVATE src/src/common/linux/elfutils.cc)
target_sources(GoogleBreakpadCommon PRIVATE src/src/common/linux/elfutils.h)
target_sources(GoogleBreakpadCommon PRIVATE src/src/common/linux/file_id.cc)
target_sources(GoogleBreakpadCommon PRIVATE src/src/common/linux/file_id.h)
target_sources(GoogleBreakpadCommon PRIVATE src/src/common/linux/guid_creator.cc)
target_sources(GoogleBreakpadCommon PRIVATE src/src/common/linux/guid_creator.h)
target_sources(GoogleBreakpadCommon PRIVATE src/src/common/linux/linux_libc_support.cc)
target_sources(GoogleBreakpadCommon PRIVATE src/src/common/linux/linux_libc_support.h)
target_sources(GoogleBreakpadCommon PRIVATE src/src/common/linux/memory_mapped_file.cc)
target_sources(GoogleBreakpadCommon PRIVATE src/src/common/linux/memory_mapped_file.h)
target_sources(GoogleBreakpadCommon PRIVATE src/src/common/linux/safe_readlink.cc)
target_sources(GoogleBreakpadCommon PRIVATE src/src/common/linux/safe_readlink.h)

target_sources(GoogleBreakpadClient PRIVATE src/src/client/minidump_file_writer.cc)
target_sources(GoogleBreakpadClient PRIVATE src/src/client/minidump_file_writer.h)
target_sources(GoogleBreakpadClient PRIVATE src/src/client/linux/crash_generation/crash_generation_client.cc)
target_sources(GoogleBreakpadClient PRIVATE src/src/client/linux/crash_generation/crash_generation_client.h)
target_sources(GoogleBreakpadClient PRIVATE src/src/client/linux/dump_writer_common/thread_info.cc)
target_sources(GoogleBreakpadClient PRIVATE src/src/client/linux/dump_writer_common/thread_info.h)
target_sources(GoogleBreakpadClient PRIVATE src/src/client/linux/dump_writer_common/ucontext_reader.cc)
target_sources(GoogleBreakpadClient PRIVATE src/src/client/linux/dump_writer_common/ucontext_reader.h)
target_sources(GoogleBreakpadClient PRIVATE src/src/client/linux/handler/exception_handler.cc)
target_sources(GoogleBreakpadClient PRIVATE src/src/client/linux/handler/exception_handler.h)
target_sources(GoogleBreakpadClient PRIVATE src/src/client/linux/handler/minidump_descriptor.cc)
target_sources(GoogleBreakpadClient PRIVATE src/src/client/linux/handler/minidump_descriptor.h)
target_sources(GoogleBreakpadClient PRIVATE src/src/client/linux/log/log.cc)
target_sources(GoogleBreakpadClient PRIVATE src/src/client/linux/log/log.h)
target_sources(GoogleBreakpadClient PRIVATE src/src/client/linux/microdump_writer/microdump_writer.cc)
target_sources(GoogleBreakpadClient PRIVATE src/src/client/linux/microdump_writer/microdump_writer.h)
target_sources(GoogleBreakpadClient PRIVATE src/src/client/linux/minidump_writer/linux_dumper.cc)
target_sources(GoogleBreakpadClient PRIVATE src/src/client/linux/minidump_writer/linux_dumper.h)
target_sources(GoogleBreakpadClient PRIVATE src/src/client/linux/minidump_writer/linux_ptrace_dumper.cc)
target_sources(GoogleBreakpadClient PRIVATE src/src/client/linux/minidump_writer/linux_ptrace_dumper.h)
target_sources(GoogleBreakpadClient PRIVATE src/src/client/linux/minidump_writer/minidump_writer.cc)
target_sources(GoogleBreakpadClient PRIVATE src/src/client/linux/minidump_writer/minidump_writer.h)

if (CMAKE_SYSTEM_NAME MATCHES "Android")
target_include_directories(GoogleBreakpadCommon PUBLIC src/src/common/android/include)
target_sources(GoogleBreakpadCommon PRIVATE src/src/common/android/breakpad_getcontext.S)
target_link_libraries(GoogleBreakpadCommon PUBLIC -llog)
endif()
elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
if (MINGW)
target_compile_options(GoogleBreakpadClient PRIVATE -Wno-conversion-null)
endif()

target_sources(GoogleBreakpadClient PRIVATE src/src/client/windows/crash_generation/crash_generation_client.cc)
target_sources(GoogleBreakpadClient PRIVATE src/src/client/windows/crash_generation/crash_generation_client.h)
target_sources(GoogleBreakpadClient PRIVATE src/src/client/windows/handler/exception_handler.cc)
target_sources(GoogleBreakpadClient PRIVATE src/src/client/windows/handler/exception_handler.h)
endif()


#[[
OTHER_FILES += \
breakpad.pri \
breakpad-config.pri

linux {
QMAKE_CXXFLAGS_WARN_ON += \
-Wno-missing-field-initializers \
-Wno-unused-parameters \
-Wno-tautological-compare \
-Wno-tautological-constant-out-of-range-compare \
-Wno-unused-value
} else: ios: CONFIG(device, device|simulator) {
SOURCES += \
src/src/client/ios/exception_handler_no_mach.cc \
src/src/client/mac/handler/breakpad_nlist_64.cc \
src/src/client/mac/handler/dynamic_images.cc \
src/src/client/mac/handler/minidump_generator.cc \
src/src/common/mac/file_id.cc \
src/src/common/mac/macho_id.cc \
src/src/common/mac/macho_utilities.cc \
src/src/common/mac/macho_walker.cc \
src/src/common/mac/string_utilities.cc
} else {
warning("Skipping breakpad, which is not supported for this platform")
SOURCES = breakpad_dummy.cpp # building a dummy to make XCode happy
}

# Custom targets to build breakpad's dump_syms tool ------------------------------------------------

equals(QMAKE_HOST.os, Linux) {
dumpsyms_configure.depends = $$_PRO_FILE_
dumpsyms_configure.target = $$BREAKPAD_HOSTDIR/Makefile
dumpsyms_configure.commands = \
mkdir -p $$BREAKPAD_HOSTDIR && \
cd $$BREAKPAD_HOSTDIR && \
$$PWD/src/configure

dumpsyms_build.depends = dumpsyms_configure
dumpsyms_build.target = $$BREAKPAD_HOSTDIR/src/tools/linux/dump_syms/dump_syms
dumpsyms_build.commands = +\$(MAKE) -C $$BREAKPAD_HOSTDIR

!equals(BREAKPAD_BUILDDIR, $$BREAKPAD_HOSTDIR) {
QMAKE_EXTRA_TARGETS += dumpsyms_build dumpsyms_configure
PRE_TARGETDEPS += $$dumpsyms_build.target
}
}

# Install targets ----------------------------------------------------------------------------------

target.path = $$LIBDIR
target.extra = \
$$QMAKE_COPY $$shell_path($$BREAKPAD_LIBRARY) \
$$shell_path($${QMAKE_PREFIX_STATICLIB}KDHockeyAppBreakpad.$${QMAKE_EXTENSION_STATICLIB})
target.files += $${QMAKE_PREFIX_STATICLIB}KDHockeyAppBreakpad.$${QMAKE_EXTENSION_STATICLIB}

INSTALLS += target
]]
Expand Up @@ -224,6 +224,8 @@ class ExceptionHandler {
UpdateNextID(); // Necessary to put dump_path_ in next_minidump_path_.
}

wstring next_minidump_path() const { return next_minidump_path_; }

// Requests that a previously reported crash be uploaded.
bool RequestUpload(DWORD crash_id);

Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
@@ -0,0 +1,2 @@
add_subdirectory(3rdparty)
add_subdirectory(KDHockeyApp)
40 changes: 40 additions & 0 deletions src/KDHockeyApp/CMakeLists.txt
@@ -0,0 +1,40 @@
configure_file(KDHockeyAppConfig.h.cmake include/KDHockeyAppConfig.h)
configure_file(KDHockeyAppManager.h include/ COPYONLY)

add_library(KDHockeyApp STATIC)

target_compile_definitions(KDHockeyApp PRIVATE -D_CRT_NONSTDC_NO_DEPRECATE)
target_compile_definitions(KDHockeyApp PRIVATE -D_CRT_SECURE_NO_WARNINGS)
target_include_directories(KDHockeyApp PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/include)
target_link_libraries(KDHockeyApp PUBLIC GoogleBreakpadClient Qt5::Network)

target_sources(KDHockeyApp PRIVATE KDHockeyAppLiterals.cpp KDHockeyAppLiterals_p.h)
target_sources(KDHockeyApp PRIVATE KDHockeyAppManager.cpp KDHockeyAppManager.h KDHockeyAppManager_p.h)
target_sources(KDHockeyApp PRIVATE KDHockeyAppSoftAssert.cpp KDHockeyAppSoftAssert_p.h)

if (KDHOCKEYAPP_QMLSUPPORT_ENABLED)
target_link_libraries(KDHockeyApp PUBLIC Qt5::QmlPrivate)
endif()

if (CMAKE_SYSTEM_NAME STREQUAL "Android") # ============================================================================
target_link_libraries(KDHockeyApp PRIVATE Qt5::AndroidExtras)
target_sources(KDHockeyApp PRIVATE KDHockeyAppManager_android.cpp)
elseif (CMAKE_SYSTEM_NAME STREQUAL "iOS") # ============================================================================
target_sources(KDHockeyApp PRIVATE KDHockeyAppManager_ios.mm)
elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux") # ==========================================================================
target_sources(KDHockeyApp PRIVATE KDHockeyAppManager_linux.cpp)
elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows") # ========================================================================
target_sources(KDHockeyApp PRIVATE KDHockeyAppManager_windows.cpp)
else() # ===============================================================================================================
message(WARNING "KDHockeyApp doesn't support crash reporting for ${CMAKE_SYSTEM_NAME}.")
target_sources(KDHockeyApp PRIVATE KDHockeyAppManager_generic.cpp)
endif() # ==============================================================================================================

#[[
target.path = $$LIBDIR
INSTALLS += target

headers.path = $$INCLUDEDIR/KDHockeyApp
headers.files = $$INSTALLHEADERS
INSTALLS += headers
]]
6 changes: 6 additions & 0 deletions src/KDHockeyApp/KDHockeyAppConfig.h.cmake
@@ -0,0 +1,6 @@
#ifndef KDHOCKEYAPPCONFIG_H
#define KDHOCKEYAPPCONFIG_H

#cmakedefine KDHOCKEYAPP_QMLSUPPORT_ENABLED

#endif // KDHOCKEYAPPCONFIG_H
106 changes: 106 additions & 0 deletions src/KDHockeyApp/KDHockeyAppManager_windows.cpp
@@ -0,0 +1,106 @@
//
// Copyright (C) 2018 F.X.MEILLER GmbH & Co. KG
// All rights reserved.
//
// This file is part of the KD HockeyApp library.
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of either:
//
// The GNU Lesser General Public License version 2.1 and version 3
// as published by the Free Software Foundation and appearing in the
// file LICENSE.LGPL.txt included.
//
// Or:
//
// The Mozilla Public License Version 2.0 as published by the Mozilla
// Foundation and appearing in the file LICENSE.MPL2.txt included.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// Contact info@kdab.com if any conditions of this licensing is not clear to you.
//

#include "KDHockeyAppManager_p.h"

#include "KDHockeyAppLiterals_p.h"
#include "KDHockeyAppSoftAssert_p.h"

#include <client/windows/handler/exception_handler.h>

#include <QStandardPaths>

namespace KDHockeyApp {

using google_breakpad::CustomClientInfo;
using google_breakpad::ExceptionHandler;

namespace {

class PlatformData
{
public:
explicit PlatformData(const QString &path, ExceptionHandler::MinidumpCallback callback, void *context)
: eh{path.toStdWString(), NoFilter, callback, context, ExceptionHandler::HANDLER_ALL,
MiniDumpNormal, NoPipeName, NoClientInfo}
{}

constexpr static ExceptionHandler::FilterCallback NoFilter = nullptr;
constexpr static const wchar_t *NoPipeName = nullptr;
constexpr static const CustomClientInfo *NoClientInfo = nullptr;

const ExceptionHandler eh;
};

} // namespace

// use multi-inheritance to ensure that the exception handler is initialized before all of the Private fields
class HockeyAppManager::PlatformPrivate : public PlatformData, public Private
{
public:
explicit PlatformPrivate(const QString &appId, HockeyAppManager *q)
: PlatformData{dataDirPath(), &PlatformPrivate::onException, this}
, Private{appId, q}
{}

private:
static bool onException(const wchar_t *, const wchar_t *, void *context,
EXCEPTION_POINTERS *, MDRawAssertionInfo *, bool succeeded)
{
// NOTICE: This context is compromised. Complex operations, allocations must be avoided!
return static_cast<const PlatformPrivate *>(context)->writeCrashReport(succeeded);
}
};

HockeyAppManager::Private *HockeyAppManager::Private::create(const QString &appId, HockeyAppManager *q)
{
return new PlatformPrivate{appId, q};
}

QDir HockeyAppManager::Private::cacheLocation()
{
return QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
}

void HockeyAppManager::Private::fillAppInfo(AppInfo *)
{
}

std::string HockeyAppManager::Private::nextMiniDumpFileName() const
{
const auto fileName = static_cast<const PlatformPrivate *>(this)->eh.next_minidump_path();
return QString::fromStdWString(fileName).toStdString();
}

QString HockeyAppManager::Private::requestParameterDeviceId()
{
return "udid"_l1;
}

bool HockeyAppManager::Private::installedFromMarket()
{
return false;
}

} // namespace KDHockeyApp