From 13f94f113a75bf632db681e6030fe4edb0a2a8c7 Mon Sep 17 00:00:00 2001 From: Vithorio Polten Date: Fri, 21 Jun 2024 16:38:52 -0300 Subject: [PATCH] fix(macos): fix boost on macos (#2733) Co-authored-by: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> --- cmake/compile_definitions/common.cmake | 2 +- cmake/prep/options.cmake | 6 +++++- packaging/macos/Portfile | 3 ++- packaging/sunshine.rb | 25 +++++++++++++++++++++++++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/cmake/compile_definitions/common.cmake b/cmake/compile_definitions/common.cmake index fe31f290..e7436825 100644 --- a/cmake/compile_definitions/common.cmake +++ b/cmake/compile_definitions/common.cmake @@ -125,8 +125,8 @@ include_directories( "${CMAKE_SOURCE_DIR}/third-party/moonlight-common-c/enet/include" "${CMAKE_SOURCE_DIR}/third-party/nanors" "${CMAKE_SOURCE_DIR}/third-party/nanors/deps/obl" - ${Boost_INCLUDE_DIRS} ${FFMPEG_INCLUDE_DIRS} + ${Boost_INCLUDE_DIRS} # has to be the last, or we get runtime error on macOS ffmpeg encoder ) list(APPEND SUNSHINE_EXTERNAL_LIBRARIES diff --git a/cmake/prep/options.cmake b/cmake/prep/options.cmake index c659e2f9..8772d6d2 100644 --- a/cmake/prep/options.cmake +++ b/cmake/prep/options.cmake @@ -15,7 +15,11 @@ option(SUNSHINE_REQUIRE_TRAY "Require system tray icon. Fail the build if tray r option(SUNSHINE_SYSTEM_WAYLAND_PROTOCOLS "Use system installation of wayland-protocols rather than the submodule." OFF) -option(BOOST_USE_STATIC "Use static boost libraries." ON) +if(APPLE) + option(BOOST_USE_STATIC "Use static boost libraries." OFF) +else() + option(BOOST_USE_STATIC "Use static boost libraries." ON) +endif() option(CUDA_INHERIT_COMPILE_OPTIONS "When building CUDA code, inherit compile options from the the main project. You may want to disable this if diff --git a/packaging/macos/Portfile b/packaging/macos/Portfile index e47fc77d..81526b1f 100644 --- a/packaging/macos/Portfile +++ b/packaging/macos/Portfile @@ -44,7 +44,8 @@ depends_lib port:avahi \ depends_test port:doxygen \ port:graphviz -configure.args -DBUILD_WERROR=ON \ +configure.args -DBOOST_USE_STATIC=ON \ + -DBUILD_WERROR=ON \ -DCMAKE_INSTALL_PREFIX=${prefix} \ -DSUNSHINE_ASSETS_DIR=etc/sunshine/assets diff --git a/packaging/sunshine.rb b/packaging/sunshine.rb index 282b4e69..a634931e 100644 --- a/packaging/sunshine.rb +++ b/packaging/sunshine.rb @@ -21,6 +21,9 @@ class @PROJECT_NAME@ < Formula end end + option "without-dynamic-boost", "Statically link Boost libraries" # default option + option "with-dynamic-boost", "Dynamically link Boost libraries" + depends_on "cmake" => :build depends_on "node" => :build depends_on "pkg-config" => :build @@ -28,6 +31,7 @@ class @PROJECT_NAME@ < Formula depends_on "miniupnpc" depends_on "openssl" depends_on "opus" + depends_on "icu4c" => :recommended on_linux do depends_on "libcap" @@ -64,6 +68,27 @@ class @PROJECT_NAME@ < Formula -DSUNSHINE_ENABLE_TRAY=OFF -DTESTS_ENABLE_PYTHON_TESTS=OFF ] + + if build.without? "dynamic-boost" + args << "-DBOOST_USE_STATIC=ON" + ohai "Statically linking Boost libraries" + + unless Formula["icu4c"].any_version_installed? + odie <<~EOS + icu4c must be installed to link against static Boost libraries, + either install icu4c or use brew install sunshine --with-dynamic-boost instead + EOS + end + ENV.append "CXXFLAGS", "-I#{Formula["icu4c"].opt_include}" + icu4c_lib_path = Formula["icu4c"].opt_lib.to_s + ENV.append "LDFLAGS", "-L#{icu4c_lib_path}" + ENV["LIBRARY_PATH"] = icu4c_lib_path + ohai "Linking against ICU libraries at: #{icu4c_lib_path}" + else + args << "-DBOOST_USE_STATIC=OFF" + ohai "Dynamically linking Boost libraries" + end + system "cmake", "-S", ".", "-B", "build", *std_cmake_args, *args cd "build" do