Skip to content

Commit

Permalink
refactor: macos specific checks
Browse files Browse the repository at this point in the history
  • Loading branch information
mehulmathur001 committed Apr 4, 2024
1 parent 970ca42 commit b92a17f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-mudlet.yml
Expand Up @@ -97,8 +97,8 @@ jobs:
shell: bash

# workaround a poor interaction between github actions/cmake/vcpkg, see https://github.com/lukka/run-vcpkg/issues/88#issuecomment-885758902
- name: Use CMake 3.26.3
uses: lukka/get-cmake@v3.26.3
- name: Use CMake 3.20.1
uses: lukka/get-cmake@v3.20.1

- name: (macOS) Install non-vcpkg dependencies (1/2)
if: runner.os == 'macOS'
Expand Down
13 changes: 9 additions & 4 deletions CMakeLists.txt
Expand Up @@ -202,9 +202,11 @@ git_submodule_init(
CHECK_FILE "3rdparty/edbee-lib/CMakeLists.txt" SUBMODULE_PATH
"3rdparty/edbee-lib" READABLE_NAME "edbee-lib editor widget")

git_submodule_init(
CHECK_FILE "3rdparty/sentry-native/CMakeLists.txt" SUBMODULE_PATH
"3rdparty/sentry-native" READABLE_NAME "sentry-native")
if(APPLE)
git_submodule_init(
CHECK_FILE "3rdparty/sentry-native/CMakeLists.txt" SUBMODULE_PATH
"3rdparty/sentry-native" READABLE_NAME "sentry-native")
endif()

if(USE_OWN_QTKEYCHAIN)
git_submodule_init(
Expand Down Expand Up @@ -263,9 +265,12 @@ set(SENTRY_BACKEND "crashpad")
set(SENTRY_INCLUDE_DIR "3rdparty/sentry-native/include")
set(SENTRY_LIBRARIES "3rdparty/sentry-native")

if(APPLE)
add_subdirectory(3rdparty/sentry-native)
endif()

add_subdirectory(3rdparty/edbee-lib/edbee-lib)
add_subdirectory(3rdparty/communi)
add_subdirectory(3rdparty/sentry-native)
add_subdirectory(translations/translated)
add_subdirectory(src)
add_subdirectory(test)
Expand Down
10 changes: 8 additions & 2 deletions src/CMakeLists.txt
Expand Up @@ -441,7 +441,10 @@ endif()

message(STATUS "Using ${CMAKE_CXX_COMPILER_ID} compiler")

find_package(sentry REQUIRED)
if(APPLE)
find_package(sentry REQUIRED)
endif()

find_package(ZIP REQUIRED)
find_package(Lua51 REQUIRED)
find_package(ZLIB REQUIRED)
Expand Down Expand Up @@ -536,7 +539,6 @@ target_compile_definitions(communi PUBLIC IRC_STATIC)
target_link_libraries(
mudlet
communi
sentry::sentry
edbee-lib
Boost::boost
HUNSPELL::HUNSPELL
Expand All @@ -554,6 +556,10 @@ if(USE_UPDATER)
target_compile_definitions(mudlet PRIVATE INCLUDE_UPDATER)
endif(USE_UPDATER)

if(APPLE)
target_link_libraries(mudlet sentry::sentry)
endif()

if(USE_3DMAPPER)
target_link_libraries(mudlet OpenGL::GLU)
target_compile_definitions(mudlet PRIVATE INCLUDE_3DMAPPER)
Expand Down
15 changes: 13 additions & 2 deletions src/main.cpp
Expand Up @@ -46,9 +46,11 @@
#include "Announcer.h"
#include "FileOpenHandler.h"

#if defined(Q_OS_MACOS)
extern "C" {
#include "sentry.h"
}
#endif

using namespace std::chrono_literals;

Expand Down Expand Up @@ -156,28 +158,37 @@ QTranslator* loadTranslationsForCommandLine()
}

void initSentry() {
#ifdef Q_OS_MACOS
sentry_options_t *options = sentry_options_new();
sentry_options_set_dsn(options, "");
sentry_options_set_handler_path(options, "./crashpad_handler");
sentry_options_set_debug(options, 1);
sentry_init(options);

sentry_value_t mudlet_info = sentry_value_new_object();
sentry_value_set_by_key(mudlet_info, "Version", sentry_value_new_string(APP_VERSION));
sentry_set_context("Mudlet", mudlet_info);

sentry_set_tag("mudlet-version", APP_VERSION);

/*
sentry_capture_event(sentry_value_new_message_event(
SENTRY_LEVEL_INFO,
"Testing",
"Working as expected!"
));
*/
#endif
}

int main(int argc, char* argv[])
{
// print stdout to console if Mudlet is started in a console in Windows
// credit to https://stackoverflow.com/a/41701133 for the workaround

initSentry();

#ifdef Q_OS_MACOS
initSentry();
#endif
#ifdef Q_OS_WIN32
if (AttachConsole(ATTACH_PARENT_PROCESS)) {
freopen("CONOUT$", "w", stdout);
Expand Down
20 changes: 12 additions & 8 deletions src/mudlet.pro
Expand Up @@ -455,7 +455,10 @@ exists(/usr/bin/ccache)|exists(/usr/local/bin/ccache)|exists(C:/Program Files/cc
macx:LIBS += -lz

INCLUDEPATH += ../3rdparty/discord/rpc/include
INCLUDEPATH += ../3rdparty/sentry-native/include

macx {
INCLUDEPATH += ../3rdparty/sentry-native/include
}

# Define a preprocessor symbol with the default fallback location from which
# to load installed mudlet lua files. Set LUA_DEFAULT_DIR to a
Expand Down Expand Up @@ -489,8 +492,6 @@ DEFINES += LUA_DEFAULT_PATH=\\\"$${LUA_DEFAULT_DIR}\\\"
# lua packages used via the luarocks sub-system, most specifically "utf8". This
# method has NOT been checked thoroughly though, so YMMV.
win32 {
system("cd $${PWD}\.. & git submodule update --init --recursive 3rdparty/sentry-native")

# Use a check explicitly based on where the project file is in the sources
!exists("$${PWD}/../3rdparty/edbee-lib/edbee-lib/edbee-lib.pri") {
message("git submodule for required edbee-lib editor widget missing from source code, executing 'git submodule update --init' to get it...")
Expand All @@ -510,8 +511,9 @@ win32 {
}
}
} else {
system("cd $${PWD}/.. ; git submodule update --init --recursive 3rdparty/sentry-native")

macx {
system("cd $${PWD}/.. ; git submodule update --init --recursive 3rdparty/sentry-native")
}
!exists("$${PWD}/../3rdparty/edbee-lib/edbee-lib/edbee-lib.pri") {
message("git submodule for required edbee-lib editor widget missing from source code, executing 'git submodule update --init' to get it...")
system("cd $${PWD}/.. ; git submodule update --init 3rdparty/edbee-lib")
Expand Down Expand Up @@ -717,7 +719,6 @@ SOURCES += \
HEADERS += \
../3rdparty/discord/rpc/include/discord_register.h \
../3rdparty/discord/rpc/include/discord_rpc.h \
../3rdparty/sentry-native/include/sentry.h \
ActionUnit.h \
Announcer.h \
AliasUnit.h \
Expand Down Expand Up @@ -847,8 +848,11 @@ HEADERS += \
XMLimport.h \
widechar_width.h \
../3rdparty/discord/rpc/include/discord_register.h \
../3rdparty/discord/rpc/include/discord_rpc.h \
../3rdparty/sentry-native/include/sentry.h
../3rdparty/discord/rpc/include/discord_rpc.h

macx {
HEADERS += ../3rdparty/sentry-native/include/sentry.h
}

macx|win32 {
macx {
Expand Down

0 comments on commit b92a17f

Please sign in to comment.