[Qt-creator] Generating QtCreator cmake project for given CMakeLists.txt from command line
Nikolaus Demmel
nikolaus at nikolaus-demmel.de
Mon Mar 28 01:49:43 CEST 2016
Hi,
I am cross-posting this from https://forum.qt.io/topic/65483/generating-qtcreator-project-for-cmakelists-txt-from-command-line, since it was suggested there that the topic were more appropriate for the mailing list. The following is a slightly adapted version of the original post over at forum.qt.io, including now a paragraph talking about how this might interact with QtCreator Kits.
I was woundering if it is at all possible to generate a QtCreator project for a given `CMakeLists.txt` from command line, i.e. generating the `CMakeLists.txt.user` from command line while giving some parameters, such as the desired configurations and according build directories.
My use case is the following.
BACKGROUND:
I am developing software within the ROS [1] framework. One of the many aspects of ROS is the `catkin` build system, which makes it easy for you to manage many different ROS packages and their depedencies. For example, the latest ROS distribution "Jade" has almost 1000 packages released [2]. `catkin` is CMake-based, and as such in a typical ROS workspace you might have 10s or even >100 CMake projects.
Now while you can use `catkin` with the standard CMake workflow of `mkidr build && cd build && cmake ../src && make`, there also exists a command line tool suite `catkin_tools` [3], which aids you in building all catkin/CMake projects in your workspace independently, while still respecting the interdependencies. As such, it manages the `cmake` invocations and build-locations for each package. It also has support for profiles, such that you could handle different configurations at the same time (debug, relase, ...).
My current workflow using this together with QtCreator is the following: I use `catkin build` to compile all my packages, which also entails calling cmake in a specific build directory for each package. Then, whenever I want to work on a specific package, I open the `CMakeLists.txt` as a project in QtCreator, but need to manually select the correct build directory. If I have different profiles, I need to select each of the build directories for the different configurations.
DESIRED WORKFLOW:
It would be nice if for a catkin workspace such as described above, I could generate QtCreator projects for *all* packages with the appropriate build directories set up. For example, to do the same for Eclipse, I can call something like `catkin build --force-cmake -G"Eclipse CDT4 - Unix Makefiles"`, and then import the generated projects into Eclipse, which is extremely convenient. It would be great to be able to generate the QtCreator project files in a similar fashion without user intervention.
I think we really only would need to generate the `CMakeLists.txt.user` file. The `.cbp` files generated by cmake itself could be created when the user first opens the project in QtCreator and invokes cmake through QtCreator. The only parameters I currently would want to pass are the configurations and according build-directories.
Note that when the user opens the generated QtCreator project, the build directory with cmake-cache etc already exists from the original `catkin build` call. As such I would not want QtCreator to inject any configuration into the cmake call such as which compiler to use, which Qt version, which version of cmake. This seems to conflict somewhat with the concept of Kits in QtCreator. What I am looking for here is using QtCreator with some sort of “current environment kit”, which should use the compiler, Qt, cmake as defined by the current environment, i.e. the same way that `cmake` and `make` (or in fact `catkin build`) calls from the command line would do. If this cannot easily be done, I think the next best thing would be allowing to select a specific Kit (by name) from command line. It would then be the responsibility of the user to setup a Kit in QtCreator first that is compatible with the environment on the command line.
Does anyone have any input on what would the best way to achieve this? Should this be a standalone script/application, or somehow built into qtcreator with a specific command line invocation? Would it be easier to utilise the cmakeproject-related classes implemented in QtCreator, or generate the xml independently? Is there some kind of spec describing the contents of `CMakeLists.txt.user`? Is there some way to query information like the available Kits from QtCreator from command line in a machine readable form?
Any comments or insights are welcome.
Cheers & Happy Easter everyone,
Niko
[1] http://www.ros.org/
[2] http://repositories.ros.org/status_page/ros_jade_default.html
[3] http://catkin-tools.readthedocs.org/en/latest/index.html
More information about the Qt-creator
mailing list