[Qt-creator] Generating QtCreator cmake project for given CMakeLists.txt from command line

Hunger Tobias Tobias.Hunger at theqtcompany.com
Thu Mar 31 21:27:02 CEST 2016


Hi Nikolaus,

On Thu, Mar 31, 2016 at 8:23 PM, Nikolaus Demmel <nikolaus at nikolaus-demmel.de> wrote:
>> You actually should not even need to rerun cmake, provided you set up catkin to use the "-GCodeBlocks - Unix Makefiles" generator we need for Qt Creator.
>
> Is that enough? That sounds great. I thought that QtCreator might do some more "magic".

We try very hard to not do any magic, especially not with the build systems! Ideally you should be able to open any project using one of the supported build systems without any changes and without any special configuration in Qt Creator.

That is one of the reasons why I sometimes joke that "Qt Creator is the best IDE for everybody that hates IDEs":-)

> This can be run easily for all packages with `catkin build --force-cmake --cmake-args "-GCodeBlocks - Unix Makefiles"`.

In fact I did
catkin config -DCMAKE_BUILD_TYPE=Release "-GCodeBlocks - Unix Makefiles"

You need to experiment a bit to get the spaces quoted (who puts spaces into something that is supposed to be used as a command line argument?!).

> However I noticed that QtCreator currently reruns cmake in any case whenever you open a project. I think this is fine, and that way the user doesn't even have to remember to call `catkin build` with the `"-GCodeBlocks - Unix Makefiles"` argument manually.

I do not know catkin well enough to comment whether or not that is viable.

Qt Creator will rerun cmake though, since it needs to make sure there is no stale data in the configuration it reads. Who knows what the user did to the project since cmake was last run?

>>> The step that is inconvenient, which I was asking about in this thread, is the fact that for each ROS package, you have to manually select the correct build directory and Kit when opening the project. Since there can be many ROS packages in a workspace (>100), it gets cumbersome. That’s why I am looking for a way to generate the project file (CMakeLists.txt.user) from command line without user interaction. I want to be able to specify the build directory(s), and also the configuration(s)/Kit(s). For the latter it would be great if there was a “environment Kit”, which selects compiler/qmake/cmake in the same way that cmake would on the command line (in fact cmake has already been run from the initial `catkin build` call, so QtCreator could just ask cmake what compiler it configured, which would maybe be a sort of “cmake Kit”, where you let cmake run in the current environment determine the compiler).
>>
>> My original idea was to use the default build directory setting (Tools>Options>Build & Run>General IIRC) and adapt that for catkin use. Opening the source directory should then automatically pick up the right build directory.
>
> Your idea is to determine if the opened CMakeLists.txt file corresponds to a catkin package, and if yes, use some special logic to determine the correct build directory? This could be the perfect solution, I like it.

Even simpler: My idea was to just configure the default build directory for all projects to point to wherever catkin will put its build directories. At this point I am mostly thinking about how you can configure Qt Creator to make things more convenient for you right now (or soon, since I assume you will be using Qt Creator 4.0 for the better cmake experience;-).

<snip long section on catkin implementation>

> This is only a rough sketch, but I think using catkin itself to find the correct folders could be a robust solution. I can certainly help with figuring out the details and edge cases, and also extending `catkin locate` to provide all the informaton we need.

Sure, something like that would be best. But that of course requires somebody that knows those tools well to actually implement this:-)

<snip>
>> For Qt Creator 4.1 I would like to have a "import existing build" functionality<snip>
>
> This sounds perfect. I think this could be the last piece of the puzzle to achieve what I had originally intended. :)
>
> How would this work with configurations (Release / Debug / ...). At least with the Makefile backend, a given build directory that you import would correspond to exactly one configuration, namely the one that CMAKE_BUILD_TYPE is set to. Would you then simply only offer this one configuration for that project, or offer to create additional build directories for the other configurations?

I want to generalize the code and reuse as much as possible from the qmake implementation. There we basically use the default build directory as configured by the user for the kits, go up one level and scan all the folders found in that directory. If a directory is found, then all the checkboxes for build configurations are unchecked, the existing directories are shown under the kit they use (with kits being set up for builds that do not match any existing kit) and all these directories are checked.

So all the configurations should be found (provided you use a somewhat sane directory layout) and clicking on "Configure" should get you rolling with all of them set up.

That is not perfect for your use-case, but it should seriously reduce the necessary number of user interactions to open one cmake project that is a part of a bigger catkin project.

> The solution above is shaping up nicely IMHO, so maybe we can talk about a deeper integration of catkin_tools sooner than expected. E.g. offering to automatically set the build-step to `catkin build --this` for cmake projects that are detected to be a catkin package inside a workspace should be straight forward once the above is implemented.

I will keep your use-case in the back of my mind as I continue to work on Creator's cmake support for 4.1.

> Thanks for your ideas! You got me all excited now :-).

I am looking forward to discuss ideas as they evolve, and will await your patches;-)

Best Regards,
Tobias

--
Tobias Hunger, Senior Software Engineer | The Qt Company

The Qt Company GmbH, Rudower Chaussee 13, D-12489 Berlin
Geschäftsführer: Mika Pälsi, Juha Varelius, Tuula Haataja Sitz der Gesellschaft: Berlin, Registergericht: Amtsgericht Charlottenburg, HRB 144331 B


More information about the Qt-creator mailing list