Qt Creator 10 - CMake update

Now that Qt Creator 10 has been released, it’s time to highlight the CMake changes.

“include” CMake presets

The “include” field in CMake presets is part of CMakePresets version 4. pathListSep field from CMakePresets version 5 is also supported.

This way, I was able to hide the nitty gritty details of the Visual C++ Ninja preset into an msvc.json file.

Now the CMakePresets.json looks like this:

{
"version": 4,
"include": [ "msvc.json" ],
"configurePresets": [
{
"name": "visualc-ninja",
"displayName": "Visual C++ 2022 arm64 Ninja",
"inherits": "visualstudio-2022-preview",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build-${presetName}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_PREFIX_PATH": "C:/Qt/6.4.0/msvc2019_arm64"
},
"environment" : {
"VCToolsVersion": "14.36.32502",
"WindowsSDKVersion" : "10.0.22621.0",
"VCArch": "arm64",
"VCHostArch": "HostARM64"
}
}
],
"buildPresets": [
{
"name": "visualc-ninja",
"configurePreset": "visualc-ninja"
}
]
}

And now for the msvc.json:

{
"version": 4,
"configurePresets": [
{
"name": "visualstudio-2022-preview",
"hidden": true,
"cacheVariables": {
"CMAKE_C_COMPILER": "cl.exe",
"CMAKE_CXX_COMPILER": "cl.exe"
},
"environment" : {
"VCToolsInstallDir": "$env{ProgramFiles}/Microsoft Visual Studio/2022/Preview/VC/Tools/MSVC/$env{VCToolsVersion}",
"WindowsSdkDir" : "$env{ProgramFiles(x86)}/Windows Kits/10",
"WindowsSdkIncVerDir": "$env{WindowsSdkDir}/Include/$env{WindowsSDKVersion}",
"WindowsSdkLibVerDir": "$env{WindowsSdkDir}/Lib/$env{WindowsSDKVersion}",
"INCLUDE": "$env{VCToolsInstallDir}/ATLMFC/include;$env{VCToolsInstallDir}/include;$env{WindowsSdkIncVerDir}/ucrt;$env{WindowsSdkIncVerDir}/shared;$env{WindowsSdkIncVerDir}/um;$env{WindowsSdkIncVerDir}/winrt;$env{WindowsSdkIncVerDir}/cppwinrt",
"LIB": "$env{VCToolsInstallDir}/ATLMFC/lib/$env{VCArch};$env{VCToolsInstallDir}/lib/$env{VCArch};$env{WindowsSdkLibVerDir}/ucrt/$env{VCArch};$env{WindowsSdkLibVerDir}/um/$env{VCArch}",
"PATH": "$env{VCToolsInstallDir}/bin/$env{VCHostArch}/$env{VCArch};$env{WindowsSdkDir}/bin/$env{WindowsSDKVersion}/$env{VCArch};$penv{PATH}"
}
}
]
}

And the screen cast done on a Windows 11 Arm64 laptop:

qtcreator10-presets-v4-include

“external” strategy for Visual C++ Presets

The “external” strategy for Visual C++ presets means that Qt Creator needs to find out the right vcvarsall.bat and have the environment setup for CMake.

This way, one doesn’t have to specify the INCLUDE, LIB and PATH environment variables.

The equivalent preset looks like this:

{
"version": 3,
"configurePresets": [
{
"name": "visualc-ninja",
"displayName": "Visual C++ 2022 arm64 Ninja",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build-${presetName}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_PREFIX_PATH": "C:/Qt/6.4.0/msvc2019_arm64",
"CMAKE_C_COMPILER": "cl.exe",
"CMAKE_CXX_COMPILER": "cl.exe"
},
"architecture": {
"value": "arm64",
"strategy": "external"
},
"toolset": {
"value": "host=arm64,version=14.36.32502",
"strategy": "external"
}
}
],
"buildPresets": [
{
"name": "visualc-ninja",
"configurePreset": "visualc-ninja"
}
]
}

Screen cast below:

qtcreator10-presets-external

Build environment variables

Qt Creator 9 introduced support for CMake presets which required an environment for the CMake configuration step.

Unfortunately, for projects not using CMake presets, this feature broke the existing workflow of setting environment variables in the build environment and having them available for the CMake configuration step.

Qt Creator 10 fixes this as seen in the screen cast below:

qtcreator10-build-environment

Package manager auto-setup

Qt Creator 9 made the CMake package manager auto-setup disabled by default.

Qt Creator 10 enabled it back, but it also fixed the issue for disabling it in the first place – the usage of Qt Creator path for the auto-setup.cmake file. Which would break CMake projects when the Qt Creator version got updated, and the old Qt Creator got removed.

Qt Creator 10 will copy the auto-setup.cmake files into a <build-dir>/.qtc/package-manager directory. This will be independent of the Qt Creator’s version and will also work in remote configurations!

Below you have a screen cast of a vcpkg libfmt usage on a Windows 11 Arm64:

qtcreator10-vcpkg

Conan has also been updated with the experimental code from the cmake-conan/develop2 branch.

Qt Creator 10 supports both, conan 1.5x and 2.0 versions!

cmake-format

CMake has an issue upstream named Formatting tool for CMake language. It is still in an open state.

Xavier Besson has contributed a Beautifier for CMake files by adding support for cmake-format in similar fashion as the Beautifier plug-in and clang-format. Thank you!

All one have to do is:

$ pip3 install cmake-format

You can see it in action below:

qtcreator10-cmake-format

CMake settings page

Qt Creator’s 10 first settings page looks like this:

qtcreator10-cmake-settings

There, you can see Autorun CMake. This has been made a global setting. This used to be individually configurable for every CMake tool.

Alexander Pershin has contributed the Show advanced options by default checkbox. Thank you!

Case-insensitive “cmo” locator

The cmo locator is now case insensitive. Now, I can open the CMakeProjectManager’s CMakeLists.txt file by just typing cmo cmakepr in the Locator window as seen in the screen cast below:

qtcreator10-cmo-lowercase

 


Blog Topics:

Comments