QtCreator and CMake: Where are the files in the Project panel?



  • I am working more and more with CMake within QtCreator, but recently I am having a problem.

    In the past I was able to first "prepare" a project with the cmake-gui, then open it with QtCreator and all looked like a "normal Qt Creator project" - with files shown in the Project panel (upper left), and all relationships nicely tracked, so I can jump from any key word to it's declaration and definition, find usages fast etc. etc.

    Now the support for CMake is on one side improved: I do not any more need the cmake-gui in most cases. But at the same time I do not see any filea except the CMakeLists.txt in the Projects panel! And this is more than a minor problem...

    What I have seen that in the past, some *.qbp file was created that contained somehow the project structure to be displayed. Now I do not see this file any more, but that might be the key to the problem:

    • How and when and through which tool is it generated?

    Many thanks for any helpful hints!
    Cornelis



  • CMake is used to generate the project information. There are two ways that happens though: First there is the mode that has been used in creator for ages, which requires the codeblocks extra generator to be used with CMake and then parses a surprisingly long list of different files, most starting with a warning about them being internal implementation details of CMake. The codeblocks extra generator creates those .cbp-files.

    The new approach uses CMake server-mode support to extract all required data. That is what CMake officially recommends to get information from. Server-Mode provides more and more reliable data, so Creator will use that whenever possible.

    Which mode is used depends on your CMake binary. Try running "cmake -E capabilities": If that produces JSON output that includes "Server-Mode":"true" then the new way of doing things is used with no way to go back:-) Basically all CMake binaries version >= 3.7 should support that. Eventually the old tea leave reading mode will get removed -- as soon as Linux distributions ship CMake that is new enough for Server-Mode by default.

    So to answer your question: Which mode does creator use in your case? If it is tea leave mode, please consider to update your CMake binary.



  • It looks like you are bringing me one step further!

    Indeed I am running on a fresh install of OpenSuse Leap 42.3, and this ships with a CMake version 3.5.2.

    Then I downloaded a new CMake version from cmake.org, which is 3.9.5 - and indeed the output of cmake -E capabilities is totally different! Only I was so far not able to "officially" install that version: what you get from cmake.org is simply a packed archive with all the files, and it looks like it is up to the user to find the right places for them in the system - which is also the reason why just typing "cmake" in some terminal always goes for the "old" version.

    Now my QtCreator was obviously and automatically using the "official" version on the system, because that is what comes automatically. Now, manually telling QtCreator to use the new version 3.9.5 - surprise! - the files are back! And also there is a cbp file now in my folder...

    I already somehow had the guess that codeblocks is maybe generating the cbp files, and of course some time ago I was using it. But then I learned that QtCreator is now supposed to do without now.

    Bottom line: I was aware of the fact that you need a recent Qt Creator for this to work, but I did not fully think about the need for a recent CMake version as well!

    So thanks for the really helpful explanations!



  • If you ask CMake to use a generator and the codeblocks extra generator, then CMake will generate .cbp-files, just as it also creates other files like Makefile, ninja files or whatever. If Server-Mode is available, then Creator will still use that and ask CMake directly for information and will not read any file CMake created.

    You can set the generator and extra generator in tools > options > kits now. It should be safe to deselect the codeblocks extra generator there (or select any other generator) -- provided your CMake supports Server-Mode.

    CMake 3.5.2 actually should not support -E capabilities at all and will most likely just error out:-) IIRC that only became available in 3.7, together with server mode.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.