Qt Creator 17 - CMake Update

Here are the new CMake changes in Qt Creator 17:

find_package dependency provider

Qt Creator implements a find_package() dependecy provider as part of the package manager auto-setup feature.

This dependency provider checks every find_package() CMake call for required Qt components. If a Qt component is not installed, Qt Maintenance Tool will be started to install the required component.

See below the setup of the Dice example when configured on a system that lacks Qt Multimedia.

qt-creator-17-cmake-find-package-dependency

By default Qt Maintenance Tool will be started in GUI mode. By setting QT_CREATOR_MAINTENANCE_TOOL_PROVIDER_USE_CLI to ON then the CLI mode from Qt Maintenance Tool will be used. This mode will install components without asking the user.

Qt CMake component setup

When using a C++ header from an installed Qt compoment, but which is not available due to the lack of build system setup, Qt Creator will issue a fix-it that would add the in the build system the required configuration.

In case for Qt Multimedia and CMake this is the equivalent:

find_package(Qt6 REQUIRED COMPONENTS Multimedia)
target_link_libraries(WidgetsDemo PRIVATE Qt6::Multimedia)

 

qt-creator-17-cmake-add-qt-component

CMake Presets kits with proper 'Run device'

Given the Android CMake preset below:

{
  "version": 4,
  "cmakeMinimumRequired": {
    "major": 3,
    "minor": 23,
    "patch": 0
  },
  "configurePresets": [
    {
      "name": "android-clang-arm64",
      "displayName": "Android Clang Arm64",
      "binaryDir": "${sourceDir}/build-${presetName}",
      "generator" : "Ninja",
      "cacheVariables": {
        "QT_HOST_PATH" : "C:/QtArm64/6.8.3/msvc2022_arm64",
        "CMAKE_PREFIX_PATH" : "C:/QtArm64/6.8.3/android_arm64_v8a",
        "CMAKE_FIND_ROOT_PATH" : "C:/QtArm64/6.8.3/android_arm64_v8a",
        "ANDROID_PLATFORM" : "android-31",
        "ANDROID_STL": "c++_shared",
        "ANDROID_ABI" : "arm64-v8a",
        "ANDROID_SDK_ROOT": "C:/Tools/Android/Sdk",
        "ANDROID_NDK" : "C:/Tools/Android/Sdk/ndk/26.1.10909125",
        "CMAKE_TOOLCHAIN_FILE": "C:/Tools/Android/Sdk/ndk/26.1.10909125/build/cmake/android.toolchain.cmake"
      }
    }
  ]
}

... after configuring the project, the resulting Kit will have an Android device selected for 'Run Device'.

qt-creator-17-android-preset-kit

More feature parity with QMake projects

This time is about the %{Project:Name} Qt Creator macro. Previous Qt Creator versions would set the parent project directory as the %{Project:Name} since the project name is not part of the project file name. All project files are named CMakeLists.txt, unlike project.pro for qmake.

Qt Creator 17 will parse the CMakeLists.txt after the project() CMake function call and use that for %{ProjectName}.

qt-creator-17-project-name

 


Blog Topics:

Comments