summaryrefslogtreecommitdiffstats
path: root/mkspecs/features/ios/qt.prf
blob: f89cb0c287a26b6860154b094c16c95dc0bd9684 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

equals(TEMPLATE, app):contains(QT, gui(-private)?) {
    LIBS *= -L$$[QT_INSTALL_PLUGINS/get]/platforms

    lib_name = qios
    lib_path_and_base = $$[QT_INSTALL_PLUGINS/get]/platforms/lib$${lib_name}$$qtPlatformTargetSuffix()
    LIBS += -l$${lib_name}$$qtPlatformTargetSuffix() $$fromfile($${lib_path_and_base}.prl, QMAKE_PRL_LIBS)

    # By marking qt_registerPlatformPlugin as undefined, we ensure that
    # the plugin.o translation unit is considered for inclusion in
    # the final binary, which in turn ensures that the plugin's
    # static initializer is included and run.
    QMAKE_LFLAGS += -u _qt_registerPlatformPlugin

    # We do link and dependency resolution for the platform plugin
    # manually, since we know we always need the plugin, so we don't
    # need to generate an import for it.
    CONFIG -= import_qpa_plugin

    !no_main_wrapper {
        # Instead of messing with the user's main function we go the other
        # way and change the application entry point to call our main wrapper.
        # This entry point is the 'start' symbol, provided by crt1.o, so we
        # make a copy of the file and rename the '_main' unresolved symbol
        # to our wrapper function, '_qtmn', injecting ourselves into the app
        # startup. Once Apple starts shipping the LLVM linker (lld) we may
        # get rid of this step completely and just pass -e _qtmn to the
        # linker, taking advantage of the new LC_MAIN load command.

        # We use xcodebuild to resolve the location of the crt1 object file
        # as we know that it lives in the same location as the c library.
        c_library_path = $$system("/usr/bin/xcodebuild -sdk $$QMAKE_MAC_SDK -find-library c 2>/dev/null")

        # We also know that iOS 3.1 and up uses crt1.3.1.o (technically not
        # true for simulator, but the SDK has a symlink to the correct file).
        original_crt_path = $$dirname(c_library_path)/crt1.3.1.o

        xcode_objects_path = "$(OBJECT_FILE_DIR_$(CURRENT_VARIANT))/$(CURRENT_ARCH)"
        custom_crt_filename = "crt1_qt.o"
        custom_crt_path = "$$xcode_objects_path/$$custom_crt_filename"

        EOC = $$escape_expand(\\n\\t)
        create_custom_crt.commands = \
            # Copy original crt1 to build directory
            "$$QMAKE_COPY_FILE $$original_crt_path $$custom_crt_path $$EOC" \
            # And rename all occurrences of _main to _qtmn
            "strings -t d - $${custom_crt_path}" \
                "| sed -n 's/^\\([0-9]\\{1,\\}\\) _main\$\$/\1/p'" \
                "| while read offset; do" \
                    "printf '_qtmn'" \
                        "| dd of=$${custom_crt_path} bs=1 seek=\$\$offset conv=notrunc >/dev/null 2>&1" \
                "; done"
        create_custom_crt.depends = $$original_crt_path
        create_custom_crt.target = $$custom_crt_path
        preprocess.depends = create_custom_crt
        QMAKE_EXTRA_TARGETS += create_custom_crt preprocess

        clean_custom_crt.commands = "$$QMAKE_DEL_FILE $$custom_crt_path"
        preprocess_clean.depends += clean_custom_crt
        QMAKE_EXTRA_TARGETS += clean_custom_crt preprocess_clean

        # Prevent usage of new LC_MAIN load command, which skips start/crt1
        # and calls main from the loader. We rely on injecting into start.
        QMAKE_LFLAGS += -Wl,-no_new_main

        # Explicitly link against our modified crt1 object
        QMAKE_LFLAGS += -nostartfiles -l$${custom_crt_filename}

        # Workaround for QMAKE_PBX_LIBPATHS mangling the Xcode variables
        lib_search_path.name = LIBRARY_SEARCH_PATHS
        lib_search_path.value = $$xcode_objects_path
        QMAKE_MAC_XCODE_SETTINGS += lib_search_path
    }
}

load(qt)