Qt Creator 10-CMake更新

Qt Creator 10 - CMake update

Qt Creator 10-CMake更新

March 30, 2023 by Cristian Adam | Comments

​2023年3月30日:Cristian Adam |评论

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

​现在Qt Creator 10已经发布,是时候强调CMake的变化了。

“include” CMake presets

“include”CMake预设

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

​CMake预设中的“include”字段是CMakePresets版本4的一部分。也支持CMakePreset版本5中的pathListSep字段。

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

通过这种方式,我能够将Visual C++Ninja预设的细节隐藏到msvc.json文件中。

Now the CMakePresets.json looks like this:

现在,CMakePresets.json看起来是这样的:

{
  "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:

现在是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:

在Windows 11 Arm64笔记本电脑上进行的屏幕投影:

“external” strategy for Visual C++ Presets

Visual C++预设的“扩展”策略

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.

Visual C++预设的“外部”策略意味着Qt Creator需要找到合适的vcvarsall.bat,并为CMake设置环境。

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

这样,就不必指定INCLUDE、LIB和PATH环境变量。

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:

屏幕投影如下:

Build environment variables

生成环境变量

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

Qt Creator 9引入了对CMake预设的支持,这需要一个用于CMake配置步骤的环境。

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.

不幸的是,对于不使用CMake预设的项目,此功能打破了在构建环境中设置环境变量并使其可用于CMake配置步骤的现有工作流程。

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

Qt Creator 10修复了这一问题,如下屏幕所示:

Package manager auto-setup

包管理器自动设置

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

​Qt Creator 9默认情况下禁用了CMake包管理器的自动设置。

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重新启用了它,但也解决了首次禁用auto-setup.cmake文件中的,Qt Creater路径使用。当Qt Creaator版本更新,旧的Qt Creator被删除时,这将破坏cmake项目。

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!

Qt Creator 10会将auto-setup.make文件复制到<build-dir>/.qtc/package manager目录中。这将独立于Qt Creator的版本,也将在远程配置中工作!

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

下面是在Windows 11 Arm64上使用vcpkg libfmt的屏幕截图:

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

​Conan还更新了cmake-Conan/develop2分支的实验代码。

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

Qt Creator 10同时支持conan 1.5x和2.0版本!

cmake-format

cmake格式

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

​CMake在上游有一个问题,命名为CMake语言的格式化工具。它仍然处于开放状态。

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!

​Xavier Besson以与Beautifier插件和clang格式类似的方式添加了对CMake格式的支持,为CMake文件贡献了一个Beautifieer。非常感谢。

All one have to do is:

所要做的就是:

$ pip3 install cmake-format

You can see it in action below:

可以在下面看到它的作用:

CMake settings page

CMake设置页面

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

Qt Creator的第10个设置页面,第一个选项卡如下所示:

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

在那里,你可以看到Autorun CMake。这已经成为一个全局设置。这曾经是为每个CMake工具单独配置的。

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

​Alexander Pershin提供了“默认显示高级选项”复选框。非常感谢。

Case-insensitive “cmo” locator

不区分大小写的“cmo”定位器

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:

cmo定位器现在不区分大小写。现在,可以打开CMakeProjectManager的CMakeLists.txt文件,只需在定位器窗口中键入cmo cmakepr,如下屏幕所示:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值