1#!/bin/bash
2
3############################################################################
4#
5# Copyright (C) 2016 The Qt Company Ltd.
6# Contact: https://www.qt.io/licensing/
7#
8# This file is part of Qt Creator.
9#
10# Commercial License Usage
11# Licensees holding valid commercial Qt licenses may use this file in
12# accordance with the commercial license agreement provided with the
13# Software or, alternatively, in accordance with the terms contained in
14# a written agreement between you and The Qt Company. For licensing terms
15# and conditions see https://www.qt.io/terms-conditions. For further
16# information use the contact form at https://www.qt.io/contact-us.
17#
18# GNU General Public License Usage
19# Alternatively, this file may be used under the terms of the GNU
20# General Public License version 3 as published by the Free Software
21# Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
22# included in the packaging of this file. Please review the following
23# information to ensure the GNU General Public License requirements will
24# be met: https://www.gnu.org/licenses/gpl-3.0.html.
25#
26############################################################################
27
28[ $# -lt 5 ] && echo "Usage: $(basename $0) <app folder> <qt bin folder> <qt translations folder> <qt plugin folder> <qt quick 2 imports folder>" && exit 2
29[ $(uname -s) != "Darwin" ] && echo "Run this script on Mac OS X" && exit 2;
30
31app_path="$1"
32resource_path="$app_path/Contents/Resources"
33libexec_path="$app_path/Contents/Resources/libexec"
34bin_src="$2"
35translation_src="$3"
36plugin_src="$4"
37quick2_src="$5"
38
39echo "Deploying Qt"
40
41# copy qtdiag
42echo "- Copying qtdiag"
43cp "$bin_src/qtdiag" "$app_path/Contents/MacOS/" || exit 1
44# fix rpath if qtdiag was from binary Qt package
45( xcrun install_name_tool -delete_rpath "@loader_path/../lib" "$app_path/Contents/MacOS/qtdiag" &&
46  xcrun install_name_tool -add_rpath "@loader_path/../Frameworks" "$app_path/Contents/MacOS/qtdiag" ) || true
47
48
49# collect designer plugins
50designerDestDir="$app_path/Contents/PlugIns/designer"
51if [ ! -d "$designerDestDir" ]; then
52    echo "- Copying designer plugins"
53    mkdir -p "$designerDestDir"
54    for plugin in "$plugin_src"/designer/*.dylib; do
55        cp "$plugin" "$designerDestDir"/ || exit 1
56    done
57fi
58
59# collect 3d assetimporter plugins
60assetimporterDestDir="$app_path/Contents/PlugIns/assetimporters"
61assetimporterSrcDir="$plugin_src/assetimporters"
62if [ -d "$assetimporterSrcDir" ]; then
63    if [ ! -d "$assetimporterDestDir" ]; then
64        echo "- Copying 3d assetimporter plugins"
65        mkdir -p "$assetimporterDestDir"
66        find "$assetimporterSrcDir" -iname "*.dylib" -maxdepth 1 -exec cp {} "$assetimporterDestDir"/ \;
67    fi
68fi
69
70# collect tls plugins to have ssl download feature available
71tlsDestDir="$app_path/Contents/PlugIns/tls"
72tlssrcDir="$plugin_src/tls"
73if [ -d "$tlssrcDir" ]; then
74    if [ ! -d "$tlsDestDir" ]; then
75        echo "- Copying tls plugins to have ssl download feature available"
76        mkdir -p "$tlsDestDir"
77        find "$tlssrcDir" -iname "*.dylib" -maxdepth 1 -exec cp {} "$tlsDestDir"/ \;
78    fi
79fi
80
81# workaround for Qt 6.2:
82# - QTBUG-94796 macdeployqt does not deploy /Contents/PlugIns/sqldrivers/libqsqlite.dylib anymore
83sqldriversDestDir="$app_path/Contents/PlugIns/sqldrivers"
84sqldriversSrcDir="$plugin_src/sqldrivers"
85if [ -d "$sqldriversSrcDir" ]; then
86    if [ ! -d "$sqldriversDestDir" ]; then
87        echo "- Copying sqlitedriver plugin"
88        mkdir -p "$sqldriversDestDir"
89        cp "$sqldriversSrcDir/libqsqlite.dylib" "$sqldriversDestDir/libqsqlite.dylib"
90    fi
91fi
92
93# workaround for Qt 6.2:
94# - QTBUG-94796 macdeployqt does not deploy /Contents/PlugIns/imageformats/libqsvg.dylib anymore
95imageformatsDestDir="$app_path/Contents/PlugIns/imageformats"
96imageformatsSrcDir="$plugin_src/imageformats"
97if [ -d "$imageformatsSrcDir" ]; then
98    if [ ! -d "$imageformatsDestDir" ]; then
99        echo "- Copying sqlitedriver plugin"
100        mkdir -p "$imageformatsDestDir"
101        cp "$imageformatsSrcDir/libqsvg.dylib" "$imageformatsDestDir/libqsvg.dylib"
102    fi
103fi
104
105# copy Qt Quick 2 imports
106imports2Dir="$app_path/Contents/Imports/qtquick2"
107if [ -d "$quick2_src" ]; then
108    if [ ! -d "$imports2Dir" ]; then
109        echo "- Copying Qt Quick 2 imports"
110        mkdir -p "$imports2Dir"
111        cp -R "$quick2_src"/ "$imports2Dir"/
112        find "$imports2Dir" -path "*.dylib.dSYM*" -delete
113    fi
114fi
115
116# copy qt creator qt.conf
117if [ ! -f "$resource_path/qt.conf" ]; then
118    echo "- Copying qt.conf"
119    cp -f "$(dirname "${BASH_SOURCE[0]}")/../dist/installer/mac/qt.conf" "$resource_path/qt.conf" || exit 1
120fi
121
122# copy libexec tools' qt.conf
123if [ ! -f "$libexec_path/qt.conf" ]; then
124    echo "- Copying libexec/qt.conf"
125    cp -f "$(dirname "${BASH_SOURCE[0]}")/../dist/installer/mac/libexec_qt.conf" "$libexec_path/qt.conf" || exit 1
126fi
127
128# copy ios tools' qt.conf
129if [ ! -f "$libexec_path/ios/qt.conf" ]; then
130    echo "- Copying libexec/ios/qt.conf"
131    cp -f "$(dirname "${BASH_SOURCE[0]}")/../dist/installer/mac/ios_qt.conf" "$libexec_path/ios/qt.conf" || exit 1
132fi
133
134# copy qml2puppet's qt.conf
135if [ ! -f "$libexec_path/qmldesigner/qt.conf" ]; then
136    echo "- Copying libexec/qmldesigner/qt.conf"
137    cp -f "$(dirname "${BASH_SOURCE[0]}")/../dist/installer/mac/qmldesigner_qt.conf" "$libexec_path/qmldesigner/qt.conf" || exit 1
138fi
139
140# copy Qt translations
141# check for known existing translation to avoid copying multiple times
142if [ ! -f "$resource_path/translations/qt_de.qm" ]; then
143    echo "- Copying Qt translations"
144    cp "$translation_src"/*.qm "$resource_path/translations/" || exit 1
145fi
146
147# copy libclang if needed
148if [ $LLVM_INSTALL_DIR ]; then
149    if [ "$LLVM_INSTALL_DIR"/lib/libclang.dylib -nt "$app_path/Contents/PlugIns"/libclang.dylib ]; then
150        echo "- Copying libclang"
151        mkdir -p "$app_path/Contents/Frameworks" || exit 1
152        # use recursive copy to make it copy symlinks as symlinks
153        mkdir -p "$libexec_path/clang/bin"
154        mkdir -p "$libexec_path/clang/lib"
155        cp -Rf "$LLVM_INSTALL_DIR"/lib/libclang.*dylib "$app_path/Contents/Frameworks/" || exit 1
156        cp -Rf "$LLVM_INSTALL_DIR"/lib/clang "$libexec_path/clang/lib/" || exit 1
157        cp -Rf "$LLVM_INSTALL_DIR"/lib/libclang-cpp.dylib "$libexec_path/clang/lib/" || exit 1
158        cp -Rf "$LLVM_INSTALL_DIR"/lib/ClazyPlugin.dylib "$libexec_path/clang/lib/" || exit 1
159        clangsource="$LLVM_INSTALL_DIR"/bin/clang
160        clanglinktarget="$(readlink "$clangsource")"
161        cp -Rf "$clangsource" "$libexec_path/clang/bin/" || exit 1
162        if [ $clanglinktarget ]; then
163            cp -Rf "$(dirname "$clangsource")/$clanglinktarget" "$libexec_path/clang/bin/$clanglinktarget" || exit 1
164        fi
165        clangdsource="$LLVM_INSTALL_DIR"/bin/clangd
166        cp -Rf "$clangdsource" "$libexec_path/clang/bin/" || exit 1
167        clangtidysource="$LLVM_INSTALL_DIR"/bin/clang-tidy
168        cp -Rf "$clangtidysource" "$libexec_path/clang/bin/" || exit 1
169        clazysource="$LLVM_INSTALL_DIR"/bin/clazy-standalone
170        cp -Rf "$clazysource" "$libexec_path/clang/bin/" || exit 1
171        install_name_tool -add_rpath "@executable_path/../lib" "$libexec_path/clang/bin/clazy-standalone" || exit 1
172        install_name_tool -delete_rpath "/Users/qt/work/build/libclang/lib" "$libexec_path/clang/bin/clazy-standalone" 2> /dev/null
173    fi
174    clangbackendArgument="-executable=$libexec_path/clangbackend"
175fi
176
177#### macdeployqt
178
179if [ ! -d "$app_path/Contents/Frameworks/QtCore.framework" ]; then
180
181    qml2puppetapp="$libexec_path/qmldesigner/qml2puppet"
182    if [ -f "$qml2puppetapp" ]; then
183        qml2puppetArgument="-executable=$qml2puppetapp"
184    fi
185
186    qbsapp="$app_path/Contents/MacOS/qbs"
187    if [ -f "$qbsapp" ]; then
188        qbsArguments=("-executable=$qbsapp" \
189        "-executable=$qbsapp-config" \
190        "-executable=$qbsapp-config-ui" \
191        "-executable=$qbsapp-setup-android" \
192        "-executable=$qbsapp-setup-qt" \
193        "-executable=$qbsapp-setup-toolchains" \
194        "-executable=$qbsapp-create-project" \
195        "-executable=$libexec_path/qbs_processlauncher")
196    fi
197
198    echo "- Running macdeployqt ($bin_src/macdeployqt)"
199
200    "$bin_src/macdeployqt" "$app_path" \
201        "-executable=$app_path/Contents/MacOS/qtdiag" \
202        "-executable=$libexec_path/qtpromaker" \
203        "-executable=$libexec_path/sdktool" \
204        "-executable=$libexec_path/ios/iostool" \
205        "-executable=$libexec_path/buildoutputparser" \
206        "-executable=$libexec_path/cpaster" \
207        "${qbsArguments[@]}" \
208        "$qml2puppetArgument" \
209        "$clangbackendArgument" || exit 1
210
211fi
212