2

In the Qt Creator 2.8 documentation (now defunct, alternative link here) there is a screenshot showing a wizard dialog where I can pass CMake command line arguments:

The screenshot below shows how you can specify command line arguments to CMake for your project.

CMake Wizard screenshot

Is there a way to make these settings not there, but in a CMakeLists.txt file?

For example, if I want a project to compile in release, every time I have to type -DCMAKE_BUILD_TYPE=Release into this dialog. How can I set that I want the project to build in release mode in a CMakeLists.txt file?

2
  • Possible duplicate of QtCreator 4 and CMake parameters Commented Nov 8, 2017 at 10:12
  • Consider changing title as it is misleading: the question and answers are about setting CMake variables rather than passing command line arguments (switches) to cmake executable Commented Jan 30, 2020 at 15:50

4 Answers 4

4

Before QtC 4 just pass it as string when you build the CMakeLists.txt.

Since QtC 4 "Tools" > "Options" > "Build & Run" > "Your kit" > "CMake configuration"

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

Sign up to request clarification or add additional context in comments.

Comments

1

Starting with Qt Creator 4, you can set CMake configuration variables in the project settings as follows:

  1. Open the "Projects" sidebar tab and there go to "Build & Run → (your build config) → Build → CMake".

  2. In the table of CMake configuration settings, check if the variable you want to define already exists. If so, double-click on its value and change it.

  3. If the variable does not yet exist, click Add, select the type, then add its name and value.

    If you need to assign multiple values to your variable, separate them with ";". That is equivalent to how CMake defines multi-value lists.

  4. Click the button "Apply Configuration Changes" below the list.

While it is also possible to make these settings in your CMakeLists.txt makefile, that is better avoided for configuration settings specific to just your machine. That way, you can include the CMakeLists.txt into your source code repository because one version is suitable for all developers then.

Comments

0

A few comments. Because cmake will cache the build type, you only need to set it when you change it. I use QtCreator on Linux with cmake and typically I either: 1) have separate build trees for a Release and Debug build, or 2) build everything as Release and then use Whitt's approach to set the build type to Debug for the few projects I need to interactively debug. When I have completely different build trees, I use QtCreator with the debug config, and then just use a terminal to build the release.

Comments

-1

SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCMAKE_BUILD_TYPE=Release")

Try something like that in your CMakeLists.txt.

1 Comment

Build type does not belong in your CMakeLists.txt file.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.