13
votes

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 ...

3
That is a beta version, it is possible some feature is missing, no ?Boiethios
Yes, it is possible. Or the developers decided to remove it. I don't know ...Martin Vymazal
I think the better way to know it is asking on Qt forum. I do not have this version : is not it a commercial version ? You must have support with it, on this case.Boiethios
It's not a commercial version, but QtCreator compiled from sources on Linux. Maybe I should just wait for the official release - as you say, the feature might be just temporarily disabled.Martin Vymazal
As of Qt Creator 4.1.0, the situation has not changed.normanius

3 Answers

9
votes

"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.

3
votes

@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...

0
votes

Since QtCreator 4.13 it is possible to set CMake parameters per project (finally):

Project > Build Settings > CMake > Initial CMake parameters