# Passing lists or strings with semi-colon to add\_custom\_command

**URL:** https://discourse.cmake.org/t/passing-lists-or-strings-with-semi-colon-to-add-custom-command/15231
**Category:** Code
**Created:** [October 9, 2025, 9:24pm UTC](https://discourse.cmake.org/t/passing-lists-or-strings-with-semi-colon-to-add-custom-command/15231 "2025-10-09T21:24:39Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![pboettch](https://discourse.cmake.org/user_avatar/discourse.cmake.org/pboettch/32/216_2.png) [@pboettch](https://discourse.cmake.org/u/pboettch)
#### Post date: [October 9, 2025, 9:24pm UTC](https://discourse.cmake.org/t/passing-lists-or-strings-with-semi-colon-to-add-custom-command/15231/1 "2025-10-09T21:24:39Z")

</div>

What is the correct way (if any) to pass a variable containing a semi-colon `;` as an argument to `COMMAND` for `add_custom_command()` ? I especially would like to pass a CMake List, which is usually represented as a semi-colon-separated string when, e.g., printing it out with `message`.

It always gets replaced by a space in my case, I tried `VERBATIM` but this just add quotes. `COMMAND_EXPAND_LISTS` does nothing in my case.

---

<div class="post-metadata">

### Author: ![pboettch](https://discourse.cmake.org/user_avatar/discourse.cmake.org/pboettch/32/216_2.png) [@pboettch](https://discourse.cmake.org/u/pboettch)
#### Post date: [October 9, 2025, 9:32pm UTC](https://discourse.cmake.org/t/passing-lists-or-strings-with-semi-colon-to-add-custom-command/15231/2 "2025-10-09T21:32:10Z")

</div>

I found a solution, replacing `;` with `\\;` will ultimately escape de semi-colon enough for it to arrive as the executing shell:

```auto
string(REPLACE ";" "\\;" ADDITIONAL_CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH}")
add_custom_target(
    pybuild ALL
    COMMAND
        ${CMAKE_COMMAND} -E env CMAKE_ARGS=-DADDITIONAL_CMAKE_PREFIX_PATH="${ADDITIONAL_CMAKE_PREFIX_PATH}"
            ${PYTHON_ENV_DIR}/bin/pip install -e path/
    ...
    )

```

---

<div class="post-metadata">

### Author: ![leha-bot](https://discourse.cmake.org/user_avatar/discourse.cmake.org/leha-bot/32/921_2.png) [@leha-bot](https://discourse.cmake.org/u/leha-bot)
#### Post date: [January 3, 2026, 11:47am UTC](https://discourse.cmake.org/t/passing-lists-or-strings-with-semi-colon-to-add-custom-command/15231/3 "2026-01-03T11:47:01Z")

</div>

Did you also try the `$<SEMICOLON>` [escaped generator expression](https://cmake.org/cmake/help/v3.15/manual/cmake-generator-expressions.7.html#id10) ?
