cmake: avoid de-duplication of user's CXXFLAGS
[quassel.git] / cmake / FinalizeBundle.cmake.in
1 include(BundleUtilities)
2
3 # After the relevant targets, support files, as well as plugins have already been installed into the bundle structure,
4 # the bundle must still be made standalone by copying the required frameworks and making them position-independent.
5 # This is generally called "fixing up" the bundle.
6 #
7 # Principally there are two ways to do that: Qt's official macdeployqt tool, and CMake's BundleUtilities.
8 #
9 # Some frameworks, in particular QtWebEngineCore, come with nested bundles. In order for them to work correctly, the Frameworks directory
10 # from the main bundle must be symlinked into the nested bundle, otherwise dependencies cannot be resolved.
11 # Neither macdeployqt (shockingly) nor BundleUtilities can handle this properly. The former simply ignores nested bundles and thus
12 # does not fix them up at all. The latter scans for additional binaries and tries fixing them up, but there is no way to inject
13 # creation of the Frameworks symlink between the copy and the fixup steps.
14 #
15 # The working solution implemented here is to first run macdeployqt (which also handles some Qt-specific quirks), then symlink Frameworks
16 # into the nested bundles (if any), then use BundleUtilities to perform the remaining fixups and verify the bundle.
17
18 # Since we're in the install phase, DESTDIR might be set
19 set(BUNDLE_PATH "$ENV{DESTDIR}@BUNDLE_PATH@")
20 set(DMG_PATH    "$ENV{DESTDIR}@DMG_PATH@")
21
22 # First, use Qt's official tool, macdeployqt, for deploying the needed Qt Frameworks into the bundle
23 message(STATUS "Deploying Qt Frameworks in bundle \"${BUNDLE_PATH}\"")
24 execute_process(
25     # Don't deploy plugins - we've already installed the selection relevant for our target!
26     COMMAND @MACDEPLOYQT_EXECUTABLE@ "${BUNDLE_PATH}" -verbose=1 -no-plugins
27     RESULT_VARIABLE result
28 )
29 if(NOT result EQUAL 0)
30     message(FATAL_ERROR "Deploying Qt Frameworks failed.")
31 endif()
32
33 # Scan for nested bundles and symlink the main bundle's Frameworks directory into them
34 message(STATUS "Checking for nested bundles")
35 execute_process(
36     COMMAND find "${BUNDLE_PATH}" -mindepth 1 -type d -name "*.app"
37     OUTPUT_VARIABLE nested_bundles
38     OUTPUT_STRIP_TRAILING_WHITESPACE
39 )
40 if(nested_bundles)
41     string(REPLACE "\n" ";" nested_bundles ${nested_bundles})
42     foreach(nested_bundle IN LISTS nested_bundles)
43         message(STATUS "Symlinking Frameworks into nested bundle \"${nested_bundle}\"")
44         file(RELATIVE_PATH path "${nested_bundle}/Contents" "${BUNDLE_PATH}/Contents/Frameworks")
45         execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${path}" "${nested_bundle}/Contents/Frameworks")
46     endforeach()
47 else()
48     message("Checking for nested bundles - none found")
49 endif()
50
51 # Now fixup the whole thing using CMake's own tooling, which (unlike macdeployqt) will take care of any additional internal executables
52 message(STATUS "Fixing up bundle...")
53 fixup_bundle("${BUNDLE_PATH}" "" "")
54
55 # Create the DMG image
56 message(STATUS "Creating DMG image...")
57 execute_process(
58     COMMAND hdiutil create "${DMG_PATH}" -srcfolder "${BUNDLE_PATH}" -format "UDBZ" -fs "HFS+" -volname "Quassel IRC"
59     RESULT_VARIABLE result
60 )
61 if(NOT result EQUAL 0)
62     message(FATAL_ERROR "Creating DMG image failed.")
63 endif()