From 0048e61fc7eb48841aacf0225e22ad319f933c6e Mon Sep 17 00:00:00 2001 From: GPUCode <47210458+GPUCode@users.noreply.github.com> Date: Sun, 6 Aug 2023 22:23:53 +0300 Subject: [PATCH] Fix compilation without ENABLE_WEB_SERVICE (#6856) --- CMakeLists.txt | 1 + externals/CMakeLists.txt | 61 ++++++++++++++-------------- src/core/CMakeLists.txt | 28 ++++++++----- src/core/core.cpp | 6 +++ src/core/core.h | 2 + src/core/hle/service/http/http_c.cpp | 5 --- src/core/hle/service/http/http_c.h | 4 -- src/network/CMakeLists.txt | 6 +-- src/web_service/CMakeLists.txt | 1 - 9 files changed, 60 insertions(+), 54 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b6dc9c40..a52c4f66a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,6 +57,7 @@ CMAKE_DEPENDENT_OPTION(ENABLE_TESTS "Enable generating tests executable" ON "NOT CMAKE_DEPENDENT_OPTION(ENABLE_DEDICATED_ROOM "Enable generating dedicated room executable" ON "NOT ANDROID AND NOT IOS" OFF) option(ENABLE_WEB_SERVICE "Enable web services (telemetry, etc.)" ON) +option(ENABLE_SCRIPTING "Enable RPC server for scripting" ON) CMAKE_DEPENDENT_OPTION(ENABLE_CUBEB "Enables the cubeb audio backend" ON "NOT IOS" OFF) option(ENABLE_OPENAL "Enables the OpenAL audio backend" ON) diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt index 1927d2ef6..38038af1d 100644 --- a/externals/CMakeLists.txt +++ b/externals/CMakeLists.txt @@ -173,37 +173,38 @@ endif() add_library(json-headers INTERFACE) target_include_directories(json-headers INTERFACE ./json) +# OpenSSL +if (USE_SYSTEM_OPENSSL) + find_package(OpenSSL 1.1) + if (OPENSSL_FOUND) + set(OPENSSL_LIBRARIES OpenSSL::SSL OpenSSL::Crypto) + endif() +endif() + +if (NOT OPENSSL_FOUND) + # LibreSSL + set(LIBRESSL_SKIP_INSTALL ON CACHE BOOL "") + set(OPENSSLDIR "/etc/ssl/") + add_subdirectory(libressl EXCLUDE_FROM_ALL) + target_include_directories(ssl INTERFACE ./libressl/include) + target_compile_definitions(ssl PRIVATE -DHAVE_INET_NTOP) + get_directory_property(OPENSSL_LIBRARIES + DIRECTORY libressl + DEFINITION OPENSSL_LIBS) +endif() + +# httplib +add_library(httplib INTERFACE) +target_include_directories(httplib INTERFACE ./httplib) +target_compile_options(httplib INTERFACE -DCPPHTTPLIB_OPENSSL_SUPPORT) +target_link_libraries(httplib INTERFACE ${OPENSSL_LIBRARIES}) + +if(ANDROID) + add_subdirectory(android-ifaddrs) +endif() + +# cpp-jwt if (ENABLE_WEB_SERVICE) - if (USE_SYSTEM_OPENSSL) - find_package(OpenSSL 1.1) - if (OPENSSL_FOUND) - set(OPENSSL_LIBRARIES OpenSSL::SSL OpenSSL::Crypto) - endif() - endif() - - if (NOT OPENSSL_FOUND) - # LibreSSL - set(LIBRESSL_SKIP_INSTALL ON CACHE BOOL "") - set(OPENSSLDIR "/etc/ssl/") - add_subdirectory(libressl EXCLUDE_FROM_ALL) - target_include_directories(ssl INTERFACE ./libressl/include) - target_compile_definitions(ssl PRIVATE -DHAVE_INET_NTOP) - get_directory_property(OPENSSL_LIBRARIES - DIRECTORY libressl - DEFINITION OPENSSL_LIBS) - endif() - - if(ANDROID) - add_subdirectory(android-ifaddrs) - endif() - - # httplib - add_library(httplib INTERFACE) - target_include_directories(httplib INTERFACE ./httplib) - target_compile_options(httplib INTERFACE -DCPPHTTPLIB_OPENSSL_SUPPORT) - target_link_libraries(httplib INTERFACE ${OPENSSL_LIBRARIES}) - - # cpp-jwt add_library(cpp-jwt INTERFACE) target_include_directories(cpp-jwt INTERFACE ./cpp-jwt/include) target_compile_definitions(cpp-jwt INTERFACE CPP_JWT_USE_VENDORED_NLOHMANN_JSON) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index f507b5dc4..5ac61ce23 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -461,14 +461,6 @@ add_library(citra_core STATIC perf_stats.cpp perf_stats.h precompiled_headers.h - rpc/packet.cpp - rpc/packet.h - rpc/rpc_server.cpp - rpc/rpc_server.h - rpc/server.cpp - rpc/server.h - rpc/udp_server.cpp - rpc/udp_server.h savestate.cpp savestate.h system_titles.cpp @@ -483,18 +475,32 @@ add_library(citra_core STATIC create_target_directory_groups(citra_core) target_link_libraries(citra_core PUBLIC citra_common PRIVATE audio_core network video_core) -target_link_libraries(citra_core PRIVATE Boost::boost Boost::serialization Boost::iostreams) +target_link_libraries(citra_core PRIVATE Boost::boost Boost::serialization Boost::iostreams httplib) target_link_libraries(citra_core PUBLIC dds-ktx PRIVATE cryptopp fmt::fmt lodepng open_source_archives) set_target_properties(citra_core PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${ENABLE_LTO}) if (ENABLE_WEB_SERVICE) - target_compile_definitions(citra_core PRIVATE -DENABLE_WEB_SERVICE -DCPPHTTPLIB_OPENSSL_SUPPORT) - target_link_libraries(citra_core PRIVATE web_service ${OPENSSL_LIBS} httplib) + target_compile_definitions(citra_core PRIVATE -DENABLE_WEB_SERVICE) + target_link_libraries(citra_core PRIVATE web_service) if (ANDROID) target_link_libraries(citra_core PRIVATE ifaddrs) endif() endif() +if (ENABLE_SCRIPTING) + target_compile_definitions(citra_core PRIVATE -DENABLE_SCRIPTING) + target_sources(citra_core PRIVATE + rpc/packet.cpp + rpc/packet.h + rpc/rpc_server.cpp + rpc/rpc_server.h + rpc/server.cpp + rpc/server.h + rpc/udp_server.cpp + rpc/udp_server.h + ) +endif() + if ("x86_64" IN_LIST ARCHITECTURE OR "arm64" IN_LIST ARCHITECTURE) target_sources(citra_core PRIVATE arm/dynarmic/arm_dynarmic.cpp diff --git a/src/core/core.cpp b/src/core/core.cpp index 97f71d7d6..de239fe21 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -45,7 +45,9 @@ #include "core/hw/lcd.h" #include "core/loader/loader.h" #include "core/movie.h" +#ifdef ENABLE_SCRIPTING #include "core/rpc/server.h" +#endif #include "core/telemetry_session.h" #include "network/network.h" #include "video_core/custom_textures/custom_tex_manager.h" @@ -418,7 +420,9 @@ System::ResultStatus System::Init(Frontend::EmuWindow& emu_window, telemetry_session = std::make_unique(); +#ifdef ENABLE_SCRIPTING rpc_server = std::make_unique(*this); +#endif service_manager = std::make_unique(*this); archive_manager = std::make_unique(*this); @@ -555,7 +559,9 @@ void System::Shutdown(bool is_deserializing) { } custom_tex_manager.reset(); telemetry_session.reset(); +#ifdef ENABLE_SCRIPTING rpc_server.reset(); +#endif archive_manager.reset(); service_manager.reset(); dsp_core.reset(); diff --git a/src/core/core.h b/src/core/core.h index 4c401b736..ae3310ca7 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -405,8 +405,10 @@ private: /// Image interface std::shared_ptr registered_image_interface; +#ifdef ENABLE_SCRIPTING /// RPC Server for scripting support std::unique_ptr rpc_server; +#endif std::unique_ptr archive_manager; diff --git a/src/core/hle/service/http/http_c.cpp b/src/core/hle/service/http/http_c.cpp index f3583982c..30f16db9f 100644 --- a/src/core/hle/service/http/http_c.cpp +++ b/src/core/hle/service/http/http_c.cpp @@ -77,7 +77,6 @@ static std::pair SplitUrl(const std::string& url) { void Context::MakeRequest() { ASSERT(state == RequestState::NotStarted); -#ifdef ENABLE_WEB_SERVICE const auto& [host, path] = SplitUrl(url); const auto client = std::make_unique(host); SSL_CTX* ctx = client->ssl_context(); @@ -128,10 +127,6 @@ void Context::MakeRequest() { // TODO(B3N30): Verify this state on HW state = RequestState::ReadyToDownloadContent; } -#else - LOG_ERROR(Service_HTTP, "Tried to make request but WebServices is not enabled in this build"); - state = RequestState::TimedOut; -#endif } void HTTP_C::Initialize(Kernel::HLERequestContext& ctx) { diff --git a/src/core/hle/service/http/http_c.h b/src/core/hle/service/http/http_c.h index 7b2045465..4ba7d2576 100644 --- a/src/core/hle/service/http/http_c.h +++ b/src/core/hle/service/http/http_c.h @@ -17,12 +17,10 @@ #include #include #include -#ifdef ENABLE_WEB_SERVICE #if defined(__ANDROID__) #include #endif #include -#endif #include "core/hle/kernel/shared_memory.h" #include "core/hle/service/service.h" @@ -217,9 +215,7 @@ public: std::future request_future; std::atomic current_download_size_bytes; std::atomic total_download_size_bytes; -#ifdef ENABLE_WEB_SERVICE httplib::Response response; -#endif }; struct SessionData : public Kernel::SessionRequestHandler::SessionDataBase { diff --git a/src/network/CMakeLists.txt b/src/network/CMakeLists.txt index 18dc7e632..48a449d40 100644 --- a/src/network/CMakeLists.txt +++ b/src/network/CMakeLists.txt @@ -19,14 +19,14 @@ add_library(network STATIC create_target_directory_groups(network) if (ENABLE_WEB_SERVICE) - target_compile_definitions(network PRIVATE -DENABLE_WEB_SERVICE -DCPPHTTPLIB_OPENSSL_SUPPORT) - target_link_libraries(network PRIVATE web_service httplib) + target_compile_definitions(network PRIVATE -DENABLE_WEB_SERVICE) + target_link_libraries(network PRIVATE web_service) if (ANDROID) target_link_libraries(network PRIVATE ifaddrs) endif() endif() -target_link_libraries(network PRIVATE citra_common enet Boost::serialization) +target_link_libraries(network PRIVATE citra_common enet Boost::serialization httplib) set_target_properties(network PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${ENABLE_LTO}) if (CITRA_USE_PRECOMPILED_HEADERS) diff --git a/src/web_service/CMakeLists.txt b/src/web_service/CMakeLists.txt index d03023604..2a97e2b1c 100644 --- a/src/web_service/CMakeLists.txt +++ b/src/web_service/CMakeLists.txt @@ -16,7 +16,6 @@ add_library(web_service STATIC create_target_directory_groups(web_service) -target_compile_definitions(web_service PRIVATE -DCPPHTTPLIB_OPENSSL_SUPPORT) target_link_libraries(web_service PRIVATE citra_common network json-headers httplib cpp-jwt) target_link_libraries(web_service PUBLIC ${OPENSSL_LIBS}) set_target_properties(web_service PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${ENABLE_LTO})