CMakePresets should it automatically create build folder?

I was surprised that CMakePresets does not automatically create the build folder.
Since presets are trying to simplify the CMake process should this be the case?

❯ cmake --build --preset debug --target check-stablehlo-ci

Error: /usr/.../github.com/openxla/stablehlo/build is not a directory
❯ cmake --version
cmake version 3.28.1

CMake suite maintained and supported by Kitware (kitware.com/cmake).

Maybe i’m confused – I would have expected the build preset to also configure the project since I inherit from my configure preset.

{
    "version": 6,
    "configurePresets": [
        {
          "name": "debug",
          "displayName": "Debug w/ ccache",
          "generator": "Ninja",
          "binaryDir": "build/",
          "cacheVariables": {
            "CMAKE_BUILD_TYPE": "Debug",
            "LLVM_ENABLE_ASSERTIONS": "ON",
            "LLVM_ENABLE_LLD": "ON",
            "STABLEHLO_ENABLE_BINDINGS_PYTHON" : "OFF",
            "CMAKE_CXX_COMPILER_LAUNCHER": "ccache",
            "CMAKE_CXX_COMPILER": "clang++",
            "CMAKE_C_COMPILER_LAUNCHER": "ccache",
            "CMAKE_C_COMPILER": "clang",
            "CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
            "CMAKE_PLATFORM_NO_VERSIONED_SONAME": "ON",
            "LLVM_VERSION_SUFFIX": "",
            "LLVM_USE_SPLIT_DWARF": "ON",
            "STABLEHLO_ENABLE_SPLIT_DWARF": "ON"
          }
        },
        {
          "name": "debug-python",
          "displayName": "Debug w/ python bindings",
          "inherits": "debug",
          "cacheVariables": {
            "MLIR_ENABLE_BINDINGS_PYTHON": "ON",
            "STABLEHLO_ENABLE_BINDINGS_PYTHON" : "ON",
            "STABLEHLO_ENABLE_SANITIZER": "OFF"
          }
        }
      ],
      "buildPresets": [
        {
          "name": "debug",
          "displayName": "Build Debug",
          "configurePreset": "debug"
        },
        {
          "name": "debug-python",
          "displayName": "Build Debug w/ python bindings",
          "configurePreset": "debug-python"
        }
    ]
}

Does the --build --preset command re-configure the project but assumes it’s configured prior at least once?

Did you run cmake --preset debug first to configure the project? The way I use it is that I first run cmake --preset xyz once to configure the project, then repeatedly use cmake --build --preset xyz to build the project.

The --build --preset will not rerun cmake directly to reconfigure. Most generators will make a dependency on CMake files to rerun cmake automatically. But some projects may have dependencies that don’t get detected so you need to run cmake --preset manually to reconfigure.

There is also something called workflow presets, but I haven’t used them.

Yes I am trying workflow – I just find it confusing that a build preset must link to a configure preset in the JSON file.

What if they conflict ?
What’s the point of build preset just to set the targets ?

Here is my latest:

{
    "version": 6,
    "configurePresets": [
        {
          "name": "debug",
          "displayName": "Debug w/ ccache",
          "generator": "Ninja",
          "binaryDir": "build/",
          "cacheVariables": {
            "CMAKE_BUILD_TYPE": "Debug",
            "LLVM_ENABLE_ASSERTIONS": "ON",
            "LLVM_ENABLE_LLD": "ON",
            "STABLEHLO_ENABLE_BINDINGS_PYTHON" : "OFF",
            "CMAKE_CXX_COMPILER_LAUNCHER": "ccache",
            "CMAKE_CXX_COMPILER": "clang++",
            "CMAKE_C_COMPILER_LAUNCHER": "ccache",
            "CMAKE_C_COMPILER": "clang",
            "CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
            "CMAKE_PLATFORM_NO_VERSIONED_SONAME": "ON",
            "LLVM_VERSION_SUFFIX": "",
            "LLVM_USE_SPLIT_DWARF": "ON",
            "STABLEHLO_ENABLE_SPLIT_DWARF": "ON"
          }
        },
        {
          "name": "debug-python",
          "displayName": "Debug w/ python bindings",
          "inherits": "debug",
          "cacheVariables": {
            "MLIR_ENABLE_BINDINGS_PYTHON": "ON",
            "STABLEHLO_ENABLE_BINDINGS_PYTHON" : "ON",
            "STABLEHLO_ENABLE_SANITIZER": "OFF"
          }
        }
      ],
      "buildPresets": [
        {
          "name": "debug",
          "displayName": "Build Debug",
          "configurePreset": "debug",
          "targets": ["check-stablehlo-ci"]
        },
        {
          "name": "debug-python",
          "displayName": "Build Debug w/ python bindings",
          "configurePreset": "debug-python",
          "targets": ["check-stablehlo-ci"]
        }
    ],
    "workflowPresets": [
      {
        "name": "debug",
        "displayName": "Configure, Debug & Test",
        "steps": [
          {
            "type": "configure",
            "name": "debug"
          },
          {
            "type": "build",
            "name": "debug"
          }
        ]
      }
    ]
}

There’s much history behind the questions you’re asking. The short version is that when presets were first conceived, it was driven by IDE vendors (one in particular). The expectation at the time was that build presets would be the primary thing users would select for their builds. A build preset needed to be associated with a configure preset so that the build directory would be known, and the IDE would know how to set it up.

Since then, it has emerged that configure presets are the primary thing users tend to want to use in an IDE. Build presets have proven to be problematic because of the requirement that they have a one-to-one mapping to a configure preset. This results in a combinatorial explosion of build presets for all the different combination of things developers might want to have presets for. This has been discussed at length (see issue 22538), so I’ll leave you to trawl through those discussions to get the full background and latest details.

2 Likes