| 1 |
# This module can be used in two different ways. |
| 2 |
# |
| 3 |
# When invoked as `cmake -P DolphinPostprocessBundle.cmake`, it fixes up an |
| 4 |
# application folder to be standalone. It bundles all required libraries from |
| 5 |
# the system and fixes up library IDs. Any additional shared libraries, like |
| 6 |
# plugins, that are found under Contents/MacOS/ will be made standalone as well. |
| 7 |
# |
| 8 |
# When called with `include(DolphinPostprocessBundle)`, it defines a helper |
| 9 |
# function `dolphin_postprocess_bundle` that sets up the command form of the |
| 10 |
# module as a post-build step. |
| 11 |
|
| 12 |
if(CMAKE_GENERATOR) |
| 13 |
# Being called as include(DolphinPostprocessBundle), so define a helper function. |
| 14 |
set(_DOLPHIN_POSTPROCESS_BUNDLE_MODULE_LOCATION "${CMAKE_CURRENT_LIST_FILE}") |
| 15 |
function(dolphin_postprocess_bundle target) |
| 16 |
add_custom_command(TARGET ${target} POST_BUILD |
| 17 |
COMMAND ${CMAKE_COMMAND} "-D" "DOLPHIN_BUNDLE_PATH=$<TARGET_BUNDLE_DIR:${target}>" |
| 18 |
-P "${_DOLPHIN_POSTPROCESS_BUNDLE_MODULE_LOCATION}" |
| 19 |
) |
| 20 |
endfunction() |
| 21 |
return() |
| 22 |
endif() |
| 23 |
|
| 24 |
message(STATUS "Fixing up application bundle: ${DOLPHIN_BUNDLE_PATH}") |
| 25 |
|
| 26 |
# Make sure to fix up any additional shared libraries (like plugins) that are |
| 27 |
# needed. |
| 28 |
file(GLOB_RECURSE extra_libs "${DOLPHIN_BUNDLE_PATH}/Contents/MacOS/*.dylib") |
| 29 |
|
| 30 |
# BundleUtilities doesn't support DYLD_FALLBACK_LIBRARY_PATH behavior, which |
| 31 |
# makes it sometimes break on libraries that do weird things with @rpath. Specify |
| 32 |
# equivalent search directories until https://gitlab.kitware.com/cmake/cmake/issues/16625 |
| 33 |
# is fixed and in our minimum CMake version. |
| 34 |
set(extra_dirs "/usr/local/lib" "/lib" "/usr/lib") |
| 35 |
|
| 36 |
# BundleUtilities is overly verbose, so disable most of its messages |
| 37 |
function(message) |
| 38 |
if(NOT ARGV MATCHES "^STATUS;") |
| 39 |
_message(${ARGV}) |
| 40 |
endif() |
| 41 |
endfunction() |
| 42 |
|
| 43 |
include(BundleUtilities) |
| 44 |
set(BU_CHMOD_BUNDLE_ITEMS ON) |
| 45 |
fixup_bundle("${DOLPHIN_BUNDLE_PATH}" "${extra_libs}" "${extra_dirs}") |