# Passing list variables to external project commands

**URL:** <https://discourse.cmake.org/t/passing-list-variables-to-external-project-commands/15210>\
**Category:** Code\
**Tags:** os:linux\
**Created:** [October 2, 2025, 10:58am UTC](https://discourse.cmake.org/t/passing-list-variables-to-external-project-commands/15210 "2025-10-02T10:58:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sergeniously](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/e495f1/32.png) [@sergeniously](https://discourse.cmake.org/u/sergeniously)\
**Post date:** [October 2, 2025, 10:58am UTC](https://discourse.cmake.org/t/passing-list-variables-to-external-project-commands/15210/1 "2025-10-02T10:58:07Z")

</div>

Hello, everyone.

For some reason in my project I need to set a compiler launcher this way:

```cmake
set(CMAKE_C_COMPILER_LAUNCHER env DIR=/path/to/dir)

```

But when I try to configure an external cmake project with the same launcher:

```cmake
ExternalProject_Add(name
	CONFIGURE_COMMAND cmake -DCMAKE_C_COMPILER_LAUNCHER="${CMAKE_C_COMPILER_LAUNCHER}" ...
    ...
)

```

I end up with the following configure command:

```auto
cmake -DCMAKE_C_COMPILER_LAUNCHER=\"env DIR=/path/to/dir\" ...

```

Which is incorrect and I expect something like this:

```auto
cmake -DCMAKE_C_COMPILER_LAUNCHER="env;DIR=/path/to/dir" ...

```

How could I achieve the result I expect without using any string transformations?

---

<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:** [October 2, 2025, 5:07pm UTC](https://discourse.cmake.org/t/passing-list-variables-to-external-project-commands/15210/2 "2025-10-02T17:07:56Z")

</div>

Use CMAKE\_CACHE\_ARGS as those are transferred with a file and not via command line

---

<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:** [October 2, 2025, 10:36pm UTC](https://discourse.cmake.org/t/passing-list-variables-to-external-project-commands/15210/3 "2025-10-02T22:36:13Z")

</div>

> [@sergeniously](#):
>
> ```auto
> ExternalProject_Add(name
> CONFIGURE_COMMAND cmake -DCMAKE_C_COMPILER_LAUNCHER="${CMAKE_C_COMPILER_LAUNCHER}" ...
> ...
> )
> 
> ```

CMake doesn’t have the same quoting rules as a bash shell. In particular, quotes anywhere other than at the start and end of an argument are not treated specially and become part of the string. Instead of putting the opening quote in the middle of the argument, put it at the start like so:

```cmake
ExternalProject_Add(name
	CONFIGURE_COMMAND cmake "-DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER}" ...
    ...
)

```

---

<div class="post-metadata">

**Author:** ![sergeniously](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/e495f1/32.png) [@sergeniously](https://discourse.cmake.org/u/sergeniously)\
**Post date:** [October 3, 2025, 12:28pm UTC](https://discourse.cmake.org/t/passing-list-variables-to-external-project-commands/15210/4 "2025-10-03T12:28:18Z")

</div>

Unfortunately, your variant does not work as well:

```cmake
set(CMAKE_C_COMPILER_LAUNCHER env DIR=/tmp)

ExternalProject_Add(name
	CONFIGURE_COMMAND cmake "-DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER}" ...
)

```

Which produces the following output:

```auto
cd ... && cmake -DCMAKE_C_COMPILER_LAUNCHER=env DIR=/tmp ...

```

Now I have to convert it to a string to make it work:

```cmake
string(REPLACE ";" "$<SEMICOLON>" CMAKE_C_COMPILER_LAUNCHER_STR "${CMAKE_C_COMPILER_LAUNCHER}")

```

But this is pretty inconvenient.

PS. cmake version 3.28.3
