After much searching and banging my head against the wall for days, I am still at a loss. I have looked into BundleUtilities
and I have made progress, but still having issues.
What I have now is a cmake script to invoke BundleUtilities
like this:
separate_arguments(libs UNIX_COMMAND ${ARG_LIBS})
include(BundleUtilities)
get_bundle_and_executable(${ARG_EXECUTABLE} bundle executable valid)
if(valid)
set(FRAMEWORK_PATH "${bundle}/Contents/Frameworks")
foreach (lib IN LISTS libs)
cmake_path(GET lib FILENAME filename)
set(bundle_lib "${FRAMEWORK_PATH}/${filename}")
# file(COPY "${lib}" DESTINATION "${FRAMEWORK_PATH}")
copy_resolved_item_into_bundle("${lib}" "${bundle_lib}")
list(APPEND bundle_libs "${bundle_lib}")
endforeach ()
fixup_bundle(${bundle} "${bundle_libs}" "")
endif()
The script gets invoked like this:
add_custom_target(post_process
COMMAND ${CMAKE_COMMAND} -DARG_EXECUTABLE="$<TARGET_FILE:${target}>" -DARG_LIBS="${google_angle_libs}" -P "${CMAKE_SOURCE_DIR}/cmake/MacOSCopyDynamicLibraries.cmake"
DEPENDS ${target})
This generates the bundle (.app) with the proper format with the 2 libraries under test_raylib.app/Contents/Framework
If I comment out the fixup_bundle
line, the executable (test_raylib.app/Contents/MacOS/test_raylib
) is like this:
> otool -L test_raylib
test_raylib:
... truncated
./libEGL.dylib (compatibility version 0.0.0, current version 0.0.0)
./libGLESv2.dylib (compatibility version 0.0.0, current version 0.0.0)
... truncated
And of course that does not work, because it cannot find the libraries:
Library not loaded: */libEGL.dylib
Referenced from: <7E771F4F-2129-32E9-8EB6-1EABC34E6ECA> /Volumes/VOLUME/*/test_raylib.app/Contents/MacOS/test_raylib
Reason: tried: '*/libEGL.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS*/libEGL.dylib' (no such file), '*/libEGL.dylib' (no such file), '/usr/local/lib/libEGL.dylib' (no such file), '/usr/lib/libEGL.dylib' (no such file, not in dyld cache), '//libEGL.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS//libEGL.dylib' (no such file), '//libEGL.dylib' (no such file), '/usr/local/lib/libEGL.dylib' (no such file), '/usr/lib/libEGL.dylib' (no such file, not in dyld cache)
(terminated at launch; ignore backtrace)
If I restore the fixup_bundle
line, then the executable seems to be properly “fixed” as in, now the path is correct:
> otool -L test_raylib
test_raylib:
... truncated
@executable_path/../Frameworks/libEGL.dylib (compatibility version 0.0.0, current version 0.0.0)
@executable_path/../Frameworks/libGLESv2.dylib (compatibility version 0.0.0, current version 0.0.0)
... truncated
But when I run it fails again, this time with a different message:
Exception Type: EXC_BAD_ACCESS (SIGKILL (Code Signature Invalid))
Note that I never run any kind of code signature at all.
Any idea what I can do to fix this issue. I didn’t think it was going to be this hard to add an external dylib to my project!