CMake 3.31: Replacement for add_custom_command(TARGET ... USES_TERMINAL)?

CMake 3.31 complains that USES_TERMINAL is not valid with add_custom_command(TARGET...)

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:

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.

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.

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?

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.

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

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

@szhorvat This was an oversight on my part when I implemented the CMP0175 policy. I’ve created a bug report for it and am working on a fix now.

1 Like

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

1 Like