Skipping an useless argument when invoking a command

I want to call string(REGEX MATCH without the <output_variable> argument, because I don’t need it in this particular case since I want to use CMAKE_MATCH_<n> variables instead. So my invocation line looks something like this:

string(REGEX MATCH "^#define LIBRARY_VERSION .*\\(([0-9]+),([0-9]+),([0-9]+)\\)" _z "${version_file_raw}")

The problem is that I don’t want to clutter namespace with obscure dummy variables that use some unclear notation to mark them as unused (in this example it’s _z - a leading underscore and a meaningless name).

Is there any default notation and/or good practice way for that?

I have tried to replace _z with the following options:

  1. "" - doesn’t work, fails with a random error citing the contents of the match, as in CMAKE_MATCH_0:
-- Detecting C compiler ABI info
CMake Error: Parse error in command line argument: #define LIBRARY_VERSION \
 Should be: VAR:type=value

CMake Error at C:/Program Files/CMake/share/cmake-3.25/Modules/CMakeDetermineCompilerABI.cmake:57 (try_compile):
  Failed to configure test project build system.
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.25/Modules/CMakeTestCCompiler.cmake:26 (CMAKE_DETERMINE_COMPILER_ABI)
  CMakeLists.txt:8 (project)

-- Configuring incomplete, errors occurred!
  1. 0 - doesn’t work, fails with another random error:
-- Detecting CXX compile features - failed
CMake Error at sources/plainmtp.cmake:19 (target_compile_features):
  target_compile_features no known features for C compiler


  version 19.29.30147.0.
Call Stack (most recent call first):
  CMakeLists.txt:9 (include)

-- Configuring incomplete, errors occurred!
  1. " " - seems to work.
  2. _ / , / ; / : / $ / invalid identifiers like 123test - also seem to work.

If there is no default way, then which of the mentioned ones is better?

Thanks in advance.

Just use unset(_z) after the call.

1 Like

This is also an option, but I’m wondering how it can be done without being too verbose.

There’s no “bit bucket” variable available in CMake.

1 Like