Jump to content

QtWebEngine/Qt6Build: Difference between revisions

From Qt Wiki
Michal Klocek (talk | contribs)
m fix typo in build instructions
Michal Klocek (talk | contribs)
m add subsection
 
(32 intermediate revisions by 2 users not shown)
Line 3: Line 3:
Please check platform notes for required dependencies https://doc.qt.io/qt-6/qtwebengine-platform-notes.html.
Please check platform notes for required dependencies https://doc.qt.io/qt-6/qtwebengine-platform-notes.html.


Qt builds can be done in ''top level'' manner, meaning that you clone qt5 main repository (git://code.qt.io/qt/qt5.git),
{{note| Starting from 6.12 QtWebEngine is no longer a submodule of qt5 repository, meaning that if you clone qt5 main repository (git://code.qt.io/qt/qt5.git) the QtWebEngine module will be not there and it has to be cloned in separate step.}}
which then initializes all the qt modules as sub-modules,configures and builds everything in one go.
However, this small guide shows the alternative way, so called ''module build'', which is more robust as
it clones minimum subset of modules required for QtWebEngine and compiles each module separately. It is
also very flexible way of building as you can try to compile newer QtWebEngine module with older qt modules.
Compiling each module separately has also advantage that you can see configure and compilation issues just for given module,
meaning that you can install missing dependencies and just reconfigure and recompile the problematic module instead
of rerunning configuration for all modules.


==Obtain Qt6 source code==
==Overview==


<syntaxhighlight>
As a first step we clone minimum subset of Qt6 modules required for QtWebEngine build and compile
mkdir qt6
them. Secondly we clone QtWebEngine repository and use compiled Qt6 modules to build QtWebEngine.
cd qt6
 
==Open the build shell==
 
All the build commands we execute in a build shell / terminal.


git clone git://code.qt.io/qt/qtbase.git
On Windows platform ''Developer Command Prompt'' is required, therefore for example for Visual Studio Build Tools 2022 the
git clone git://code.qt.io/qt/qtshadertools.git
correct setup requires:
git clone git://code.qt.io/qt/qtdeclarative.git
git clone git://code.qt.io/qt/qtwebengine.git


cd qtwebenigne
<syntaxhighlight lang="bash">
git submodule init
call "C:\Program File (x86)\Microsoft Visial Studio\2022\BuildTools\VC\Auxilary\Build\vcvarsall.bat" amd64
git submodule update
cd ..
</syntaxhighlight>
</syntaxhighlight>


Note that web engine needs initialization of submodule.
{{note| The location of the script may vary please refer to the [https://learn.microsoft.com/en-us/visualstudio/ide/reference/command-prompt-powershell Microsoft documentation.]}}


==Select branches==
==Obtain the Qt6 source code==


Let's assume we want to compile Qt 6.2.4 with Qt Webengine 6.4.3
Select the location for the source code and checkout the qt6 source:
Therefore, in qtbase, qtshadertools, qtdeclarative repositories we select barnches:


<syntaxhighlight>
<syntaxhighlight lang="bash">
git checkout origin/6.2.4
git clone git://code.qt.io/qt/qt5.git qt6
</syntaxhighlight>
 
==Select branch==
 
Let's assume we want to compile latest Qt 6.12.
 
<syntaxhighlight lang="bash">
cd qt6
git checkout origin/6.12
</syntaxhighlight>
</syntaxhighlight>


Where-else in qtwebengine
==Initialize all required modules==


<syntaxhighlight>
Starting with Qt 6.8 you can simply after cloning qt5 repository and selecting branch call 'init-repository' cmake script. This will also setup all the required submodules.  
cd qtwebengine
 
git checkout origin/6.4.3
<syntaxhighlight lang="bash">
git submodule update
./init-repository --module-subset=qtbase,qtshadertools,qtdeclarative --no-resolve-deps
cd ..
</syntaxhighlight>
</syntaxhighlight>
{{note|On Windows platform you should use 'init-repository.bat' instead of 'init-repository' command.}}


==Shadow build==
==Shadow build==


It is common practice to compile project is separate build directory instead of doing in-source build, therefore we create following build layout:
It is a common practice to compile the project in separate build directory instead of doing in-source build, therefore we create build directory:
 
{{note|On Windows platform you should use 'md' instead of 'mkdir' command}}


<syntaxhighlight>
<syntaxhighlight lang="bash">
mkdir build
mkdir build
cd build
cd build
mkdir qtbase qtshadertools qtdeclarative qtwebengine
</syntaxhighlight>
</syntaxhighlight>


==Configure and build qtbase==
==Configure top level build and build required qt6 submodules==
 
From our 'build' directory we call the configure from qt6 'source' directory to make prefix build, which means that we will compile and than install to the specific installation directory defined with 'prefix' argument.
 
On '''Linux''' the configure command line for the release builds might look like:
 
<syntaxhighlight lang="bash">
 
../configure -release -nomake tests -nomake examples -no-pch -linker mold -prefix /opt/qt/6.12
</syntaxhighlight>
 
{{note|To speed up linking time for WebEngine we decided to use mold linker.}}
 
On '''Windows''' the configure command line for the release build might look like:


From out qtbase build directory we call configure from qtbase source directory to make prefix build, which
means that we compile and than install to specific installation directory here /opt/qt/6.2
<syntaxhighlight>
<syntaxhighlight>
cd build/qtbase
..\configure.bat -release -nomake tests -nomake examples -no-pch -prefix C:\opt\qt\6.12
../../qtbase/configure -opensource -confirm-license -release -nomake tests -nomake examples -xcb -opengl desktop -qpa xcb -no-pch -linker lld -prefix /opt/qt/6.2
</syntaxhighlight>
</syntaxhighlight>


Here we do release build with no examples and no tests. For other configure options please refer to configure quide https://doc.qt.io/qt-6/configure-options.html
On '''Mac''' the configure command line for the release framework builds might look like:


Note to speed up linking time for webengine we decided to use lld linker.
<syntaxhighlight lang="bash">
../configure -release -framework -release -nomake tests -nomake examples -no-pch -prefix /opt/qt/6.12
</syntaxhighlight>


To build and install qt base you just need to call cmake:
or '''Mac universal''' build :


<syntaxhighlight>
<syntaxhighlight lang="bash">
../configure -release -framework -nomake tests -nomake examples -no-pch -prefix /opt/qt/6.12 -- -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64"
</syntaxhighlight>
 
{{note| For other configure options please refer to the configure guide https://doc.qt.io/qt-6/configure-options.html}}
 
To build and install modules you just need to call cmake:
 
<syntaxhighlight lang="bash">
cmake --build . --parallel
cmake --build . --parallel
cmake --install .
cmake --install .
</syntaxhighlight>
</syntaxhighlight>


{{note | On Windows in case of debug and release build please use "ninja install" instead of "cmake --install ." due to cmake [https://gitlab.kitware.com/cmake/cmake/-/issues/21475 issue]}}


==Configure and build other modules==
==Obtain the Qt6 WebEngine source code==


To configure and build other modules we use qt-configure-module wrapper script for the installed qtbase module.
Now let's focus on QtWebEngine build, first clone the repository with required sub repository.


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
cd build/qtshadertools
git clone git://code.qt.io/qt/qtwebengine.git qtwebengine
/opt/qt/6.2/bin/qt-cofigure-module ../../qtshadertools
cd qtwebengine
cmake --build . --parallel
git submodule init
cmake --install .
git submodule update
cd ..
</syntaxhighlight>
 
==Configure and build QtWebEngine module==
 
To configure and build QtWebEngine module we use the '''qt-configure-module wrapper''' script from the installed in previous step Qt.


cd qtdeclarative
{{note|On Windows you might want to call 'C:\opt\qt\6.12\bin\qt-cofigure-module.bat' instead of 'qt-cofigure-module'}}
/opt/qt/6.2/bin/qt-cofigure-module ../../qtdeclarative
cmake --build . --parallel
cmake --install .
cd ..


cd qtwebengine
<syntaxhighlight lang="bash">
/opt/qt/6.2/bin/qt-cofigure-module ../../qtwebengine
mkdir qtwebengine-build
cd qtwebengine-build
/opt/qt/6.12/bin/qt-configure-module ../../qtwebengine
cmake --build . --parallel
cmake --build . --parallel
cmake --install .
cmake --install .
cd ..
cd ..
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 08:01, 20 August 2026

Building Qt6 WebEngine from Source

Please check platform notes for required dependencies https://doc.qt.io/qt-6/qtwebengine-platform-notes.html.

  Note: Starting from 6.12 QtWebEngine is no longer a submodule of qt5 repository, meaning that if you clone qt5 main repository (git://code.qt.io/qt/qt5.git) the QtWebEngine module will be not there and it has to be cloned in separate step.

Overview

As a first step we clone minimum subset of Qt6 modules required for QtWebEngine build and compile them. Secondly we clone QtWebEngine repository and use compiled Qt6 modules to build QtWebEngine.

Open the build shell

All the build commands we execute in a build shell / terminal.

On Windows platform Developer Command Prompt is required, therefore for example for Visual Studio Build Tools 2022 the correct setup requires:

call "C:\Program File (x86)\Microsoft Visial Studio\2022\BuildTools\VC\Auxilary\Build\vcvarsall.bat" amd64

  Note: The location of the script may vary please refer to the Microsoft documentation.

Obtain the Qt6 source code

Select the location for the source code and checkout the qt6 source:

git clone git://code.qt.io/qt/qt5.git qt6

Select branch

Let's assume we want to compile latest Qt 6.12.

cd qt6
git checkout origin/6.12

Initialize all required modules

Starting with Qt 6.8 you can simply after cloning qt5 repository and selecting branch call 'init-repository' cmake script. This will also setup all the required submodules.

./init-repository --module-subset=qtbase,qtshadertools,qtdeclarative --no-resolve-deps

  Note: On Windows platform you should use 'init-repository.bat' instead of 'init-repository' command.

Shadow build

It is a common practice to compile the project in separate build directory instead of doing in-source build, therefore we create build directory:

  Note: On Windows platform you should use 'md' instead of 'mkdir' command

mkdir build
cd build

Configure top level build and build required qt6 submodules

From our 'build' directory we call the configure from qt6 'source' directory to make prefix build, which means that we will compile and than install to the specific installation directory defined with 'prefix' argument.

On Linux the configure command line for the release builds might look like:

../configure -release -nomake tests -nomake examples -no-pch -linker mold -prefix /opt/qt/6.12

  Note: To speed up linking time for WebEngine we decided to use mold linker.

On Windows the configure command line for the release build might look like:

..\configure.bat -release -nomake tests -nomake examples -no-pch -prefix C:\opt\qt\6.12

On Mac the configure command line for the release framework builds might look like:

../configure -release -framework -release -nomake tests -nomake examples -no-pch -prefix /opt/qt/6.12

or Mac universal build :

../configure -release -framework -nomake tests -nomake examples -no-pch -prefix /opt/qt/6.12 -- -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64"

  Note: For other configure options please refer to the configure guide https://doc.qt.io/qt-6/configure-options.html

To build and install modules you just need to call cmake:

cmake --build . --parallel
cmake --install .

  Note: On Windows in case of debug and release build please use "ninja install" instead of "cmake --install ." due to cmake issue

Obtain the Qt6 WebEngine source code

Now let's focus on QtWebEngine build, first clone the repository with required sub repository.

git clone git://code.qt.io/qt/qtwebengine.git qtwebengine
cd qtwebengine
git submodule init
git submodule update

Configure and build QtWebEngine module

To configure and build QtWebEngine module we use the qt-configure-module wrapper script from the installed in previous step Qt.

  Note: On Windows you might want to call 'C:\opt\qt\6.12\bin\qt-cofigure-module.bat' instead of 'qt-cofigure-module'

mkdir qtwebengine-build
cd qtwebengine-build
/opt/qt/6.12/bin/qt-configure-module ../../qtwebengine
cmake --build . --parallel
cmake --install .
cd ..