summaryrefslogtreecommitdiffstats
path: root/mkspecs/features/functions.prf
blob: f858243e1f8efb674f00aaa571838e8d00327c09 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
defineReplace(getConfigDir) {
  CONFIG(release, debug|release):return("release")
  return("debug")
}

defineReplace(getChromiumSrcDir) {
  exists($$QTWEBENGINE_ROOT/.git): git_chromium_src_dir = $$system("git config qtwebengine.chromiumsrcdir")
  # Fall back to the snapshot path if git does not know about chromium sources (i.e. init-repository.py has not been used)
  isEmpty(git_chromium_src_dir): git_chromium_src_dir = "src/3rdparty/chromium"
  return($$git_chromium_src_dir)
}

defineReplace(which) {
  out = $$1
  win32 {
    command = $$split(out, " ")
    executable = $$first(command)
    # Return the first match only
    out = $$system("((for /f \"usebackq delims=\" %i in (`where $$executable 2^> NUL`) do @if not defined _endwhich (@echo %i & set _endwhich=true)) & set _endwhich=)")
    isEmpty(out) {
      message($$executable not found)
      out = $$executable
    }
    for(arg, command): !equals(arg, $$executable): out += $$arg
  } else:unix {
    command = $$split(out, " ")
    executable = $$first(command)
    out = $$system("which $$executable 2>/dev/null")
    isEmpty(out) {
      message($$executable not found)
      out = $$executable
    }
    for(arg, command): !equals(arg, $$executable): out += $$arg
  }
  return($$out)
}

# Returns the unquoted path to the python executable.
defineReplace(pythonPath) {
    isEmpty(QMAKE_PYTHON2) {
        # Fallback for building QtWebEngine with Qt < 5.8
        QMAKE_PYTHON2 = python
    }
    return($$QMAKE_PYTHON2)
}

# Returns the python executable for use with shell / make targets.
defineReplace(pythonPathForShell) {
    return($$shell_quote($$shell_path($$pythonPath())))
}

# Returns the python executable for use with $$system()
defineReplace(pythonPathForSystem) {
    return($$system_quote($$system_path($$pythonPath())))
}

defineReplace(ninjaPath) {
    src_3rd_party_dir = $$absolute_path("$${getChromiumSrcDir()}/../", "$$QTWEBENGINE_ROOT")
    out = $$shadowed($$absolute_path(ninja/ninja, $$src_3rd_party_dir))
    win32: out = $${out}.exe
    return($$out)
}

defineReplace(gnPath) {
    src_3rd_party_dir = $$absolute_path("$${getChromiumSrcDir()}/../", "$$QTWEBENGINE_ROOT")
    out = $$shadowed($$absolute_path(gn/out/Release/gn, $$src_3rd_party_dir))

    win32: out = $${out}.exe
    return($$out)
}

defineReplace(gnArgs) {
    linux: include($$QTWEBENGINE_ROOT/src/core/config/linux.pri)
    macos: include($$QTWEBENGINE_ROOT/src/core/config/mac_osx.pri)
    win32: include($$QTWEBENGINE_ROOT/src/core/config/windows.pri)
    isEmpty(gn_args): error(No gn_args found please make sure you have valid configuration.)
    return($$gn_args)
}

defineReplace(gnArch) {
    qtArch = $$1
    contains(qtArch, "i386"): return(x86)
    contains(qtArch, "x86_64"): return(x64)
    contains(qtArch, "arm"): return(arm)
    contains(qtArch, "arm64"): return(arm64)
    contains(qtArch, "mips"): return(mipsel)
    contains(qtArch, "mips64"): return(mips64el)
    return(unknown)
}

defineReplace(gnOS) {
    macos: return(mac)
    win32: return(win)
    linux: return(linux)
    error(Unsupported platform)
    return(unknown)
}

defineTest(skipBuild) {
    isEmpty(skipBuildReason): skipBuildReason = $$1
    else: skipBuildReason = "$$skipBuildReason $${EOL}$$1"
    export(skipBuildReason)
}

defineTest(isWebEngineCoreBuild) {
    !qtHaveModule(gui) {
        skipBuild("QtWebEngine requires QtGui.")
        return(false)
    }

    !exists($$QTWEBENGINE_ROOT/src/3rdparty/chromium) {
        skipBuild("Submodule qtwebengine-chromium does not exist. Run 'git submodule update --init'.")
        return(false)
    }

    WSPC = $$find(OUT_PWD, \\s)
    !isEmpty(WSPC) {
        skipBuild("QtWebEngine cannot be built in a path that contains whitespace characters.")
        return(false)
    }

    !isPlatformSupported() {
        # make sure we have skipBuildReason
        isEmpty(skipBuildReason): skipBuild("Unknow error. Platform unspported")
        return(false)
    }

    linux:contains(QT_CONFIG,no-pkg-config) {
        skipBuild("pkg-config is required")
        return(false)
    }

    include($$QTWEBENGINE_OUT_ROOT/src/core/qtwebenginecore-config.pri)
    QT_FOR_CONFIG += webenginecore-private

    win32:!qtConfig(webengine-win-compiler64) {
        skipBuild("Required 64-bit cross-building or native toolchain could not be found.")
        return(false)
    }

    !qtConfig(webengine-gperf) {
        skipBuild("Required gperf could not be found.")
        return(false)
    }
    !qtConfig(webengine-bison) {
        skipBuild("Required bison could not be found.")
        return(false)
    }
    !qtConfig(webengine-flex) {
        skipBuild("Required flex could not be found.")
        return(false)
    }
    !qtConfig(webengine-python2) {
        skipBuild("A suitable version of python2 could not be found.")
        return(false)
    }

    sanitizer: !qtConfig(webengine-sanitizer) {
        skipBuild("Chosen sanitizer configuration is not supported. Check config.log for details or use -feature-webengine-sanitizer to force build with the chosen sanitizer configuration.")
        return(false);
    }

    linux {

        !qtConfig(webengine-host-pkg-config) {
            skipBuild("Host pkg-config is required")
            return(false)
        }

        !qtConfig(webengine-system-glibc) {
            skipBuild("A suitable version >= 2.27 of libc could not be found.")
            return(false)
        }

        QT_FOR_CONFIG += gui-private

        !qtConfig(webengine-system-khr) {
            skipBuild("khronos development headers appear to be missing (mesa/libegl1-mesa-dev)")
            return(false)
        }

        for(package, $$list("nss dbus fontconfig")) {
            !qtConfig(webengine-system-$$package) {
                skipBuild("A suitable version of $$package could not be found.")
                return(false)
            }
         }

        qtConfig(xcb) : !qtConfig(webengine-ozone-x11) {
            skipBuild("Could not find all necessary libraries for qpa-xcb support")
            return(false)
        }
    }
}

defineReplace(pkgConfigHostExecutable) {
    wrapper_name = $$OUT_PWD/pkg-config-host_wrapper.sh
    wrapper_cmd = $$QMAKE_PKG_CONFIG_HOST
    isEmpty(wrapper_cmd): wrapper_cmd = pkg-config
    wrapper_content = \
        "$$LITERAL_HASH!/bin/sh" \
        "unset PKG_CONFIG_LIBDIR" \
        "unset PKG_CONFIG_SYSROOT_DIR" \
        "exec $$wrapper_cmd \"$@\""
    !build_pass:!write_file($$wrapper_name, wrapper_content, exe): error()
    QMAKE_DISTCLEAN += $$wrapper_name
    export(QMAKE_DISTCLEAN)
    return($$system_quote($$system_path($$wrapper_name)))
}