Qt Creator 5 - CMake projects update

Qt Creator 5 comes with bug fixes and new features that affect CMake projects.

CMake output in Projects mode

When configuring CMake projects in Projects mode now you can see the output of the CMake command.

Besides seeing the output you can also filter the output messages as seen in the screencast below:

qtcreator-cmake-configure-projects-mode

Compile output in Projects mode

Now you can see the compilation output in Projects mode, there is no more need to switch between “Projects” and “Edit” mode to see the compilation output.

qtcreator-build-output-projects-mode

No more temporary build directory

Qt Creator 5 doesn’t use a temporary directory for the initial project configuration. This means that for bigger projects, you don’t have to configure the project twice to get it right.

This behavior was previously opt-in in settings by checking the “Auto-create build directories” check box.

qtcreator-cmake-build-dir

Build directory is no longer read-only

Qt Creator 4.13 made the build directory edit field read-only due to build directories created for every letter typed when “Auto-create build directories” setting was enabled.

Qt Creator 5 enables you to edit the build directory and the directory is created only when you finish editing.

qtcreator-cmake-build-dir-edit

Hide Source and Header groups

Now you can have the source and header files without the extra tree level of “Header Files” and “Source Files”. This can be configured as seen below:

qtcreator-hide-header-source-groups

Selecting a default run target

Qt Creator itself has multiple executables, but when you run the project you would just want to run “qtcreator” and not the first executable in the list.

With Qt Creator 5, you can set the FOLDER property with the qtc_runnable value and Qt Creator will only create run configurations for these targets when you first open the project in Qt Creator. You are still able to create run configurations manually for other executable targets any time after that. It only influences which run configurations Qt Creator creates by default.

In your CMakeLists.txt you need to have something like:

set_target_properties(main_executable PROPERTIES FOLDER "qtc_runnable")

Note: The FOLDER property that Qt Creator uses for this is not intended for this use-case by CMake.
FOLDER is used for example by Visual Studio to visually sort targets into folders in the IDE.
So, do not use this feature for qtc_runnable, if this creates a conflict of usage in your project.

No more QT_QMAKE_EXECUTABLE warning

Qt Creator is setting a few CMake variables when configuring a project. If the variables are not referenced, CMake is showing a warning.

Now these variables are referenced in the package-manager/auto-setup.cmake CMake file that gets injected via the CMAKE_PROJECT_INCLUDE_BEFORE parameter and CMake will no longer emit those warnings.

Macro support for Execute Custom Commands

Locator’s “Execute Custom Commands” option got support for macros.

This means that if you want to delete the active project’s build directory you can do:

! cmake -E rm -rf %{ActiveProject:BuildConfig:Path}

Or if you want to run ctest for the active project (CMake 3.20+):

! ctest --test-dir %{ActiveProject:BuildConfig:Path}

qtcreator-custom-command

 


Blog Topics:

Comments