Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Cmake with Qt Creator

Tags:

I would like to use Qt creator and Cmake together (please, don't ask me about my motivation, accept this as a given.)

I successfully set up Qt creator to use cmake "Cmake": see this, this and this documents regarding how I did that.

I successfully create hello world project, but I can't create files in project, only add existing files to project tree and after that adding it to cmake list. Standard operation of Qt creator "Add New..." doesn't work and I can't find why.

Is there anybody who uses Qt creator and "Cmake" together? Is the combination actually possible?

Note: I'm using Qt creator v2.4.1.

like image 854
themean Avatar asked Feb 23 '12 15:02

themean


People also ask

Does Qt Creator support CMake?

You can use CMake from Qt Creator to build applications for the desktop, as well as mobile and embedded devices. You can also build single files to test your changes. Qt Creator automatically detects the CMake executable specified in the PATH .

Should I use CMake or Qmake?

You can use CMake to build Qt projects, so either works if you're a Qt developer. If you're looking for a simple build experience with QtCreator, you can't go wrong with QMake. For more complex building tasks, CMake may be a better choice.

What is CMake Qt GUI?

Qt based user interface for CMake (cmake-gui) CMake is used to control the software compilation process using simple platform and compiler independent configuration files. CMake generates native makefiles and workspaces that can be used in the compiler environment of your choice.


2 Answers

You can add files using glob expression in your CMakeLists.txt, like this:

file(GLOB SRC . *.cpp) add_executable (your_exe_name ${SRC}) 

Cmake will pick your new cpp files next time you run it and QtCreator will show them in the project browser.

Update

This solution may be useful but as noted in comments - this is not a good practice. Every time somebody add new source file and commit changes, you need to rerun cmake to build all the sources. Usually I just touch one of the CMakeLists.txt files if my build is broken after I pool recent changes from repository. After that make will run cmake automatically and I didn't need to run it by hands. Despite of that I think that explicit source lists in CMakeLists.txt is a good thing, they called thing CMake Lists for a reason.

like image 145
Evgeny Lazin Avatar answered Oct 01 '22 16:10

Evgeny Lazin


When you add new files in QtCreator using the "New File or Project..." dialog it only creates the files on disk, it doesn't automatically add the files to the CMakeLists.txt. You need to do this by hand by editing the CMakeLists.txt file.

The next time you build the project, CMake will be re-run, and QtCreator will pick up the new files and show them in the project browser.

like image 45
alanxz Avatar answered Oct 01 '22 15:10

alanxz