Qt Creator qmake to CMake Workflow: Difference between revisions
No edit summary |
(Added link to instructions for building the docs.) |
||
(One intermediate revision by one other user not shown) | |||
Line 28: | Line 28: | ||
set(CMAKE_C_COMPILER_LAUNCHER "/usr/local/bin/ccache" CACHE STRING "") | set(CMAKE_C_COMPILER_LAUNCHER "/usr/local/bin/ccache" CACHE STRING "") | ||
set(CMAKE_CXX_COMPILER_LAUNCHER "/usr/local/bin/ccache" CACHE STRING "") | set(CMAKE_CXX_COMPILER_LAUNCHER "/usr/local/bin/ccache" CACHE STRING "") | ||
Alternative: use presets (requires CMake 3.19) | |||
==Building only parts "qmake && make qmake_all && cd sub/dir/ && make"== | ==Building only parts "qmake && make qmake_all && cd sub/dir/ && make"== | ||
Line 79: | Line 82: | ||
If you want to configure with a list of individual tests to begin with, you can use '-DWITH_TESTS=ON "-DBUILD_TESTS=tst_onetest;tst_anothertest"'. | If you want to configure with a list of individual tests to begin with, you can use '-DWITH_TESTS=ON "-DBUILD_TESTS=tst_onetest;tst_anothertest"'. | ||
== I want to build Qt Creator or Qt Design Studio docs == | |||
The instructions for building the docs are included in [https://doc.qt.io/qtcreator-extending/qtcreator-documentation.html#using-cmake Extending Qt Creator Manual]. |
Latest revision as of 13:26, 15 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". This is not limited to the prefix path but can contain anything that you would otherwise pass to cmake via -D.
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 "")
Alternative: use presets (requires CMake 3.19)
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". All build commands must be issued from the toplevel build directory. If you have configured Qt Creator with CMake (see next subsection) to your liking, there is no performance benefit of triggering the build command only for a subdirectory though, because of that.
The command to build only a subdirectory and all its dependencies is
ninja sub/dir/all
e.g. "ninja src/plugins/coreplugin/all".
ninja -t targets all # lists all targets
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=....... # there is a shortcut for this if you use that in the first initial CMake call: cmake -DBUILD_EXECUTABLES_BY_DEFAULT=OFF "-DBUILD_PLUGINS=Core;TextEditor" -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
(This is master branch / Qt Creator 5.)
Configure Qt Creator with "-DWITH_TESTS=ON -DBUILD_TESTS_BY_DEFAULT=OFF" to have test capability enabled (including the WITH_TESTS C++ define) but no tests being compiled. You can enable individual tests with "-DBUILD_TEST_TST_MY_TEST=ON".
If you want to configure with a list of individual tests to begin with, you can use '-DWITH_TESTS=ON "-DBUILD_TESTS=tst_onetest;tst_anothertest"'.
I want to build Qt Creator or Qt Design Studio docs
The instructions for building the docs are included in Extending Qt Creator Manual.