Qt Creator 13 - CMake Update

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.

Windows long path workaround

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.

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

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

<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).

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.

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.

Hello World

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

qtcreator-13-longpath-failing

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

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

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

qtcreator-13-longpath-success

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.

Set the QTC_CMAKE_JUNCTIONS_HASH_LENGTH environment variable to shorten the MD5 hash key length from the default length value of 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:

<?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.

CMake Presets Kits

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.

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

{
  "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"
      }
    }
  ]
}

qtcreator-13-only-preset-kits

CMake output parsing

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.

Consider this CMakeLists.txt project file:

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)

qtcreator-13-cmake-output-error-parsing

 


Blog Topics:

Comments