diff --git a/CMakeLists.txt b/CMakeLists.txt index f6a813f..680cd8b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,17 @@ cmake_minimum_required(VERSION 3.0) +if (WIN32) + set(VCPKG_TARGET_TRIPLET "x64-windows-static") +elseif(UNIX) + set(VCPKG_TARGET_TRIPLET "x64-linux") +endif() + +option(USE_VCPKG "USE_VCPKG" ON) + +if(USE_VCPKG) + include(vcpkg.cmake) +endif() + message(STATUS "You can find build instructions and a list of dependencies in the README at \ https://github.com/BeamMP/BeamMP-Server") @@ -10,15 +22,6 @@ project(BeamMP-Server set(HTTPLIB_REQUIRE_OPENSSL ON) -include_directories("${PROJECT_SOURCE_DIR}/deps/asio/asio/include") -include_directories("${PROJECT_SOURCE_DIR}/deps/rapidjson/include") -include_directories("${PROJECT_SOURCE_DIR}/deps/websocketpp") -include_directories("${PROJECT_SOURCE_DIR}/deps/commandline") -include_directories("${PROJECT_SOURCE_DIR}/deps/sol2/include") -include_directories("${PROJECT_SOURCE_DIR}/deps/cpp-httplib") -include_directories("${PROJECT_SOURCE_DIR}/deps/json/single_include") -include_directories("${PROJECT_SOURCE_DIR}/deps") - add_compile_definitions(CPPHTTPLIB_OPENSSL_SUPPORT) if(APPLE) @@ -36,26 +39,6 @@ if (WIN32) STRING(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG}) endif() -include_directories("include/sentry-native/include") -set(SENTRY_BUILD_SHARED_LIBS OFF) -if (MSVC) - set(SENTRY_BUILD_RUNTIMESTATIC ON) -endif() -message(STATUS "Checking for Sentry URL") -# this is set by the build system. -# 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 "") - set(SENTRY_BACKEND none) -else() - string(LENGTH ${BEAMMP_SECRET_SENTRY_URL} URL_LEN) - message(STATUS "Sentry URL is length ${URL_LEN}") - set(SENTRY_BACKEND breakpad) -endif() -add_subdirectory("deps/sentry-native") - if (MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj") endif () @@ -81,7 +64,19 @@ elseif (UNIX) endif (SANITIZE) endif () - +message(STATUS "Checking for Sentry URL") +# this is set by the build system. +# 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 "") + set(SENTRY_BACKEND none) +else() + string(LENGTH ${BEAMMP_SECRET_SENTRY_URL} URL_LEN) + message(STATUS "Sentry URL is length ${URL_LEN}") + set(SENTRY_BACKEND breakpad) +endif() set(CMAKE_CXX_STANDARD 17) @@ -113,57 +108,34 @@ add_executable(BeamMP-Server target_compile_definitions(BeamMP-Server PRIVATE SECRET_SENTRY_URL="${BEAMMP_SECRET_SENTRY_URL}") include_directories(BeamMP-Server PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) -target_include_directories(BeamMP-Server PUBLIC - "${CMAKE_CURRENT_SOURCE_DIR}/include" - "${CMAKE_CURRENT_SOURCE_DIR}/commandline") +include(FindThreads) -if (APPLE) - message(STATUS "NOT looking for Lua on APPLE") -else() - message(STATUS "Looking for Lua") - find_package(Lua REQUIRED VERSION 5.3) -endif() +find_package(OpenSSL REQUIRED) +find_package(ZLIB REQUIRED) +find_package(CURL CONFIG REQUIRED) +find_package(Lua REQUIRED 5.3) +find_package(nlohmann_json CONFIG REQUIRED) +find_package(RapidJSON CONFIG REQUIRED) +find_package(sentry CONFIG REQUIRED) +find_package(sol2 CONFIG REQUIRED) +find_package(toml11 CONFIG REQUIRED) +find_path(CPP_HTTPLIB_INCLUDE_DIRS "httplib.h") -target_include_directories(BeamMP-Server PUBLIC - ${LUA_INCLUDE_DIR} - ${CURL_INCLUDE_DIRS} - "include/tomlplusplus" - "include/sentry-native/include" - "include/curl/include") +target_include_directories(BeamMP-Server PRIVATE + ${CPP_HTTPLIB_INCLUDE_DIRS} + ${LUA_INCLUDE_DIR} +) -message(STATUS "Looking for SSL") +target_link_libraries(BeamMP-Server PRIVATE OpenSSL::SSL OpenSSL::Crypto + ZLIB::ZLIB + CURL::libcurl + ${LUA_LIBRARIES} + Threads::Threads + commandline + nlohmann_json::nlohmann_json + rapidjson + sentry::sentry + sol2::sol2 + toml11::toml11 +) -if (APPLE) - set(OPENSSL_LIBRARIES ssl crypto) -else() - find_package(OpenSSL REQUIRED) -endif() - -target_link_libraries(BeamMP-Server sol2::sol2 ${LUA_LIBRARIES}) -message(STATUS "CURL IS ${CURL_LIBRARIES}") - -if (UNIX) - target_link_libraries(BeamMP-Server - z - pthread - ${LUA_LIBRARIES} - crypto - ${OPENSSL_LIBRARIES} - commandline - sentry - ssl) -elseif (WIN32) - include(FindLua) - message(STATUS "Looking for libz") - find_package(ZLIB REQUIRED) - message(STATUS "Looking for RapidJSON") - find_package(RapidJSON CONFIG REQUIRED) - target_include_directories(BeamMP-Server PRIVATE ${RAPIDJSON_INCLUDE_DIRS}) - target_link_libraries(BeamMP-Server - ws2_32 - ZLIB::ZLIB - ${LUA_LIBRARIES} - ${OPENSSL_LIBRARIES} - commandline - sentry) -endif () diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 4e556b0..6f87000 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -1,9 +1,4 @@ -include_directories("${PROJECT_SOURCE_DIR}/deps/asio/asio/include") -include_directories("${PROJECT_SOURCE_DIR}/deps/rapidjson/include") -include_directories("${PROJECT_SOURCE_DIR}/deps/websocketpp") -include_directories("${PROJECT_SOURCE_DIR}/deps/commandline") -include_directories("${PROJECT_SOURCE_DIR}/deps/sol2/include") include_directories("${PROJECT_SOURCE_DIR}/deps") +include_directories("${PROJECT_SOURCE_DIR}/deps/commandline") add_subdirectory("${PROJECT_SOURCE_DIR}/deps/commandline") -add_subdirectory("${PROJECT_SOURCE_DIR}/deps/sol2") diff --git a/include/TConfig.h b/include/TConfig.h index 3fcc597..b05f422 100644 --- a/include/TConfig.h +++ b/include/TConfig.h @@ -5,7 +5,7 @@ #include #define TOML11_PRESERVE_COMMENTS_BY_DEFAULT -#include // header-only version of TOML++ +#include // header-only version of TOML++ namespace fs = std::filesystem; diff --git a/include/TLuaEngine.h b/include/TLuaEngine.h index 5ca2222..876d910 100644 --- a/include/TLuaEngine.h +++ b/include/TLuaEngine.h @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/TSentry.cpp b/src/TSentry.cpp index da05c10..7f2b416 100644 --- a/src/TSentry.cpp +++ b/src/TSentry.cpp @@ -72,7 +72,7 @@ void TSentry::Log(SentryLevel level, const std::string& logger, const std::strin SetContext("threads", { { "thread-name", ThreadName(true) } }); auto Msg = sentry_value_new_message_event(sentry_level_t(level), logger.c_str(), text.c_str()); sentry_capture_event(Msg); - sentry_remove_transaction(); + sentry_set_transaction(nullptr); } void TSentry::LogError(const std::string& text, const std::string& file, const std::string& line) { diff --git a/vcpkg.cmake b/vcpkg.cmake new file mode 100644 index 0000000..56b51e5 --- /dev/null +++ b/vcpkg.cmake @@ -0,0 +1,18 @@ +include(FetchContent) + +message(STATUS "Getting, checking and running vcpkg, this may take a while") + +FetchContent_Declare( + vcpkg + GIT_REPOSITORY https://github.com/microsoft/vcpkg.git +) + +FetchContent_GetProperties(vcpkg) + +if(NOT vcpkg_POPULATED) + FetchContent_Populate(vcpkg) + execute_process(COMMAND ./${vcpkg_SOURCE_DIR}/bootstrap-vcpkg.sh) +endif() + +set(CMAKE_TOOLCHAIN_FILE ${vcpkg_SOURCE_DIR}/scripts/buildsystems/vcpkg.cmake +CACHE STRING "Vcpkg toolchain file") diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 0000000..f28fa5b --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,17 @@ +{ + "name": "beammp-server", + "version-string": "3.0.2", + "homepage": "https://beammp.com", + "dependencies": [ + "sentry-native", + "lua", + "zlib", + "rapidjson", + "nlohmann-json", + "openssl", + "curl", + "sol2", + "cpp-httplib", + "toml11" + ] +}