# CMake 3.31: Replacement for add\_custom\_command(TARGET ... USES\_TERMINAL)?

**URL:** https://discourse.cmake.org/t/cmake-3-31-replacement-for-add-custom-command-target-uses-terminal/12935
**Category:** Code
**Created:** [November 11, 2024, 9:52am UTC](https://discourse.cmake.org/t/cmake-3-31-replacement-for-add-custom-command-target-uses-terminal/12935 "2024-11-11T09:52:54Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![szhorvat](https://discourse.cmake.org/user_avatar/discourse.cmake.org/szhorvat/32/1906_2.png) [@szhorvat](https://discourse.cmake.org/u/szhorvat)
#### Post date: [November 11, 2024, 9:52am UTC](https://discourse.cmake.org/t/cmake-3-31-replacement-for-add-custom-command-target-uses-terminal/12935/1 "2024-11-11T09:52:54Z")

</div>

CMake 3.31 [complains](https://cmake.org/cmake/help/latest/policy/CMP0175.html) that `USES_TERMINAL` is not valid with `add_custom_command(TARGET...)`

```plaintext
CMake Warning (dev) at etc/cmake/benchmark_helpers.cmake:24 (add_custom_command):
  The following keywords are not supported when using
  add_custom_command(TARGET): USES_TERMINAL.

  Policy CMP0175 is not set: add_custom_command() rejects invalid arguments.
  Run "cmake --help-policy CMP0175" for policy details. Use the cmake_policy
  command to set the policy and suppress this warning.

```

Despite the warning that this argument is “invalid”, it does in fact have an effect. We use it to get terminal output for our benchmarking commands when using Ninja.

What is the supported way to achieve the same (i.e. terminal output for commands) with CMake 3.31? The goal is to add a `benchmark` target, with which we need to associate multiple commands, all of which should produce terminal output.

For reference, here’s our setup:

> <https://github.com/igraph/igraph/blob/f7b77f9e9cb4d670886b7e15e876c5549250befa/etc/cmake/benchmark_helpers.cmake#L24-L30>

> <https://github.com/igraph/igraph/blob/f7b77f9e9cb4d670886b7e15e876c5549250befa/tests/CMakeLists.txt#L19-L26>

---

<div class="post-metadata">

### Author: ![szhorvat](https://discourse.cmake.org/user_avatar/discourse.cmake.org/szhorvat/32/1906_2.png) [@szhorvat](https://discourse.cmake.org/u/szhorvat)
#### Post date: [November 13, 2024, 8:34am UTC](https://discourse.cmake.org/t/cmake-3-31-replacement-for-add-custom-command-target-uses-terminal/12935/2 "2024-11-13T08:34:39Z")

</div>

In short, the question is:

How do I achieve the effect of `USE_TERMINAL` in `add_custom_command(TARGET...)` with CMake 3.31? CMake 3.31 tells me that `USE_TERMINAL` is invalid in this context.

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [November 13, 2024, 3:57pm UTC](https://discourse.cmake.org/t/cmake-3-31-replacement-for-add-custom-command-target-uses-terminal/12935/3 "2024-11-13T15:57:02Z")

</div>

Shouldn’t benchmarks run in a ctest context?

Instead of a post build custom command, you can make it custom target that depends on the target to benchmark and each benchmark encoded in its add\_custom\_command(OUTPUT…)

The output can be a file, e.g. the benchmark log or a dummy file.

---

<div class="post-metadata">

### Author: ![szhorvat](https://discourse.cmake.org/user_avatar/discourse.cmake.org/szhorvat/32/1906_2.png) [@szhorvat](https://discourse.cmake.org/u/szhorvat)
#### Post date: [November 15, 2024, 1:28pm UTC](https://discourse.cmake.org/t/cmake-3-31-replacement-for-add-custom-command-target-uses-terminal/12935/4 "2024-11-15T13:28:25Z")

</div>

I’m still confused about why a working feature seems to have been marked as “invalid”. I assume there must be a direct replacement for it. Is there?

> [@hsattler](#):
>
> Shouldn’t benchmarks run in a ctest context?

I’d rather avoid ctest, which is influenced by the external environment (e.g., `CTEST_PARALLEL_LEVEL`) and can mess up benchmark results by parallelization, unless one is very careful.

Is the only option really to produce a dummy output file?

We’ll surely have to rework benchmarking in the future, but for now I’m just looking to restore functionality with minimum fuss.

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [November 15, 2024, 1:53pm UTC](https://discourse.cmake.org/t/cmake-3-31-replacement-for-add-custom-command-target-uses-terminal/12935/5 "2024-11-15T13:53:26Z")

</div>

There is a property to avoid that a specific test runs in parallel.

---

<div class="post-metadata">

### Author: ![szhorvat](https://discourse.cmake.org/user_avatar/discourse.cmake.org/szhorvat/32/1906_2.png) [@szhorvat](https://discourse.cmake.org/u/szhorvat)
#### Post date: [November 15, 2024, 2:36pm UTC](https://discourse.cmake.org/t/cmake-3-31-replacement-for-add-custom-command-target-uses-terminal/12935/6 "2024-11-15T14:36:06Z")

</div>

If we use CTest, can benchmarks be excluded from the `test` target?

---

<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 15, 2024, 10:00pm UTC](https://discourse.cmake.org/t/cmake-3-31-replacement-for-add-custom-command-target-uses-terminal/12935/7 "2024-11-15T22:00:09Z")

</div>

@szhorvat This was an oversight on my part when I implemented the CMP0175 policy. I’ve created a [bug report](https://gitlab.kitware.com/cmake/cmake/-/issues/26449) for it and am working on a fix now.

---

<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 16, 2024, 9:19pm UTC](https://discourse.cmake.org/t/cmake-3-31-replacement-for-add-custom-command-target-uses-terminal/12935/8 "2024-11-16T21:19:15Z")

</div>

The fix has been merged and should be in the next patch release.
