# Condition field for workflow presets

**URL:** https://discourse.cmake.org/t/condition-field-for-workflow-presets/6934
**Category:** Development
**Created:** [November 23, 2022, 5:53am UTC](https://discourse.cmake.org/t/condition-field-for-workflow-presets/6934 "2022-11-23T05:53:55Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![benthevining](https://discourse.cmake.org/user_avatar/discourse.cmake.org/benthevining/32/1924_2.png) [@benthevining](https://discourse.cmake.org/u/benthevining)
#### Post date: [November 23, 2022, 5:53am UTC](https://discourse.cmake.org/t/condition-field-for-workflow-presets/6934/1 "2022-11-23T05:53:55Z")

</div>

Workflows presets don’t currently have a `condition` field, which is unfortunate. Some workflows may consist of platform-specific presets, such as building for XCode or Visual Studio.

I suggest either:

- giving workflow presets a condition field
- calculating which workflow presets are unavailable based on each step preset’s condition(s)

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 23, 2022, 11:24pm UTC](https://discourse.cmake.org/t/condition-field-for-workflow-presets/6934/2 "2022-11-23T23:24:31Z")

</div>

The former makes more sense to me. Maybe one wants to skip a step in some situation (e.g., testing for `clang-tidy`?) and having to do a new workflow for that seems a bit unfortunate.

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [November 24, 2022, 10:17pm UTC](https://discourse.cmake.org/t/condition-field-for-workflow-presets/6934/3 "2022-11-24T22:17:10Z")

</div>

Having a workflow silently skip steps for which a condition is false seems attractive at first, but I would have concerns about the robustness of that. Giving workflow presets as a whole a condition field would be less risky.

---

<div class="post-metadata">

### Author: ![benthevining](https://discourse.cmake.org/user_avatar/discourse.cmake.org/benthevining/32/1924_2.png) [@benthevining](https://discourse.cmake.org/u/benthevining)
#### Post date: [November 25, 2022, 1:49am UTC](https://discourse.cmake.org/t/condition-field-for-workflow-presets/6934/4 "2022-11-25T01:49:46Z")

</div>

If workflows are going to allow but skip steps that have false conditions, then I would suggest that CMake exits with a success code if at least the configure preset had a true condition, and exits with a failure code otherwise.

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [August 4, 2023, 5:25am UTC](https://discourse.cmake.org/t/condition-field-for-workflow-presets/6934/5 "2023-08-04T05:25:40Z")

</div>

### IMHO: It is a bug, if the workflow preset does not inherit the condition of its configure preset:

```auto
bash-3.2$ cmake --workflow --list-presets
Available workflow presets:

  "windows-clang-debug"
  "windows-clang-release"
  "clang-debug"
  "clang-release"
  "gcc-debug"
  "gcc-release"
bash-3.2$ cmake --list-presets
Available configure presets:

  "gcc-debug" - gcc Debug
  "gcc-release" - gcc Release
  "clang-debug" - clang Debug
  "clang-release" - clang Release
bash-3.2$ cmake --workflow --preset=windows-clang-debug
CMake Error: Cannot use disabled configure preset in /Users/clausklein/Workspace/cmake/project_options/examples/cpp_vcpkg_project: "windows-clang-debug"
bash-3.2$ 

```

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [August 4, 2023, 7:39am UTC](https://discourse.cmake.org/t/condition-field-for-workflow-presets/6934/6 "2023-08-04T07:39:57Z")

</div>

### A conditionally disabled preset should be allowed to have a duplicate name

```auto
bash-3.2$ !json
jsonschema -i CMakePresets.json schema.json 
bash-3.2$ jsonschema -i CMakePresets.json schema.json 
bash-3.2$ cmake --workflow --list-presets
CMake Error: Could not read presets from /Users/clausklein/Workspace/cmake/project_options/examples/cpp_vcpkg_project:
Duplicate preset: "clang-install"
bash-3.2$ 

```

That would help to write simple and clear `CMakePresets.json`.

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [August 4, 2023, 4:56pm UTC](https://discourse.cmake.org/t/condition-field-for-workflow-presets/6934/7 "2023-08-04T16:56:23Z")

</div>

@craig.scott @ben.boeckel Is it planed to change this behaviour?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [August 7, 2023, 11:23am UTC](https://discourse.cmake.org/t/condition-field-for-workflow-presets/6934/8 "2023-08-07T11:23:59Z")

</div>

I’m not that familiar with presets. @kyle.edwards would know more.

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [August 18, 2023, 1:00pm UTC](https://discourse.cmake.org/t/condition-field-for-workflow-presets/6934/9 "2023-08-18T13:00:25Z")

</div>

> **[Organizing CMake presets](https://dominikberner.ch/cmake-presets-best-practices/)**
>
> CMake presets are a big help in how to configure CMake. This article shows how to set up and organize them.

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [February 1, 2024, 3:08pm UTC](https://discourse.cmake.org/t/condition-field-for-workflow-presets/6934/10 "2024-02-01T15:08:13Z")

</div>

see too [Presets - conditional config](https://discourse.cmake.org/t/presets-conditional-config/3864)

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [February 2, 2024, 11:36am UTC](https://discourse.cmake.org/t/condition-field-for-workflow-presets/6934/11 "2024-02-02T11:36:46Z")

</div>

I have created an [issue](https://gitlab.kitware.com/cmake/cmake/-/issues/25654)

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [April 2, 2024, 7:17pm UTC](https://discourse.cmake.org/t/condition-field-for-workflow-presets/6934/12 "2024-04-02T19:17:25Z")

</div>

I used a Workaround possible with `cmake preset schema version 9`

see

- [Error: @4,9: Invalid "include" field in CMake Preset - #2 by ClausKlein](https://discourse.cmake.org/t/error-4-9-invalid-include-field-in-cmake-preset/10554/2)
- [Feature/add cmake workflow presets by ClausKlein · Pull Request #1 · ClausKlein/cpp\_vcpkg\_project · GitHub](https://github.com/ClausKlein/cpp_vcpkg_project/pull/1/files#)
