CMake performance difference: --build --preset vs. --build dir

1.2k Views Asked by At

I have a CMake solution with ~1.5K C/C++ projects/subdirs and I wanted to use CMake presets. This is my CMakePresets.json:

{
    "version": 3,
    "cmakeMinimumRequired": {
        "major": 3,
        "minor": 20,
        "patch": 1
    },
    "configurePresets": [
        {
            "name"          : "base"                                ,
            "displayName"   : "Base Config Preset"                  ,
            "description"   : "Base config using VS2019"            ,
            "generator"     : "Visual Studio 16 2019"               ,
            "architecture"  : {"value":"Win32", "strategy":"set"}   ,
            "binaryDir"     : "G:/.bld"                             ,
            "installDir"    : "G:/.dst"
        }
    ],
    "buildPresets": [
        {
            "name"              : "base"                                            ,
            "displayName"       : "Base Build Preset"                               ,
            "description"       : "base build preset"                               ,
            "jobs"              : 0                                                 ,
            "cleanFirst"        : true                                              ,
            "verbose"           : false                                             ,
            "configurePreset"   : "base"
        }
    ]
  }

I observed a significant duration difference (~40%) between the following 2 approaches (both were run in an identical clean context):

  1. Using classic folder syntax to build
cmake --preset=base
cmake --build G:\.bld -j
  1. Using new preset syntax to build
cmake --preset=base
cmake --build --preset=base -j

Both perform similar during CMake config & generate step. The difference appears during build step, after the Microsoft's header is displayed:

Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

Approach 1. does not have any delay until it displays the following output lines. Total time is ~14 minutes

Approach 2. has 5-6 minutes delay before showing next lines from output (but the CPU is under load). The Microsoft's header is displayed again then everything continues normally. Total time is ~20 minutes

The duration difference seems to be, more or less, that initial delay, when nothing is displayed

Shouldn't they be identical? Could be a bug in CMake or I do something wrong?

OS: Windows 10 64bit, cmake version 3.21.2

1

There are 1 best solutions below

0
starball On

This was due to the inclusion of cleanFirst": true in the build preset, which causes --cleanFirst to be passed for build.