Semi-colon separated argument in CMake’s `add_custom_command` using the Visual Studio generator


I’ve been unable to get this very simple piece of CMake to run as expected:

set(FOO baz$<SEMICOLON>bar)

add_custom_command(
  OUTPUT whatever
  COMMAND custom-compiler.py --include=${FOO}
)

This is one of the many variations I tried.
My tests included:

  1. Using the VERBATIM flag
  2. Using the COMMAND_EXPAND_LISTS flag
  3. Using literal semi-colons
  4. Using escaped semi-colons
  5. Adding double-quotes around the expanded variable
  6. Adding double-quotes when defining the variable
  7. Copy-paste whatever hallucination $LLM gave me

At the end of the day, either the ; are turned into spaces because CMake lists, or they are double-quoted, giving me something like e.g. --include=baz";"bar.

Funniest part of all, this example works otherwise just fine with Ninja, it is only broken when using the Visual Studio generator. Unfortunately, I, for now, need to support this generator.

Leave a Reply

Your email address will not be published. Required fields are marked *