From fc20732eaadd5f72a68db4129e0efdf1e2e15940 Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Sun, 23 May 2021 00:37:12 -0400
Subject: [PATCH] Add support for Alchemy dullahan on macos

---
 indra/cmake/CEFPlugin.cmake                |   6 --
 indra/cmake/LLSharedLibs.cmake             |   8 --
 indra/cmake/Variables.cmake                |   1 +
 indra/media_plugins/cef/CMakeLists.txt     |  11 ---
 indra/media_plugins/example/CMakeLists.txt |   2 -
 indra/media_plugins/libvlc/CMakeLists.txt  |   2 -
 indra/newview/viewer_manifest.py           | 102 ++-------------------
 7 files changed, 10 insertions(+), 122 deletions(-)

diff --git a/indra/cmake/CEFPlugin.cmake b/indra/cmake/CEFPlugin.cmake
index b8e569d3a84..26394127943 100644
--- a/indra/cmake/CEFPlugin.cmake
+++ b/indra/cmake/CEFPlugin.cmake
@@ -24,16 +24,10 @@ elseif (DARWIN)
         message(FATAL_ERROR "AppKit not found")
     endif()
 
-    FIND_LIBRARY(CEF_LIBRARY "Chromium Embedded Framework" ${ARCH_PREBUILT_DIRS_RELEASE})
-    if (NOT CEF_LIBRARY)
-        message(FATAL_ERROR "CEF not found")
-    endif()
-
     set(CEF_PLUGIN_LIBRARIES
         ${ARCH_PREBUILT_DIRS_RELEASE}/libcef_dll_wrapper.a
         ${ARCH_PREBUILT_DIRS_RELEASE}/libdullahan.a
         ${APPKIT_LIBRARY}
-        ${CEF_LIBRARY}
        )
 
 elseif (LINUX)
diff --git a/indra/cmake/LLSharedLibs.cmake b/indra/cmake/LLSharedLibs.cmake
index da9d389a607..56412f81228 100644
--- a/indra/cmake/LLSharedLibs.cmake
+++ b/indra/cmake/LLSharedLibs.cmake
@@ -72,12 +72,4 @@ macro(ll_stage_sharedlib DSO_TARGET)
           COMMENT "Copying llcommon to the staging folder."
         )
     endif(NOT WINDOWS)
-
-  if (DARWIN)
-    set_target_properties(${DSO_TARGET} PROPERTIES
-      BUILD_WITH_INSTALL_NAME_DIR 1
-      INSTALL_NAME_DIR "@executable_path/../Frameworks"
-      )
-  endif(DARWIN)
-
 endmacro(ll_stage_sharedlib)
diff --git a/indra/cmake/Variables.cmake b/indra/cmake/Variables.cmake
index 3475c8f6864..8c3e1679892 100644
--- a/indra/cmake/Variables.cmake
+++ b/indra/cmake/Variables.cmake
@@ -150,6 +150,7 @@ endif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
 
 if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
   set(DARWIN 1)
+  set(CMAKE_MACOSX_RPATH TRUE)
 
   # Xcode setup
   if (XCODE_VERSION LESS 12.0.0)
diff --git a/indra/media_plugins/cef/CMakeLists.txt b/indra/media_plugins/cef/CMakeLists.txt
index a632055c38a..58d17e9d65d 100644
--- a/indra/media_plugins/cef/CMakeLists.txt
+++ b/indra/media_plugins/cef/CMakeLists.txt
@@ -96,20 +96,9 @@ if (DARWIN)
     media_plugin_cef
     PROPERTIES
     PREFIX ""
-    BUILD_WITH_INSTALL_NAME_DIR 1
-    INSTALL_NAME_DIR "@executable_path"
     LINK_FLAGS "-exported_symbols_list ${CMAKE_CURRENT_SOURCE_DIR}/../base/media_plugin_base.exp"
   )
 
   ## turns on C++11 using Cmake
   target_compile_features(media_plugin_cef PRIVATE cxx_range_for)
-
-  add_custom_command(TARGET media_plugin_cef
-    POST_BUILD COMMAND ${CMAKE_INSTALL_NAME_TOOL} -change "@executable_path/Chromium Embedded Framework"
-        "@executable_path/../../../../Frameworks/Chromium Embedded Framework.framework/Chromium Embedded Framework"
-        "$<TARGET_FILE:media_plugin_cef>"
-    VERBATIM
-    COMMENT "Fixing path to CEF Framework"
-  )
-
 endif (DARWIN)
diff --git a/indra/media_plugins/example/CMakeLists.txt b/indra/media_plugins/example/CMakeLists.txt
index fb1ee65c44b..a215381041f 100644
--- a/indra/media_plugins/example/CMakeLists.txt
+++ b/indra/media_plugins/example/CMakeLists.txt
@@ -65,8 +65,6 @@ if (DARWIN)
     media_plugin_example
     PROPERTIES
     PREFIX ""
-    BUILD_WITH_INSTALL_NAME_DIR 1
-    INSTALL_NAME_DIR "@executable_path"
     LINK_FLAGS "-exported_symbols_list ${CMAKE_CURRENT_SOURCE_DIR}/../base/media_plugin_base.exp"
   )
 
diff --git a/indra/media_plugins/libvlc/CMakeLists.txt b/indra/media_plugins/libvlc/CMakeLists.txt
index baa242f814f..0eb91ea5e91 100644
--- a/indra/media_plugins/libvlc/CMakeLists.txt
+++ b/indra/media_plugins/libvlc/CMakeLists.txt
@@ -66,8 +66,6 @@ if (DARWIN)
     media_plugin_libvlc
     PROPERTIES
     PREFIX ""
-    BUILD_WITH_INSTALL_NAME_DIR 1
-    INSTALL_NAME_DIR "@executable_path"
     LINK_FLAGS "-exported_symbols_list ${CMAKE_CURRENT_SOURCE_DIR}/../base/media_plugin_base.exp"
   )
 
diff --git a/indra/newview/viewer_manifest.py b/indra/newview/viewer_manifest.py
index 36a29422195..124e9f86957 100755
--- a/indra/newview/viewer_manifest.py
+++ b/indra/newview/viewer_manifest.py
@@ -894,10 +894,6 @@ def construct(self):
             # CEF framework goes inside Contents/Frameworks.
             # Remember where we parked this car.
             with self.prefix(src=libdir, dst="Frameworks"):
-                CEF_framework = "Chromium Embedded Framework.framework"
-                self.path2basename(libdir, CEF_framework)
-                CEF_framework = self.dst_path_of(CEF_framework)
-
                 for libfile in (
                                 'libapr-1.*.dylib',
                                 'libaprutil-1.*.dylib',
@@ -1056,102 +1052,22 @@ def construct(self):
                             self.relsymlinkf(os.path.join(libfile_parent, libfile))
 
                 # Dullahan helper apps go inside SLPlugin.app
-                with self.prefix(dst=os.path.join(
+                with self.prefix(src=os.path.join(pkgdir, 'bin', 'release'), dst=os.path.join(
                     "SLPlugin.app", "Contents", "Frameworks")):
+                    self.path("Chromium Embedded Framework.framework")
+                    self.path("DullahanHost.app")
+                    self.path("DullahanHost (GPU).app")
+                    self.path("DullahanHost (Renderer).app")
+                    self.path("DullahanHost (Plugin).app")
 
-                    frameworkname = 'Chromium Embedded Framework'
-
-                    # This code constructs a relative symlink from the
-                    # target framework folder back to the real CEF framework.
-                    # It needs to be relative so that the symlink still works when
-                    # (as is normal) the user moves the app bundle out of the DMG
-                    # and into the /Applications folder. Note we pass catch=False,
-                    # letting the uncaught exception terminate the process, since
-                    # without this symlink, Second Life web media can't possibly work.
-
-                    # It might seem simpler just to symlink Frameworks back to
-                    # the parent of Chromimum Embedded Framework.framework. But
-                    # that would create a symlink cycle, which breaks our
-                    # packaging step. So make a symlink from Chromium Embedded
-                    # Framework.framework to the directory of the same name, which
-                    # is NOT an ancestor of the symlink.
-
-                    # from SLPlugin.app/Contents/Frameworks/Chromium Embedded
-                    # Framework.framework back to
-                    # $viewer_app/Contents/Frameworks/Chromium Embedded Framework.framework
-                    SLPlugin_framework = self.relsymlinkf(CEF_framework, catch=False)
-
-                    # for all the multiple CEF/Dullahan (as of CEF 76) helper app bundles we need:
-                    for helper in (
-                        "DullahanHelper",
-                        "DullahanHelper (GPU)",
-                        "DullahanHelper (Renderer)",
-                        "DullahanHelper (Plugin)",
-                    ):
-                        # app is the directory name of the app bundle, with app/Contents/MacOS/helper as the executable
-                        app = helper + ".app"
-
-                        # copy DullahanHelper.app
-                        self.path2basename(relpkgdir, app)
-
-                        # and fix that up with a Frameworks/CEF symlink too
-                        with self.prefix(dst=os.path.join(
-                                app, 'Contents', 'Frameworks')):
-                            # from Dullahan Helper *.app/Contents/Frameworks/Chromium Embedded
-                            # Framework.framework back to
-                            # SLPlugin.app/Contents/Frameworks/Chromium Embedded Framework.framework
-                            # Since SLPlugin_framework is itself a
-                            # symlink, don't let relsymlinkf() resolve --
-                            # explicitly call relpath(symlink=True) and
-                            # create that symlink here.
-                            helper_framework = \
-                            self.symlinkf(self.relpath(SLPlugin_framework, symlink=True), catch=False)
-
-                        # change_command includes install_name_tool, the
-                        # -change subcommand and the old framework rpath
-                        # stamped into the executable. To use it with
-                        # run_command(), we must still append the new
-                        # framework path and the pathname of the
-                        # executable to change.
-                        change_command = [
-                            'install_name_tool', '-change',
-                            '@rpath/Frameworks/Chromium Embedded Framework.framework/Chromium Embedded Framework']
-
-                        with self.prefix(dst=os.path.join(
-                                app, 'Contents', 'MacOS')):
-                            # Now self.get_dst_prefix() is, at runtime,
-                            # @executable_path. Locate the helper app
-                            # framework (which is a symlink) from here.
-                            newpath = os.path.join(
-                                '@executable_path',
-                                    self.relpath(helper_framework, symlink=True),
-                                frameworkname)
-                                # and restamp the Dullahan Helper executable itself
-                            self.run_command(
-                                change_command +
-                                    [newpath, self.dst_path_of(helper)])
 
                 # SLPlugin plugins
                 with self.prefix(dst="llplugin"):
-                    dylibexecutable = 'media_plugin_cef.dylib'
+                    # copy CEF plugin
                     self.path2basename("../media_plugins/cef/" + self.args['configuration'],
-                                       dylibexecutable)
-
-                    # Do this install_name_tool *after* media plugin is copied over.
-                    # Locate the framework lib executable -- relative to
-                    # SLPlugin.app/Contents/MacOS, which will be our
-                    # @executable_path at runtime!
-                    newpath = os.path.join(
-                        '@executable_path',
-                        self.relpath(SLPlugin_framework, executable_path["SLPlugin.app"],
-                                     symlink=True),
-                        frameworkname)
-                    # restamp media_plugin_cef.dylib
-                    self.run_command(
-                        change_command +
-                        [newpath, self.dst_path_of(dylibexecutable)])
+                                       "media_plugin_cef.dylib")
 
-                    # copy LibVLC plugin itself
+                    # copy LibVLC plugin
                     self.path2basename("../media_plugins/libvlc/" + self.args['configuration'],
                                        "media_plugin_libvlc.dylib")
 
-- 
GitLab