Qt Creator qmake to CMake Workflow: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
[[Category:Tools::QtCreator]] | [[Category:Tools::QtCreator]] | ||
== Building Qt Creator with CMake == | ==Building Qt Creator with CMake== | ||
Detailed instructions at https://code.qt.io/cgit/qt-creator/qt-creator.git/tree/README.md | Detailed instructions at https://code.qt.io/cgit/qt-creator/qt-creator.git/tree/README.md | ||
Line 11: | Line 11: | ||
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". | 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" == | ==I can put qmake on the PATH and then only need to run "qmake"== | ||
=== Environment Variable === | ===Environment Variable=== | ||
You can set "CMAKE_PREFIX_PATH" as an environment variable instead of passing it to the CMake call. | You can set "CMAKE_PREFIX_PATH" as an environment variable instead of passing it to the CMake call. | ||
=== Pre-load script === | ===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". | 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 | For example my "5.15.cmake" contains | ||
Line 29: | Line 29: | ||
set(CMAKE_CXX_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" == | ==Building only parts "qmake && make qmake_all && cd sub/dir/ && make"== | ||
=== Unix/NMake/Jom Makefiles === | ===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. | 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. | 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=== | ||
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. | 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. | ||
Line 43: | Line 43: | ||
e.g. "ninja src/plugins/coreplugin/all". | e.g. "ninja src/plugins/coreplugin/all". | ||
=== Configuring Qt Creator with CMake === | ===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: | 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: | ||
Line 70: | Line 70: | ||
(TODO: investigate if we can create some "flags-to-turn-off-with-all-dependencies" script.) | (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 == | ==I want to build Qt Creator without all the auto tests and then just a single auto test== | ||
Doesn't work yet, TODO. | Doesn't work yet, TODO. |
Revision as of 07:31, 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". 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 "")
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.