Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.

Qt Creator qmake to CMake Workflow: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
(Created page with "Category:Tools::QtCreator")
 
No edit summary
Line 1: Line 1:
[[Category:Tools::QtCreator]]
[[Category:Tools::QtCreator]]
== Building Qt Creator with CMake ==
Detailed instructions at https://code.qt.io/cgit/qt-creator/qt-creator.git/tree/README.md
It boils down to:
<code>mkdir qtcreator_build
cd qtcreator_build
cmake -DCMAKE_BUILD_TYPE=Debug -G Ninja "-DCMAKE_PREFIX_PATH=/path/to/Qt;/path/to/llvm" /path/to/qtcreator_sources
cmake --build .</code>
If you happen to need to call cmake again in the same build directory (which you usually don't), you don't need to repeat parameters that you already have passed. Values are stored in "qtcreator_build/CMakeCache.txt".
== I can put qmake on the PATH and then only need to run "qmake" ==
=== Environment Variable ===
You can set "CMAKE_PREFIX_PATH" as an environment variable instead of passing it to the CMake call.
=== Pre-load script ===
You can create a file with "set(... CACHE ...)" commands and pass that to the initial cmake call with "cmake -C /path/to/build.cmake /path/to/qtcreator_sources".
For example my "5.15.cmake" contains
set(CMAKE_PREFIX_PATH "/Users/Shared/qt/Qt/5.15.4/clang_64;/Users/Shared/qt/libclang-12;/Users/Shared/qt/3rdparty/xlnt/install" CACHE STRING "")
set(CMAKE_BUILD_TYPE Debug CACHE STRING "")
set(WITH_DOCS ON CACHE BOOL "")
set(BUILD_DEVELOPER_DOCS ON CACHE BOOL "")
set(WITH_TESTS ON CACHE BOOL "")
set(CMAKE_GENERATOR "Ninja" CACHE STRING "")
set(CMAKE_C_COMPILER_LAUNCHER "/usr/local/bin/ccache" CACHE STRING "")
set(CMAKE_CXX_COMPILER_LAUNCHER "/usr/local/bin/ccache" CACHE STRING "")
== Building only parts "qmake && make qmake_all && cd sub/dir/ && make" ==
=== Unix/NMake/Jom Makefiles ===
If you use the "Unix Makefiles", "NMake Makefiles" or "NMake Makefiles JOM" generators (the default), then "cd sub/dir/ && make" works as well.
It actually has the advantage over qmake that running for example "cd src/plugins/coreplugin && make" will also build all dependencies of coreplugin, including the aggregation, extensionsystem and utils libraries, which qmake does not.
=== Ninja ===
Ninja is not "recursive". This has advantages, but means that all build commands must be issued from the toplevel build directory. The advantage is that if you have configured Qt Creator with CMake (see next subsection), there is no performance benefit of triggering the build command only for a subdirectory.
The command to build only a subdirectory and all its dependencies is
ninja sub/dir/all
e.g. "ninja src/plugins/coreplugin/all".
=== Configuring Qt Creator with CMake ===
With cmake you can configure the Qt Creator build to exclude or only include specific parts. After running CMake you can use e.g. ccmake or cmake-gui or Qt Creator to look at all the configuration options:
BUILD_PLUGIN_*: set to OFF to exclude the plugin from the build
BUILD_EXECUTABLE_*, BUILD_LIBRARY_*: the same for executables and libraries.
You can use ccmake or cmake-gui or Qt Creator to set these variables after running CMake before building, or you can pass the corresponding "-DBUILD_PLUGIN_..." flags to your cmake run.
For example to not build the QmlDesigner plugin, run cmake with
<code>cmake -DBUILD_PLUGIN_QMLDESIGNER=OFF -DCMAKE_BUILD_TYPE=Debug -G Ninja "-DCMAKE_PREFIX_PATH=/path/to/Qt;/path/to/llvm" /path/to/qtcreator_sources</code>
If you later want to exclude the CVS plugin too, run
cmake -DBUILD_PLUGIN_CVS=OFF .
in the same build directory.
After you have configured a build directory to your liking, you can just build Qt Creator without any further flags. If you need to run CMake again in an existing build directory for some reason, the flags that you already have set, stay set (saved in CMakeCache.txt).
You can create a minimal build by telling CMake to not build libraries/executables/plugins at all by default, and then turn on individual libraries/executables/plugins with the "BUILD_<type>_BY_DEFAULT" variables. This needs to be passed in the initial CMake run. For example:
cmake -DBUILD_EXECUTABLES_BY_DEFAULT=OFF -DBUILD_PLUGINS_BY_DEFAULT=OFF -DBUILD_PLUGIN_CORE=ON -DBUILD_PLUGIN_TEXTEDITOR=ON -DCMAKE_PREFIX_PATH=.......
will build a minimal Qt Creator just with the libraries and Core and TextEditor plugins. If you have a common configuration that you want to re-use, you can for example use a pre-load script (see above).
This does not automatically turn dependencies on or off. If you turn a part off that is needed by another part, the CMake run will complain with errors like
  CMake Error at qtcreator/cmake/QtCreatorAPIInternal.cmake:270 (message):
    Target Mercurial depends on VcsBase which was disabled via
    BUILD_PLUGIN_VCSBASE set to OFF
(TODO: investigate if we can create some "flags-to-turn-off-with-all-dependencies" script.)
== I want to build Qt Creator without all the auto tests and then just a single auto test ==
Doesn't work yet, TODO.

Revision as of 07:26, 11 June 2021


Building Qt Creator with CMake

Detailed instructions at https://code.qt.io/cgit/qt-creator/qt-creator.git/tree/README.md

It boils down to:

mkdir qtcreator_build
 cd qtcreator_build
 cmake -DCMAKE_BUILD_TYPE=Debug -G Ninja "-DCMAKE_PREFIX_PATH=/path/to/Qt;/path/to/llvm" /path/to/qtcreator_sources
 cmake --build .

If you happen to need to call cmake again in the same build directory (which you usually don't), you don't need to repeat parameters that you already have passed. Values are stored in "qtcreator_build/CMakeCache.txt".

I can put qmake on the PATH and then only need to run "qmake"

Environment Variable

You can set "CMAKE_PREFIX_PATH" as an environment variable instead of passing it to the CMake call.

Pre-load script

You can create a file with "set(... CACHE ...)" commands and pass that to the initial cmake call with "cmake -C /path/to/build.cmake /path/to/qtcreator_sources".

For example my "5.15.cmake" contains

set(CMAKE_PREFIX_PATH "/Users/Shared/qt/Qt/5.15.4/clang_64;/Users/Shared/qt/libclang-12;/Users/Shared/qt/3rdparty/xlnt/install" CACHE STRING "")
set(CMAKE_BUILD_TYPE Debug CACHE STRING "")
set(WITH_DOCS ON CACHE BOOL "")
set(BUILD_DEVELOPER_DOCS ON CACHE BOOL "")
set(WITH_TESTS ON CACHE BOOL "")
set(CMAKE_GENERATOR "Ninja" CACHE STRING "")
set(CMAKE_C_COMPILER_LAUNCHER "/usr/local/bin/ccache" CACHE STRING "")
set(CMAKE_CXX_COMPILER_LAUNCHER "/usr/local/bin/ccache" CACHE STRING "")

Building only parts "qmake && make qmake_all && cd sub/dir/ && make"

Unix/NMake/Jom Makefiles

If you use the "Unix Makefiles", "NMake Makefiles" or "NMake Makefiles JOM" generators (the default), then "cd sub/dir/ && make" works as well.

It actually has the advantage over qmake that running for example "cd src/plugins/coreplugin && make" will also build all dependencies of coreplugin, including the aggregation, extensionsystem and utils libraries, which qmake does not.

Ninja

Ninja is not "recursive". This has advantages, but means that all build commands must be issued from the toplevel build directory. The advantage is that if you have configured Qt Creator with CMake (see next subsection), there is no performance benefit of triggering the build command only for a subdirectory.

The command to build only a subdirectory and all its dependencies is

ninja sub/dir/all

e.g. "ninja src/plugins/coreplugin/all".

Configuring Qt Creator with CMake

With cmake you can configure the Qt Creator build to exclude or only include specific parts. After running CMake you can use e.g. ccmake or cmake-gui or Qt Creator to look at all the configuration options:

BUILD_PLUGIN_*: set to OFF to exclude the plugin from the build

BUILD_EXECUTABLE_*, BUILD_LIBRARY_*: the same for executables and libraries.

You can use ccmake or cmake-gui or Qt Creator to set these variables after running CMake before building, or you can pass the corresponding "-DBUILD_PLUGIN_..." flags to your cmake run.

For example to not build the QmlDesigner plugin, run cmake with

cmake -DBUILD_PLUGIN_QMLDESIGNER=OFF -DCMAKE_BUILD_TYPE=Debug -G Ninja "-DCMAKE_PREFIX_PATH=/path/to/Qt;/path/to/llvm" /path/to/qtcreator_sources

If you later want to exclude the CVS plugin too, run

cmake -DBUILD_PLUGIN_CVS=OFF .

in the same build directory.

After you have configured a build directory to your liking, you can just build Qt Creator without any further flags. If you need to run CMake again in an existing build directory for some reason, the flags that you already have set, stay set (saved in CMakeCache.txt).

You can create a minimal build by telling CMake to not build libraries/executables/plugins at all by default, and then turn on individual libraries/executables/plugins with the "BUILD_<type>_BY_DEFAULT" variables. This needs to be passed in the initial CMake run. For example:

cmake -DBUILD_EXECUTABLES_BY_DEFAULT=OFF -DBUILD_PLUGINS_BY_DEFAULT=OFF -DBUILD_PLUGIN_CORE=ON -DBUILD_PLUGIN_TEXTEDITOR=ON -DCMAKE_PREFIX_PATH=.......

will build a minimal Qt Creator just with the libraries and Core and TextEditor plugins. If you have a common configuration that you want to re-use, you can for example use a pre-load script (see above).

This does not automatically turn dependencies on or off. If you turn a part off that is needed by another part, the CMake run will complain with errors like

 CMake Error at qtcreator/cmake/QtCreatorAPIInternal.cmake:270 (message):
   Target Mercurial depends on VcsBase which was disabled via
   BUILD_PLUGIN_VCSBASE set to OFF

(TODO: investigate if we can create some "flags-to-turn-off-with-all-dependencies" script.)

I want to build Qt Creator without all the auto tests and then just a single auto test

Doesn't work yet, TODO.