From 2516960097703e620ed72ddf2201402a3d3f003d Mon Sep 17 00:00:00 2001 From: Vithorio Polten Date: Thu, 2 May 2024 13:50:27 -0300 Subject: [PATCH] build: nlohmann for all targets (copied from #2032) Mostly copied code from #2032 to try a PoC for the API I want to use --- .github/workflows/CI.yml | 1 - .gitmodules | 3 +++ cmake/compile_definitions/common.cmake | 2 ++ cmake/compile_definitions/macos.cmake | 1 + cmake/compile_definitions/windows.cmake | 1 - cmake/dependencies/common.cmake | 9 +++++++++ cmake/dependencies/windows.cmake | 5 +---- cmake/prep/options.cmake | 1 + docs/source/building/windows.rst | 1 - docs/source/source_code/source_code.rst | 7 +++++++ src/confighttp.cpp | 2 ++ src/display_device/dd.h | 22 ++++++++++++++++++++++ third-party/nlohmann_json | 1 + 13 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 src/display_device/dd.h create mode 160000 third-party/nlohmann_json diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index ecc18a73d43..3eaf00a5ee8 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -1008,7 +1008,6 @@ jobs: mingw-w64-x86_64-curl mingw-w64-x86_64-graphviz mingw-w64-x86_64-miniupnpc - mingw-w64-x86_64-nlohmann-json mingw-w64-x86_64-nodejs mingw-w64-x86_64-nsis mingw-w64-x86_64-onevpl diff --git a/.gitmodules b/.gitmodules index 4efc01425bd..e296d4169ac 100644 --- a/.gitmodules +++ b/.gitmodules @@ -54,3 +54,6 @@ path = third-party/wlr-protocols url = https://gitlab.freedesktop.org/wlroots/wlr-protocols branch = master +[submodule "third-party/nlohmann_json"] + path = third-party/nlohmann_json + url = https://github.com/nlohmann/json diff --git a/cmake/compile_definitions/common.cmake b/cmake/compile_definitions/common.cmake index 6e038295847..6a6db564195 100644 --- a/cmake/compile_definitions/common.cmake +++ b/cmake/compile_definitions/common.cmake @@ -56,6 +56,7 @@ set(SUNSHINE_TARGET_FILES "${CMAKE_SOURCE_DIR}/third-party/moonlight-common-c/src/RtspParser.c" "${CMAKE_SOURCE_DIR}/third-party/moonlight-common-c/src/Video.h" "${CMAKE_SOURCE_DIR}/third-party/tray/tray.h" + "${CMAKE_SOURCE_DIR}/src/display_device/dd.h" "${CMAKE_SOURCE_DIR}/src/upnp.cpp" "${CMAKE_SOURCE_DIR}/src/upnp.h" "${CMAKE_SOURCE_DIR}/src/cbs.cpp" @@ -138,4 +139,5 @@ list(APPEND SUNSHINE_EXTERNAL_LIBRARIES ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${CURL_LIBRARIES} + ${JSON_LIBRARIES} ${PLATFORM_LIBRARIES}) diff --git a/cmake/compile_definitions/macos.cmake b/cmake/compile_definitions/macos.cmake index 549ea1d0f1e..1f1f690cd6f 100644 --- a/cmake/compile_definitions/macos.cmake +++ b/cmake/compile_definitions/macos.cmake @@ -31,6 +31,7 @@ set(PLATFORM_TARGET_FILES "${CMAKE_SOURCE_DIR}/src/platform/macos/av_video.h" "${CMAKE_SOURCE_DIR}/src/platform/macos/av_video.m" "${CMAKE_SOURCE_DIR}/src/platform/macos/display.mm" + "${CMAKE_SOURCE_DIR}/src/platform/macos/display_options.mm" "${CMAKE_SOURCE_DIR}/src/platform/macos/input.cpp" "${CMAKE_SOURCE_DIR}/src/platform/macos/microphone.mm" "${CMAKE_SOURCE_DIR}/src/platform/macos/misc.mm" diff --git a/cmake/compile_definitions/windows.cmake b/cmake/compile_definitions/windows.cmake index 26e89a20b82..1fd4465985c 100644 --- a/cmake/compile_definitions/windows.cmake +++ b/cmake/compile_definitions/windows.cmake @@ -74,7 +74,6 @@ list(PREPEND PLATFORM_LIBRARIES avrt iphlpapi shlwapi - PkgConfig::NLOHMANN_JSON ${CURL_STATIC_LIBRARIES}) if(SUNSHINE_ENABLE_TRAY) diff --git a/cmake/dependencies/common.cmake b/cmake/dependencies/common.cmake index 29bed10e5cd..499123bc4c5 100644 --- a/cmake/dependencies/common.cmake +++ b/cmake/dependencies/common.cmake @@ -19,6 +19,15 @@ pkg_check_modules(CURL REQUIRED libcurl) pkg_check_modules(MINIUPNP miniupnpc REQUIRED) include_directories(SYSTEM ${MINIUPNP_INCLUDE_DIRS}) +# nlohmann_json +if(SUNSHINE_SYSTEM_NLOHMANN_JSON) + pkg_check_modules(NLOHMANN_JSON nlohmann_json>=3.9.0 REQUIRED IMPORTED_TARGET) + set(JSON_LIBRARIES PkgConfig::NLOHMANN_JSON) +else() + add_subdirectory("${CMAKE_SOURCE_DIR}/third-party/nlohmann_json") + set(JSON_LIBRARIES nlohmann_json::nlohmann_json) +endif() + # ffmpeg pre-compiled binaries if(WIN32) if(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") diff --git a/cmake/dependencies/windows.cmake b/cmake/dependencies/windows.cmake index a7ecce3963d..01b39180008 100644 --- a/cmake/dependencies/windows.cmake +++ b/cmake/dependencies/windows.cmake @@ -1,7 +1,4 @@ # windows specific dependencies set(Boost_USE_STATIC_LIBS ON) # cmake-lint: disable=C0103 -find_package(Boost 1.71.0 COMPONENTS locale log filesystem program_options REQUIRED) - -# nlohmann_json -pkg_check_modules(NLOHMANN_JSON nlohmann_json REQUIRED IMPORTED_TARGET) +find_package(Boost 1.71.0 COMPONENTS locale log filesystem program_options REQUIRED) \ No newline at end of file diff --git a/cmake/prep/options.cmake b/cmake/prep/options.cmake index 1555036eeb0..c45a6e2ea86 100644 --- a/cmake/prep/options.cmake +++ b/cmake/prep/options.cmake @@ -13,6 +13,7 @@ option(SUNSHINE_CONFIGURE_ONLY "Configure special files only, then exit." OFF) option(SUNSHINE_ENABLE_TRAY "Enable system tray icon. This option will be ignored on macOS." ON) option(SUNSHINE_REQUIRE_TRAY "Require system tray icon. Fail the build if tray requirements are not met." ON) +option(SUNSHINE_SYSTEM_NLOHMANN_JSON "Use system installation of nlohmann_json rather than the submodule." OFF) option(SUNSHINE_SYSTEM_WAYLAND_PROTOCOLS "Use system installation of wayland-protocols rather than the submodule." OFF) option(CUDA_INHERIT_COMPILE_OPTIONS diff --git a/docs/source/building/windows.rst b/docs/source/building/windows.rst index 90b3d9e3c33..cd2038cc492 100644 --- a/docs/source/building/windows.rst +++ b/docs/source/building/windows.rst @@ -28,7 +28,6 @@ Install dependencies: mingw-w64-x86_64-curl \ mingw-w64-x86_64-graphviz \ mingw-w64-x86_64-miniupnpc \ - mingw-w64-x86_64-nlohmann-json \ mingw-w64-x86_64-nodejs \ mingw-w64-x86_64-onevpl \ mingw-w64-x86_64-openssl \ diff --git a/docs/source/source_code/source_code.rst b/docs/source/source_code/source_code.rst index fecc6801c92..4503321626e 100644 --- a/docs/source/source_code/source_code.rst +++ b/docs/source/source_code/source_code.rst @@ -62,6 +62,13 @@ Source src/* +.. toctree:: + :caption: src/display_device + :maxdepth: 1 + :glob: + + src/display_device/* + .. toctree:: :caption: src/platform :maxdepth: 1 diff --git a/src/confighttp.cpp b/src/confighttp.cpp index 486cf588722..a721eed840b 100644 --- a/src/confighttp.cpp +++ b/src/confighttp.cpp @@ -26,6 +26,8 @@ #include #include +#include + #include "config.h" #include "confighttp.h" #include "crypto.h" diff --git a/src/display_device/dd.h b/src/display_device/dd.h new file mode 100644 index 00000000000..3f71e2f3600 --- /dev/null +++ b/src/display_device/dd.h @@ -0,0 +1,22 @@ +/** + * @file src/display_device/dd.h + * @brief todo this file may not exist in the future, + * todo and we only import instead, avoiding duplication + */ + +#pragma once + +#include +#include +#include +#include +#include +#include + +// lib includes +#include + +namespace dd { + namespace options { + } +} \ No newline at end of file diff --git a/third-party/nlohmann_json b/third-party/nlohmann_json new file mode 160000 index 00000000000..8c391e04fe4 --- /dev/null +++ b/third-party/nlohmann_json @@ -0,0 +1 @@ +Subproject commit 8c391e04fe4195d8be862c97f38cfe10e2a3472e