Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QtCreator 4 and CMake parameters

I used to open a CMake-based C++ project with QtCreator and pass my custom CMake command line parameters when configuring the project. In the recent versions of QtCreator (QtCreator 4 to be precise), this does not seem to be possible anymore - QtCreator configures the project with its own set of CMake variables and their default values. This is extremely annoying, because the only way to change the values of certain CMake variables is to click on 'Projects' and modify the variables one by one, which is really tedious. I have the configuration parameters for specific machine and setup on that machine in a text file that I could just paste in the configuration dialog of Qtcreator and then run CMake, but this dialog now disappeared. Do you know if there's a way of passing custom CMake values while opening a new project?

I tried to clean the build directory, remove CMakeLists.txt.user in the source tree, run CMake with my parameters and then open the project with QtCreator. Unfortunately, QtCreator ignores the cached values and generates its own ...

like image 731
Martin Vymazal Avatar asked Apr 13 '16 13:04

Martin Vymazal


People also ask

How do you use CMake Qtcreator?

Qt Creator uses the default CMake if it does not have enough information to choose the CMake to use. To set the selected CMake executable as the default, select Make Default. To remove the selected CMake executable from the list, select Remove. Select the Kits tab to add the CMake tool to a build and run kit.

What is difference between Qmake and CMake?

Both are build systems, but they're not very similar at all. If your project uses Qt, you're probably best off using qmake. CMake is more generic, and fits pretty much any type of project. Both qmake and CMake generate a Makefile, which is read by make to build the project.

What is Qmake and CMake in Qt?

CMake is an alternative to qmake for automating the generation of build configurations. Setting Up Qbs. Qbs is an all-in-one build tool that generates a build graph from a high-level project description (like qmake or CMake do) and executes the commands in the low-level build graph (like make does).

How does CMake find qt5?

In order for find_package to be successful, Qt 5 must be found below the CMAKE_PREFIX_PATH, or the Qt5_DIR must be set in the CMake cache to the location of the Qt5WidgetsConfig. cmake file. The easiest way to use CMake is to set the CMAKE_PREFIX_PATH environment variable to the install prefix of Qt 5.


2 Answers

@Manuel's answer is ideal for me when I have toolkit-specific CMake variables without project-specific variables.

When you have project-specific CMake variables, the options I have seen/used with recent QtCreator versions (~4+) are:

From QtCreator

  • Open the project
  • go to Projects (on left) and select Build Settings
  • Under CMake, use the "Add" button to add new settings
  • "Apply Configuration Changes"
  • "Build" menu, "Run CMake"
  • Notes:
    • if your project updates CMake variables (as most do), you may need to "Apply Configuration Changes" again.
    • if you have enabled the feature to automatically run CMake, it may fire off in the background, further confusing things. This can create chicken and egg situations - boo!

Outside QtCreator

  • Go to the build directory
  • Run CMake with your commands as usual
  • Open QtCreator
  • Open the project
  • Under Projects - Build Settings:
    • Confirm that the "Build directory:" is as expected
    • Confirm that your CMake variables appear in the list of variables

Sadly, I find both of these profoundly unsatisfying...

like image 88
sage Avatar answered Oct 18 '22 08:10

sage


"Tools" > "Options" > "Build & Run" > "Your kit" > "CMake configuration"

Add a line and rebuild. You can go the short way Ctrl+5 (Projects mode) > "Manage Kits...", too.

like image 22
ManuelSchneid3r Avatar answered Oct 18 '22 09:10

ManuelSchneid3r