From e6c97de3c4098b15bf8980e3b48a31ce9680dedd Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Sun, 8 Aug 2021 20:29:54 +0200 Subject: [PATCH] CMakeLists: improve documentation, emit warning if no Sentry URL is supplied --- CMakeLists.txt | 19 ++++++++++++++++--- src/Sentry.cpp | 10 ++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ca57dd8..096cfb3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,15 @@ cmake_minimum_required(VERSION 3.0) -project(Server) +project(BeamMP-Server + DESCRIPTION "Server for BeamMP - The Multiplayer Mod for BeamNG.drive" + HOMEPAGE_URL https://beammp.com + LANGUAGES CXX) + +message(STATUS "You can find build instructions and a list of dependencies in the README at \ +https://github.com/BeamMP/BeamMP-Server") add_subdirectory("include/sentry-native") +message(STATUS "Setting compiler flags") if (WIN32) message(STATUS "MSVC -> forcing use of statically-linked runtime.") STRING(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE}) @@ -21,12 +28,16 @@ elseif (UNIX) endif (SANITIZE) endif () +message(STATUS "Checking for Sentry URL") # this is set by the build system. -# if you're building from source, just leave this empty +# IMPORTANT: if you're building from source, just leave this empty if (NOT DEFINED BEAMMP_SECRET_SENTRY_URL) + message(WARNING "No sentry URL configured. Sentry logging is disabled for this build. \ + This is not an error, and if you're building the BeamMP-Server yourself, this is expected and can be ignored.") set(BEAMMP_SECRET_SENTRY_URL "") endif() +message(STATUS "Adding local source dependencies") # this has to happen before -DDEBUG since it wont compile properly with -DDEBUG include_directories("asio/asio/include") include_directories("rapidjson/include") @@ -35,9 +46,9 @@ add_subdirectory("socket.io-client-cpp") add_subdirectory("include/commandline") set(CMAKE_CXX_STANDARD 17) - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG") +message(STATUS "Looking for Boost") find_package(Boost REQUIRED COMPONENTS system thread) add_executable(BeamMP-Server @@ -60,9 +71,11 @@ add_executable(BeamMP-Server target_include_directories(BeamMP-Server PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/commandline") +message(STATUS "Looking for Lua") find_package(Lua REQUIRED) target_include_directories(BeamMP-Server PUBLIC ${Boost_INCLUDE_DIRS} ${LUA_INCLUDE_DIR} "socket.io-client-cpp/src" "include/tomlplusplus" "include/sentry-native") +message(STATUS "Looking for SSL") find_package(OpenSSL REQUIRED) if (UNIX) diff --git a/src/Sentry.cpp b/src/Sentry.cpp index 2d92f5a..66f7173 100644 --- a/src/Sentry.cpp +++ b/src/Sentry.cpp @@ -10,6 +10,7 @@ TSentry::TSentry(const std::string& SentryUrl) { sentry_options_set_dsn(options, SentryUrl.c_str()); auto ReleaseString = "BeamMP-Server@" + Application::ServerVersion(); sentry_options_set_release(options, ReleaseString.c_str()); + sentry_options_set_max_breadcrumbs(options, 10); sentry_init(options); } } @@ -21,14 +22,23 @@ TSentry::~TSentry() { } void TSentry::Log(sentry_level_t level, const std::string& logger, const std::string& text) { + if (!mValid) { + return; + } sentry_capture_event(sentry_value_new_message_event(level, logger.c_str(), text.c_str())); } void TSentry::LogException(const std::exception& e, const std::string& file, const std::string& line) { + if (!mValid) { + return; + } Log(SENTRY_LEVEL_ERROR, "exceptions", std::string(e.what()) + " @ " + file + ":" + line); } void TSentry::AddErrorBreadcrumb(const std::string& msg, const std::string& file, const std::string& line) { + if (!mValid) { + return; + } auto crumb = sentry_value_new_breadcrumb("default", (msg + " @ " + file + ":" + line).c_str()); sentry_value_set_by_key(crumb, "level", sentry_value_new_string("error")); sentry_add_breadcrumb(crumb);