Qt Creator 13-CMake更新

Qt Creator 13 - CMake Update

Qt Creator 13-CMake更新

April 05, 2024 by Cristian Adam | Comments

​2024年4月5日:Cristian Adam |评论

Here is a set of highlighted CMake features and fixes in Qt Creator 13. Have a look at the ChangeLog for all the CMake changes.

​以下是Qt Creator 13中一组突出显示的CMake功能和修复程序。查看所有CMake更改的ChangeLog。

Windows long path workaround

Windows长路径解决方法

Windows has had support for long paths (>255 characters) since Windows 10 version 1607 released on August 2015. But the applications needed to opt-in in order to use the new functionality.

​自2015年8月发布的Windows 10版本1607以来,Windows一直支持长路径(>255个字符)。但应用程序需要选择加入才能使用新功能。

Applications that used the W Win32 API functions like CreateDirectoryWCreateFileWFindFirstFileW would work out of the box, like for example the LLVM Clang compiler.

使用W Win32 API函数的应用程序,如CreateDirectoryW、CreateFileW、FindFirstFileW,将开箱即用,例如LLVM Clang编译器。

The rest of the applications need the Registry key KEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled set to 1 and the:

其余的应用程序需要注册表项KEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled设置为1,并且:

<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>

part in the application manifest.

部分在应用程序清单中。

Unlike GCC, the Visual C++ compiler cannot be fixed by updating the application manifest. The issue is being considered but not yet fixed (April 2024).

​与GCC不同,Visual C++编译器不能通过更新应用程序清单来修复。该问题正在考虑中,但尚未解决(2024年4月)。

The Ninja build system has been fixed but the 1.12.0 release has not yet been made. The latest release was v1.11.1 on Aug 30, 2022.

​Ninja构建系统已经修复,但1.12.0版本尚未发布。最新版本是2022年8月30日发布的v1.11.1。

At QTCREATORBUG-26786, there is an issue compiling Qt Creator itself. At QTBUG-117413, there is a bug report with a broader Qt application issue.

​在QTCREATORBUG-26786中,编译Qt Creator本身时出现问题。在QTBUG-117413中,有一个错误报告,涉及更广泛的Qt应用程序问题。

Hello World

Below, you have a screen cast of a Hello World C++ application located in a long path C:\Projects\ThisPathWasArtificiallyMadeLongInOrderToTestHowAWindowsCompilerWouldBehaveWhenHavingAPathLongerThanWhatMAXPATHIsAllowingNamelyLongerThan255Characters.

下面是Hello World C++应用程序的屏幕截图,该应用程序位于长路径C:\Projects\ThisPathWasArtificialyMadeLongInOrderToTestHowAWindowsCompilerWouldBehaveWhenHavingAPathLongerHanWhatMAXPATHIsAllowingNamelyLongerHan255个字符中。

The project cannot be configured by CMake, it fails at compiler detection.

CMake无法配置该项目,它在编译器检测时失败。

The usual advice is to either use shorter paths like c:\dev or to use subst.

​通常的建议是要么使用较短的路径,如c:\dev,要么使用subst。

Qt Creator 13 comes with a different workaround, namely to use junctions for source and build directory.

​QtCreator 13提供了一个不同的解决方法,即使用源和构建目录的连接。

Notice that the executable being ran or debugged has the full path. Junctions are only used for configuring and building the project.

请注意,正在运行或调试的可执行文件具有完整路径。连接仅用于配置和构建项目。

Qt Creator stores junction points in C:\ProgramData\QtCreator\Links. To use another path, set it as the value of the QTC_CMAKE_JUNCTIONS_DIR environment variable.

Qt Creator将连接点存储在C:\ProgramData\Qt Creator\Links中。要使用另一个路径,请将其设置为QTC_CMAKE_JUNCTIONS_DIR环境变量的值。

Set the QTC_CMAKE_JUNCTIONS_HASH_LENGTH environment variable to shorten the MD5 hash key length from the default length value of 32.

设置QTC_CMAKE_JUNCTIONS_HASH_LENGTH环境变量以将MD5哈希密钥长度从默认长度值32缩短。

The usage of junctions is not enabled by default. Their usage can be enabled globally in the CMake settings or per project via a CMakeLists.txt.shared file in the source directory with the following content:

默认情况下,不会启用连接的使用。它们的使用可以在CMake设置中全局启用,也可以通过源目录中具有以下内容的CMakeLists.txt.shared文件按项目启用:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<qtcreator>
  <data>
  <variable>ProjectExplorer.Project.PluginSettings</variable>
  <valuemap type="QVariantMap">
   <valuelist type="QVariantList" key="ProjectExplorer.Project.Environment">
    <value type="QString">QTC_CMAKE_USE_JUNCTIONS=1</value>
   </valuelist>
  </valuemap>
 </data>
 <data>
  <variable>Version</variable>
  <value type="int">22</value>
 </data>
</qtcreator>

QTCREATORBUG-30385 tracks the task of having a CMakePresets option to enable junctions. This will be part of a future Qt Creator version.

QTCREATORBUG-30385跟踪使用CMakePresets选项启用交叉点的任务。这将是未来Qt Creator版本的一部分。

CMake Presets Kits

CMake预设套件

If a project uses CMakePresets, the configuration page will only show the Presets Kits. Regular Kits could still be selected from the left Kit list.

如果项目使用CMakePresets,则配置页面将仅显示预设套件。常规套件仍然可以从左侧的套件列表中选择。

For example, the following Preset configures a Visual C++ 2022 Arm64 Kit with Arm64 CMake and Ninja tools:

例如,以下预设使用Arm64 CMake和Ninja工具配置Visual C++2022 Arm64套件:

{
  "version": 4,
  "configurePresets": [
    {
      "name": "visualc-arm64",
      "displayName": "Visual C++ 2022 Arm64",
      "generator": "Ninja",
      "binaryDir": "${sourceDir}/build-release",
      "cmakeExecutable": "C:/Program Files/CMake/bin/cmake.exe",
      "toolset": {
        "value": "v143,host=arm64",
        "strategy": "external"
      },
      "architecture": {
        "value": "arm64",
        "strategy": "external"
      },
      "cacheVariables": {
        "CMAKE_BUILD_TYPE": "Release",
        "CMAKE_PREFIX_PATH": "C:/Qt/6.6.0/msvc2022_arm64",
        "CMAKE_MAKE_PROGRAM": "C:/Tools/Ninja/ninja.exe",
        "CMAKE_C_COMPILER": "cl.exe",
        "CMAKE_CXX_COMPILER": "cl.exe"
      }
    }
  ]
}

CMake output parsing

CMake输出解析

There are cases when compiler warnings and errors are produced during a CMake configuration step. Now, these compiler warnings and errors will be shown in the Issues pane.

在某些情况下,在CMake配置步骤中会产生编译器警告和错误。现在,这些编译器警告和错误将显示在“问题”窗格中。

Consider this CMakeLists.txt project file:

考虑以下CMakeLists.txt项目文件:

cmake_minimum_required(VERSION 3.5)

project(HelloWeirdWorld LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/main.cpp [[
    #include <iostream>

    .

    int main()
    {
        std::cout << "Hello World!" << std::endl;
        return 0;
    }
]])

execute_process(
    COMMAND ${CMAKE_CXX_COMPILER} main.cpp -o main.exe)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值