From fce7afb8dc862c267aa43c618cce91d7f8a6fa50 Mon Sep 17 00:00:00 2001 From: EverOddish Date: Sun, 23 Sep 2018 18:16:57 -0400 Subject: [PATCH 1/3] Added CMake option to enable/disable scripting support --- CMakeLists.txt | 6 ++ externals/CMakeLists.txt | 172 ++++++++++++++++++++------------------- src/core/CMakeLists.txt | 27 +++--- src/core/core.cpp | 8 ++ src/core/core.h | 4 + 5 files changed, 122 insertions(+), 95 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2797d182e..dee71e5e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,8 @@ option(ENABLE_CUBEB "Enables the cubeb audio backend" ON) option(USE_DISCORD_PRESENCE "Enables Discord Rich Presence" OFF) +option(ENABLE_SCRIPTING ON) + if(NOT EXISTS ${CMAKE_SOURCE_DIR}/.git/hooks/pre-commit) message(STATUS "Copying pre-commit hook") file(COPY hooks/pre-commit @@ -258,6 +260,10 @@ if (CITRA_ENABLE_COMPATIBILITY_REPORTING) add_definitions(-DCITRA_ENABLE_COMPATIBILITY_REPORTING) endif() +if (ENABLE_SCRIPTING) + add_definitions(-DENABLE_SCRIPTING) +endif() + # Platform-specific library requirements # ====================================== diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt index 8ea3c8b44..aa8b0d6f2 100644 --- a/externals/CMakeLists.txt +++ b/externals/CMakeLists.txt @@ -94,95 +94,97 @@ if (ENABLE_WEB_SERVICE) target_include_directories(json-headers INTERFACE ./json) endif() -# ZeroMQ -# libzmq includes its own clang-format target, which conflicts with the -# clang-format in Citra if libzmq is added as a subdirectory. An external -# project gets around this issue. Unfortunately, a lot of different -# configuration options are required for each different platform. An -# attempt was made to use CMake variables where possible, but some -# information necessarily had to be repeated. Hopefully there is not -# often a need to change anything. -if (MINGW) - if (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows") - set(LIBZMQ_MAKE mingw32-make) - set(LIBZMQ_COMPILER "") - set(LIBZMQ_TOOLCHAIN_FILE "") +if (ENABLE_SCRIPTING) + # ZeroMQ + # libzmq includes its own clang-format target, which conflicts with the + # clang-format in Citra if libzmq is added as a subdirectory. An external + # project gets around this issue. Unfortunately, a lot of different + # configuration options are required for each different platform. An + # attempt was made to use CMake variables where possible, but some + # information necessarily had to be repeated. Hopefully there is not + # often a need to change anything. + if (MINGW) + if (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows") + set(LIBZMQ_MAKE mingw32-make) + set(LIBZMQ_COMPILER "") + set(LIBZMQ_TOOLCHAIN_FILE "") + else() + set(LIBZMQ_MAKE make) + set(LIBZMQ_COMPILER -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER};-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}) + set(LIBZMQ_TOOLCHAIN_FILE -DCMAKE_TOOLCHAIN_FILE=${PROJECT_SOURCE_DIR}/CMakeModules/MinGWCross.cmake) + endif() + ExternalProject_Add(libzmq-external + SOURCE_DIR ./libzmq + CMAKE_ARGS -DWITH_PERF_TOOL=OFF;-DZMQ_BUILD_TESTS=OFF;-DENABLE_CPACK=OFF;-DCMAKE_MAKE_PROGRAM=${LIBZMQ_MAKE};-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE};${LIBZMQ_TOOLCHAIN_FILE};${LIBZMQ_COMPILER} + BUILD_COMMAND cmake --build ${CMAKE_CURRENT_BINARY_DIR}/libzmq-external-prefix/src/libzmq-external-build --target libzmq-static --config ${CMAKE_BUILD_TYPE} + GIT_REPOSITORY https://github.com/zeromq/libzmq + GIT_TAG v4.2.5 + INSTALL_COMMAND "") else() - set(LIBZMQ_MAKE make) - set(LIBZMQ_COMPILER -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER};-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}) - set(LIBZMQ_TOOLCHAIN_FILE -DCMAKE_TOOLCHAIN_FILE=${PROJECT_SOURCE_DIR}/CMakeModules/MinGWCross.cmake) + if (MSVC) + set(LIBZMQ_COMPILER_FLAGS -DCMAKE_C_FLAGS=/GL-;-DCMAKE_CXX_FLAGS=/GL-) + else() + set(LIBZMQ_COMPILER_FLAGS "") + endif() + ExternalProject_Add(libzmq-external + SOURCE_DIR ./libzmq + CMAKE_ARGS -DCMAKE_MACOSX_RPATH=1;-DCMAKE_OSX_ARCHITECTURES=x86_64;-DWITH_PERF_TOOL=OFF;-DZMQ_BUILD_TESTS=OFF;-DENABLE_CPACK=OFF;-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE};${LIBZMQ_COMPILER_FLAGS} + BUILD_COMMAND cmake --build ${CMAKE_CURRENT_BINARY_DIR}/libzmq-external-prefix/src/libzmq-external-build --target libzmq-static --config ${CMAKE_BUILD_TYPE} + GIT_REPOSITORY https://github.com/zeromq/libzmq + GIT_TAG v4.2.5 + INSTALL_COMMAND "") endif() - ExternalProject_Add(libzmq-external - SOURCE_DIR ./libzmq - CMAKE_ARGS -DWITH_PERF_TOOL=OFF;-DZMQ_BUILD_TESTS=OFF;-DENABLE_CPACK=OFF;-DCMAKE_MAKE_PROGRAM=${LIBZMQ_MAKE};-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE};${LIBZMQ_TOOLCHAIN_FILE};${LIBZMQ_COMPILER} - BUILD_COMMAND cmake --build ${CMAKE_CURRENT_BINARY_DIR}/libzmq-external-prefix/src/libzmq-external-build --target libzmq-static --config ${CMAKE_BUILD_TYPE} - GIT_REPOSITORY https://github.com/zeromq/libzmq - GIT_TAG v4.2.5 - INSTALL_COMMAND "") -else() - if (MSVC) - set(LIBZMQ_COMPILER_FLAGS -DCMAKE_C_FLAGS=/GL-;-DCMAKE_CXX_FLAGS=/GL-) - else() - set(LIBZMQ_COMPILER_FLAGS "") - endif() - ExternalProject_Add(libzmq-external - SOURCE_DIR ./libzmq - CMAKE_ARGS -DCMAKE_MACOSX_RPATH=1;-DCMAKE_OSX_ARCHITECTURES=x86_64;-DWITH_PERF_TOOL=OFF;-DZMQ_BUILD_TESTS=OFF;-DENABLE_CPACK=OFF;-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE};${LIBZMQ_COMPILER_FLAGS} - BUILD_COMMAND cmake --build ${CMAKE_CURRENT_BINARY_DIR}/libzmq-external-prefix/src/libzmq-external-build --target libzmq-static --config ${CMAKE_BUILD_TYPE} - GIT_REPOSITORY https://github.com/zeromq/libzmq - GIT_TAG v4.2.5 - INSTALL_COMMAND "") -endif() -set(LIBZMQ_DIR ${CMAKE_CURRENT_BINARY_DIR}/libzmq-external-prefix/src/libzmq-external-build/lib) -# On macOS, we need to build a fat static library containing both x86_64 and x86_64h, since macOS -# targets specify two architectures in their link command line ("-arch x86_64 -arch x86_64h"). -if (APPLE) - ExternalProject_Add(libzmq-external-h - SOURCE_DIR ./libzmq-h - CMAKE_ARGS -DCMAKE_MACOSX_RPATH=1;-DCMAKE_OSX_ARCHITECTURES=x86_64h;-DWITH_PERF_TOOL=OFF;-DZMQ_BUILD_TESTS=OFF;-DENABLE_CPACK=OFF;-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} - BUILD_COMMAND cmake --build ${CMAKE_CURRENT_BINARY_DIR}/libzmq-external-h-prefix/src/libzmq-external-h-build --target libzmq-static --config ${CMAKE_BUILD_TYPE} - GIT_REPOSITORY https://github.com/zeromq/libzmq - GIT_TAG v4.2.5 - INSTALL_COMMAND "") - set(LIBZMQ_H_DIR ${CMAKE_CURRENT_BINARY_DIR}/libzmq-external-h-prefix/src/libzmq-external-h-build/lib) - - add_library(libzmq-external-imported STATIC IMPORTED GLOBAL) - add_library(libzmq-external-imported-h STATIC IMPORTED GLOBAL) - add_dependencies(libzmq-external-imported libzmq-external) - add_dependencies(libzmq-external-imported-h libzmq-external-h) -else() - add_library(libzmq STATIC IMPORTED GLOBAL) - add_dependencies(libzmq libzmq-external) -endif() -# Set up the imported target properties -if (MSVC) - set_target_properties(libzmq PROPERTIES IMPORTED_LOCATION ${LIBZMQ_DIR}/${CMAKE_BUILD_TYPE}/libzmq-v141-mt-s-4_2_5${CMAKE_STATIC_LIBRARY_SUFFIX}) - set_target_properties(libzmq PROPERTIES IMPORTED_LINK_INTERFACE_LIBRARIES iphlpapi${CMAKE_STATIC_LIBRARY_SUFFIX}) -else() + set(LIBZMQ_DIR ${CMAKE_CURRENT_BINARY_DIR}/libzmq-external-prefix/src/libzmq-external-build/lib) + # On macOS, we need to build a fat static library containing both x86_64 and x86_64h, since macOS + # targets specify two architectures in their link command line ("-arch x86_64 -arch x86_64h"). if (APPLE) - set_target_properties(libzmq-external-imported PROPERTIES IMPORTED_LOCATION ${LIBZMQ_DIR}/libzmq${CMAKE_STATIC_LIBRARY_SUFFIX}) - set_target_properties(libzmq-external-imported-h PROPERTIES IMPORTED_LOCATION ${LIBZMQ_H_DIR}/libzmq${CMAKE_STATIC_LIBRARY_SUFFIX}) + ExternalProject_Add(libzmq-external-h + SOURCE_DIR ./libzmq-h + CMAKE_ARGS -DCMAKE_MACOSX_RPATH=1;-DCMAKE_OSX_ARCHITECTURES=x86_64h;-DWITH_PERF_TOOL=OFF;-DZMQ_BUILD_TESTS=OFF;-DENABLE_CPACK=OFF;-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + BUILD_COMMAND cmake --build ${CMAKE_CURRENT_BINARY_DIR}/libzmq-external-h-prefix/src/libzmq-external-h-build --target libzmq-static --config ${CMAKE_BUILD_TYPE} + GIT_REPOSITORY https://github.com/zeromq/libzmq + GIT_TAG v4.2.5 + INSTALL_COMMAND "") + set(LIBZMQ_H_DIR ${CMAKE_CURRENT_BINARY_DIR}/libzmq-external-h-prefix/src/libzmq-external-h-build/lib) + + add_library(libzmq-external-imported STATIC IMPORTED GLOBAL) + add_library(libzmq-external-imported-h STATIC IMPORTED GLOBAL) + add_dependencies(libzmq-external-imported libzmq-external) + add_dependencies(libzmq-external-imported-h libzmq-external-h) else() - set_target_properties(libzmq PROPERTIES IMPORTED_LOCATION ${LIBZMQ_DIR}/libzmq${CMAKE_STATIC_LIBRARY_SUFFIX}) - if(MINGW) - set_target_properties(libzmq PROPERTIES IMPORTED_LINK_INTERFACE_LIBRARIES "ws2_32${CMAKE_STATIC_LIBRARY_SUFFIX};iphlpapi${CMAKE_STATIC_LIBRARY_SUFFIX}") + add_library(libzmq STATIC IMPORTED GLOBAL) + add_dependencies(libzmq libzmq-external) + endif() + # Set up the imported target properties + if (MSVC) + set_target_properties(libzmq PROPERTIES IMPORTED_LOCATION ${LIBZMQ_DIR}/${CMAKE_BUILD_TYPE}/libzmq-v141-mt-s-4_2_5${CMAKE_STATIC_LIBRARY_SUFFIX}) + set_target_properties(libzmq PROPERTIES IMPORTED_LINK_INTERFACE_LIBRARIES iphlpapi${CMAKE_STATIC_LIBRARY_SUFFIX}) + else() + if (APPLE) + set_target_properties(libzmq-external-imported PROPERTIES IMPORTED_LOCATION ${LIBZMQ_DIR}/libzmq${CMAKE_STATIC_LIBRARY_SUFFIX}) + set_target_properties(libzmq-external-imported-h PROPERTIES IMPORTED_LOCATION ${LIBZMQ_H_DIR}/libzmq${CMAKE_STATIC_LIBRARY_SUFFIX}) + else() + set_target_properties(libzmq PROPERTIES IMPORTED_LOCATION ${LIBZMQ_DIR}/libzmq${CMAKE_STATIC_LIBRARY_SUFFIX}) + if(MINGW) + set_target_properties(libzmq PROPERTIES IMPORTED_LINK_INTERFACE_LIBRARIES "ws2_32${CMAKE_STATIC_LIBRARY_SUFFIX};iphlpapi${CMAKE_STATIC_LIBRARY_SUFFIX}") + endif() endif() endif() + # On macOS, create the combined target + if (APPLE) + set(LIBZMQ_COMBINED_OUTPUT ${LIBZMQ_DIR}/libzmq_combined${CMAKE_STATIC_LIBRARY_SUFFIX}) + add_custom_target(libzmq-combined COMMAND lipo -create ${LIBZMQ_DIR}/libzmq${CMAKE_STATIC_LIBRARY_SUFFIX} ${LIBZMQ_H_DIR}/libzmq${CMAKE_STATIC_LIBRARY_SUFFIX} -o ${LIBZMQ_COMBINED_OUTPUT} + BYPRODUCTS ${LIBZMQ_COMBINED_OUTPUT}) + add_dependencies(libzmq-combined libzmq-external-imported libzmq-external-imported-h) + add_library(libzmq STATIC IMPORTED GLOBAL) + set_target_properties(libzmq PROPERTIES IMPORTED_LOCATION ${LIBZMQ_COMBINED_OUTPUT}) + add_dependencies(libzmq libzmq-combined) + endif() + # C interface to ZeroMQ + add_library(libzmq-headers INTERFACE) + target_include_directories(libzmq-headers INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/libzmq/include) + # C++ interface to ZeroMQ + add_library(cppzmq-headers INTERFACE) + target_include_directories(cppzmq-headers INTERFACE ./cppzmq) + add_dependencies(cppzmq-headers libzmq) endif() -# On macOS, create the combined target -if (APPLE) - set(LIBZMQ_COMBINED_OUTPUT ${LIBZMQ_DIR}/libzmq_combined${CMAKE_STATIC_LIBRARY_SUFFIX}) - add_custom_target(libzmq-combined COMMAND lipo -create ${LIBZMQ_DIR}/libzmq${CMAKE_STATIC_LIBRARY_SUFFIX} ${LIBZMQ_H_DIR}/libzmq${CMAKE_STATIC_LIBRARY_SUFFIX} -o ${LIBZMQ_COMBINED_OUTPUT} - BYPRODUCTS ${LIBZMQ_COMBINED_OUTPUT}) - add_dependencies(libzmq-combined libzmq-external-imported libzmq-external-imported-h) - add_library(libzmq STATIC IMPORTED GLOBAL) - set_target_properties(libzmq PROPERTIES IMPORTED_LOCATION ${LIBZMQ_COMBINED_OUTPUT}) - add_dependencies(libzmq libzmq-combined) -endif() -# C interface to ZeroMQ -add_library(libzmq-headers INTERFACE) -target_include_directories(libzmq-headers INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/libzmq/include) -# C++ interface to ZeroMQ -add_library(cppzmq-headers INTERFACE) -target_include_directories(cppzmq-headers INTERFACE ./cppzmq) -add_dependencies(cppzmq-headers libzmq) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index b1a14c782..7226d1bce 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(core STATIC +set(core_sources 3ds.h announce_multiplayer_session.cpp announce_multiplayer_session.h @@ -410,14 +410,6 @@ add_library(core STATIC movie.h perf_stats.cpp perf_stats.h - rpc/packet.cpp - rpc/packet.h - rpc/rpc_server.cpp - rpc/rpc_server.h - rpc/server.cpp - rpc/server.h - rpc/zmq_server.cpp - rpc/zmq_server.h settings.cpp settings.h telemetry_session.cpp @@ -426,6 +418,19 @@ add_library(core STATIC tracer/recorder.cpp tracer/recorder.h ) +if (ENABLE_SCRIPTING) + list(APPEND core_sources + rpc/packet.cpp + rpc/packet.h + rpc/rpc_server.cpp + rpc/rpc_server.h + rpc/server.cpp + rpc/server.h + rpc/zmq_server.cpp + rpc/zmq_server.h + ) +endif() +add_library(core STATIC ${core_sources}) create_target_directory_groups(core) @@ -445,4 +450,6 @@ if (ARCHITECTURE_x86_64) target_link_libraries(core PRIVATE dynarmic) endif() -target_link_libraries(core PUBLIC libzmq-headers cppzmq-headers libzmq) +if (ENABLE_SCRIPTING) + target_link_libraries(core PUBLIC libzmq-headers cppzmq-headers libzmq) +endif() diff --git a/src/core/core.cpp b/src/core/core.cpp index cef1ddc4b..9fb520fe5 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -25,7 +25,9 @@ #include "core/loader/loader.h" #include "core/memory_setup.h" #include "core/movie.h" +#ifdef ENABLE_SCRIPTING #include "core/rpc/rpc_server.h" +#endif #include "core/settings.h" #include "network/network.h" #include "video_core/video_core.h" @@ -182,7 +184,11 @@ System::ResultStatus System::Init(EmuWindow& emu_window, u32 system_mode) { dsp_core->EnableStretching(Settings::values.enable_audio_stretching); telemetry_session = std::make_unique(); + +#ifdef ENABLE_SCRIPTING rpc_server = std::make_unique(); +#endif + service_manager = std::make_shared(); shared_page_handler = std::make_shared(); @@ -234,7 +240,9 @@ void System::Shutdown() { Kernel::Shutdown(); HW::Shutdown(); telemetry_session.reset(); +#ifdef ENABLE_SCRIPTING rpc_server.reset(); +#endif service_manager.reset(); dsp_core.reset(); cpu_core.reset(); diff --git a/src/core/core.h b/src/core/core.h index 12a1e5c68..517d53e97 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -21,9 +21,11 @@ namespace AudioCore { class DspInterface; } +#ifdef ENABLE_SCRIPTING namespace RPC { class RPCServer; } +#endif namespace Service { namespace SM { @@ -220,8 +222,10 @@ private: /// Frontend applets std::shared_ptr registered_swkbd; +#ifdef ENABLE_SCRIPTING /// RPC Server for scripting support std::unique_ptr rpc_server; +#endif /// Shared Page std::shared_ptr shared_page_handler; From 15d44f04501da9a7e055b0ba24662c18845e0fb3 Mon Sep 17 00:00:00 2001 From: EverOddish Date: Sun, 23 Sep 2018 20:13:28 -0400 Subject: [PATCH 2/3] Review changes for enable/disable scripting --- src/core/CMakeLists.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 7226d1bce..afeb8d5e0 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1,4 +1,4 @@ -set(core_sources +add_library(core STATIC 3ds.h announce_multiplayer_session.cpp announce_multiplayer_session.h @@ -419,7 +419,7 @@ set(core_sources tracer/recorder.h ) if (ENABLE_SCRIPTING) - list(APPEND core_sources + target_sources(core PRIVATE rpc/packet.cpp rpc/packet.h rpc/rpc_server.cpp @@ -430,7 +430,6 @@ if (ENABLE_SCRIPTING) rpc/zmq_server.h ) endif() -add_library(core STATIC ${core_sources}) create_target_directory_groups(core) From 86ea9d3b1b62c7eb126ced7c2263a4fa71788e40 Mon Sep 17 00:00:00 2001 From: EverOddish Date: Tue, 25 Sep 2018 21:13:02 -0400 Subject: [PATCH 3/3] Adding description to CMake option --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dee71e5e3..603824f6b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,7 @@ option(ENABLE_CUBEB "Enables the cubeb audio backend" ON) option(USE_DISCORD_PRESENCE "Enables Discord Rich Presence" OFF) -option(ENABLE_SCRIPTING ON) +option(ENABLE_SCRIPTING "Enables scripting support" ON) if(NOT EXISTS ${CMAKE_SOURCE_DIR}/.git/hooks/pre-commit) message(STATUS "Copying pre-commit hook")