# Variable evaluation in command parameters

**URL:** https://discourse.cmake.org/t/variable-evaluation-in-command-parameters/10809
**Category:** Code
**Created:** [May 6, 2024, 8:32pm UTC](https://discourse.cmake.org/t/variable-evaluation-in-command-parameters/10809 "2024-05-06T20:32:12Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Oodini](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/o/db5fbb/32.png) [@Oodini](https://discourse.cmake.org/u/Oodini)
#### Post date: [May 6, 2024, 8:32pm UTC](https://discourse.cmake.org/t/variable-evaluation-in-command-parameters/10809/1 "2024-05-06T20:32:12Z")

</div>

Hello,

I am trying to understand why a target in some CMakeLists.txt is built with VS 2022, whereas it is supposed to be build with the VS 2017 generator.

I didn’t code this CMakeLists, but somethings seems strange to me.

There is a call to `ExternalProject_Add()`, and the generator parameter is given with a variable, whose value is returned by a function.

```auto
set(generator_var "CMAKE_GENERATOR;Visual Studio 2017") # Is actually retrieved from a function

ExternalProject_Add(MyProj
    ...
    ${generator_var} # Expected to be evaluated, I guess, as CMAKE_GENERATOR "Visual Studio 2017"
    LOG_CONFIGURE ON
    ...
)

```

Actually, I found that at work, I am at home now, and I am not sure if there are, in the list, quotes around **Visual Studio 2017** (sorry, I’m in Europe, and I didn’t want the american guys escaped me !).

But my question is : is the list splitted so that I am supposed to get the expected result ??  
I tried to add `LOG_CONFIGURE`, but I didn’t find where was put the log…

Personnally, I would have put in the variable only “Visual Studio 2017”, and coded :

```auto
set(generator_var "Visual Studio 2017") # Is actually retrieved from a function

ExternalProject_Add(MyProj
    ...
    CMAKE_GENERATOR ${generator_var}
    LOG_CONFIGURE ON
    ...
)

```

---

<div class="post-metadata">

### Author: ![Oodini](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/o/db5fbb/32.png) [@Oodini](https://discourse.cmake.org/u/Oodini)
#### Post date: [May 7, 2024, 7:06am UTC](https://discourse.cmake.org/t/variable-evaluation-in-command-parameters/10809/2 "2024-05-07T07:06:17Z")

</div>

I finally found the answer to my question in an interesting post of @craig.scott :

> **[Forwarding Command Arguments In CMake](https://crascit.com/2019/01/29/forwarding-command-arguments-in-cmake/)**
>
> The previous article discussed an example from Dan Pfeifer's popular Effective CMake talk. That article highlighted the dangers of trying to override a

I had read (again) in his book the chapter about lists (§6.7), but not the one about functions arguments (§9.2). I’ll see that this evening…
