DolphinPostprocessBundle.cmake 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. if(CMAKE_GENERATOR)
  12. # Being called as include(DolphinPostprocessBundle), so define a helper function.
  13. set(_DOLPHIN_POSTPROCESS_BUNDLE_MODULE_LOCATION "${CMAKE_CURRENT_LIST_FILE}")
  14. function(dolphin_postprocess_bundle target)
  15. add_custom_command(TARGET ${target} POST_BUILD
  16. COMMAND ${CMAKE_COMMAND} "-D" "DOLPHIN_BUNDLE_PATH=$<TARGET_BUNDLE_DIR:${target}>"
  17. -P "${_DOLPHIN_POSTPROCESS_BUNDLE_MODULE_LOCATION}"
  18. )
  19. endfunction()
  20. return()
  21. endif()
  22. message(STATUS "Fixing up application bundle: ${DOLPHIN_BUNDLE_PATH}")
  23. # Make sure to fix up any additional shared libraries (like plugins) that are
  24. # needed.
  25. file(GLOB_RECURSE extra_libs "${DOLPHIN_BUNDLE_PATH}/Contents/MacOS/*.dylib")
  26. # BundleUtilities doesn't support DYLD_FALLBACK_LIBRARY_PATH behavior, which
  27. # makes it sometimes break on libraries that do weird things with @rpath. Specify
  28. # equivalent search directories until https://gitlab.kitware.com/cmake/cmake/issues/16625
  29. # is fixed and in our minimum CMake version.
  30. set(extra_dirs "/usr/local/lib" "/lib" "/usr/lib")
  31. # BundleUtilities is overly verbose, so disable most of its messages
  32. function(message)
  33. if(NOT ARGV MATCHES "^STATUS;")
  34. _message(${ARGV})
  35. endif()
  36. endfunction()
  37. include(BundleUtilities)
  38. set(BU_CHMOD_BUNDLE_ITEMS ON)
  39. fixup_bundle("${DOLPHIN_BUNDLE_PATH}" "${extra_libs}" "${extra_dirs}")