From f0692b162c27cdf11629b19be0e1f6c20d4f6dc4 Mon Sep 17 00:00:00 2001
From: Chip Collier <[EMAIL REDACTED]>
Date: Wed, 28 May 2025 20:26:01 +0200
Subject: [PATCH] Add the @loader_path rpath to MacOS libraries (#142)
When using this in projects where the executable can't or doesn't set
the @executable_path rpath (dotnet), this should still allow shadercross
to find the other libraries it depends on.
---
CMakeLists.txt | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ad55bcf..8b754f2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -532,6 +532,7 @@ if(SDLSHADERCROSS_INSTALL_RUNTIME)
find_program(PATCHELF_BIN NAMES "patchelf" REQUIRED)
install(CODE "file(GLOB so_paths \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/*so*\")\n foreach(so_path \${so_paths})\n if(NOT IS_SYMLINK \${so_path})\n message(STATUS \"Adding \\\"\$ORIGIN\\\" to RPATH of \${so_path}\")\n execute_process(COMMAND ${PATCHELF_BIN} \"\${so_path}\" --add-rpath \"\$ORIGIN\")\n endif()\n endforeach()")
elseif(APPLE)
- # FIXME: Apple probably needs to do something similar as Linux, but using otool
+ find_program(INT_BIN NAMES "install_name_tool" REQUIRED)
+ install(CODE "file(GLOB so_paths \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/*dylib*\")\n foreach(so_path \${so_paths})\n if(NOT IS_SYMLINK \${so_path})\n message(STATUS \"Adding \\\"\@loader_path\\\" to RPATH of \${so_path}\")\n execute_process(COMMAND ${INT_BIN} \"\${so_path}\" -add_rpath \"\@loader_path\")\n endif()\n endforeach()")
endif()
endif()