get and build the qt in open source version

Getting the source code

First, cd into the directory where you want the "qt5" directory to live. Then, clone the top-level Qt 5 git repository:

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

or (if you're behind a firewall and want to use the https protocol):

$ git clone https://code.qt.io/qt/qt5.git

This creates a local branch that tracks "origin/dev". If you plan to submit changes to Qt, stay on this branch. Otherwise, check out the target branch (see Branch Guidelines):

$ cd qt5
$ git checkout 5.12

For commercial-only modules and commercial-only branches of public modules, see Getting Commercial Qt Sources.

Getting the submodule source code

As described in the README.git, initialize the repository using the init-repository script, which clones the various sub-modules of Qt 5.

Relevant options for init-repository:

  • --module-subset=default,-qtwebengine : Consider skipping the web module (Qt WebEngine) by passing this option. It is quite big and takes a long time to compile (and is often a source of compile errors), so it is recommended to only download it if you intend to use it. You can always re-run init-repository later on to add it.
  • --branch : Check out the branch tips instead of the SHA1s of the latest successful integration build.
  • --codereview-username <Jira/Gerrit username> : If you plan to contribute to Qt, you may specify your codereview username (pay attention to capitalization!) so that the git remotes are properly set up. Note that it is recommended to adjust your ssh configuration instead.
$ cd qt5
$ perl init-repository

In order to build a specific release of Qt, you can checkout the desired tag:

$ cd qt5
$ git checkout 5.12.0
$ perl init-repository

Note: init-repository is currently unable to initialize tags that are too old. An alternative way to build a specific release or branch of Qt5 (although without linking of the gerrit account for code reviewing) is to use git submodule update --init in place of the init-repository script. That translates to:

$ git clone https://code.qt.io/qt/qt5.git                     # cloning the repo
$ cd qt5
$ git checkout v5.8.0                                         # checking out the specific release or branch
$ git submodule update --init --recursive                     # updating each submodule to match the supermodule

More information can be found in Get The Source.

Configuring and Building

The Qt5 build system should be fairly resilient against any "outside distractions" - it shouldn't matter whether you have other Qt versions in PATH, and QTDIR is entirely ignored. However, make sure that you have no qmake-specific environment variables like QMAKEPATH or QMAKEFEATURES set, and the qmake -query output does not refer to any other Qt versions ($HOME/.config/Qt/QMake.conf should be empty).

For more configure options, see Qt Configure Options.

Note: To build qdoc and Qt documentation in future you should set LLVM_INSTALL_DIR environment variable pointing to directory where LLVM is installed (it should be top level directory, the configuration scripts use relative path tracing from this directory). For example, in Linux with LLVM installed in isolated directory (/usr/llvm), at a bash prompt:

$ export LLVM_INSTALL_DIR=/usr/llvm

A build script called configure (or configure.bat for Windows) will be in the directory that you git cloned the source code into (~/qt5 if you followed the directions above). You will want to call that script from a different, parallel-level directory, because (unless you are using a Qt Autotest Environment) you do not want to build Qt in the directory that holds the source code. Instead, you should use a "shadow build," meaning you should not build into the source directory.

For Linux / macOS, to install in ~/qt5-build (an arbitrary name), assuming you are in ~:

$ mkdir qt5-build
$ cd qt5-build
$ ../qt5/configure -developer-build -opensource -nomake examples -nomake tests

For Windows, again assuming you are in ~:

$ mkdir qt5-build
$ cd qt5-build
$ ..\\qt5\configure -developer-build -opensource -nomake examples -nomake tests

The -developer-build option causes more symbols to be exported in order to allow more classes and functions to be unit tested than in a regular Qt build. It also defaults to a 'debug' build, and installs the binaries in the current directory, avoiding the need for 'make install'. '-opensource' sets the license to be GPL/LGPL. The -nomake examples and -nomake tests parameters make sure examples and tests aren't compiled by default. You can always decide to compile them later by hand.

Some Hints

  1. You can add -confirm-license to get rid of the question whether you agree to the license.
  2. On Windows, you might not be able to build if sh.exe is in your PATH (for example due to a git or msys installation). Such an error is indicated by qt5-src\qtbase\bin\qmake.exe: command not found and alike. In this case, make sure that sh.exe is not in your path. You will have to re-configure if your installation is already configured.
  3. If you are planning to make contributions with git, it is advised to configure and build the source in a separate directory so the binaries are not seen by git. This can be done by navigating to the desired build directory and calling configure/make in that directory. (But shadow builds are discouraged in Qt Autotest Environment.)
    1. Note: If you do a shadow build, follow the instructions above for creating a build directory that is parallel to the source directory. Do NOT make the build directory a subdirectory of the source tree. The build will probably fail in weird ways if the build directory is not exactly parallel to the source directory.

Now trigger the build from within the build directory by running:

$ make -j$(nproc)

For Windows (MSVC), choose one of the following, depending on your setup/environment:

$ nmake

or

$ jom

or

$ mingw32-make

Or only build a specific module, e.g. declarative, and modules it depends on:

$ make module-qtdeclarative



https://wiki.qt.io/Building_Qt_5_from_Git#Getting_the_source_code

posted @ 2024-02-03 13:39  fire909090  阅读(7)  评论(0编辑  收藏  举报