# How to use add\_custom\_command right?

**URL:** https://discourse.cmake.org/t/how-to-use-add-custom-command-right/3229
**Category:** Usage
**Tags:** os:windows
**Created:** [April 28, 2021, 1:43pm UTC](https://discourse.cmake.org/t/how-to-use-add-custom-command-right/3229 "2021-04-28T13:43:37Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![serge](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/5f8ce5/32.png) [@serge](https://discourse.cmake.org/u/serge)
#### Post date: [April 28, 2021, 1:43pm UTC](https://discourse.cmake.org/t/how-to-use-add-custom-command-right/3229/1 "2021-04-28T13:43:37Z")

</div>

Hi there,  
I am quite new to CMake and can see some weird benaviors. Also I could see similar issues of people to this kind of problem but could not see a good solution.  
Hopefully, someone can help.  
Suppose I use add\_custom\_command in the following way:

set(flags “-c -t -o”)  
add\_custom\_command(COMMAND ${CMAKE\_C\_COMPILER} ${flags} /EP xx.c \> xx.i )

On windows this will generate the following:

“\cl.exe” “-c -t -o” /EP xx.c \> xx.i

when u build with microsoft VS you get an error saying it can’t open file “-c -t -o”.  
This is due to the fact that cmake puts those quotes around the flags string variable.  
The question is how do I get rid of those quotes and what is the right way to use this command.

Remark: you could say: do not use quotes when you define flags but in real flow I get flags via get\_property() which seems to have those quotes in there.

Thanks  
Serge

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [April 28, 2021, 2:06pm UTC](https://discourse.cmake.org/t/how-to-use-add-custom-command-right/3229/2 "2021-04-28T14:06:52Z")

</div>

`add_custom_command` takes strings as is without any interpretation.

To expect correct syntax, specify the `flags` as a list not a string. And to avoid problems if the path of the compiler contains some spaces, use quotes:

```cmake
set(flags -c -t -o)
add_custom_command(COMMAND "${CMAKE_C_COMPILER}" ${flags} /EP xx.c > xx.i )

```

---

<div class="post-metadata">

### Author: ![serge](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/5f8ce5/32.png) [@serge](https://discourse.cmake.org/u/serge)
#### Post date: [April 30, 2021, 12:06pm UTC](https://discourse.cmake.org/t/how-to-use-add-custom-command-right/3229/3 "2021-04-30T12:06:04Z")

</div>

Thank you Marc,  
and it solved the problem.  
Awesome, also a little bit counter intuitive for someone used to C/C++ python and other programming languages.

Cheers.
