# String escaping with target\_compile\_options()

**URL:** https://discourse.cmake.org/t/string-escaping-with-target-compile-options/2117
**Category:** Code
**Created:** [November 4, 2020, 11:29am UTC](https://discourse.cmake.org/t/string-escaping-with-target-compile-options/2117 "2020-11-04T11:29:14Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![JoelLinn](https://discourse.cmake.org/user_avatar/discourse.cmake.org/joellinn/32/926_2.png) [@JoelLinn](https://discourse.cmake.org/u/JoelLinn)
#### Post date: [November 4, 2020, 11:29am UTC](https://discourse.cmake.org/t/string-escaping-with-target-compile-options/2117/1 "2020-11-04T11:29:14Z")

</div>

Hi,  
I need to pass some unorthodox arguments to the compiler, but without having their special characters escaped, like `/wd"1234"`. This works with setting the flags variable globally but not when using `target_compile_options()`. It always escapes the special characters. Is there a way to disable this for some values? I took a peek into the cmake source code but it wasn’t obvious to me. Things I tried:

```
target_compile_options("my_awesome_target" PRIVATE
  `echo 1234`
  $(echo 1234)
  /wd"1234"
  "`echo 1234`"
  "$(echo 1234)"
  "/wd\"1234\""
  "\`echo 1234\`"
)

```

I know the immediate problems these arguments solve can be solved in another way using cmake but the cmake is auto-generated itself so I have limited control over the options passed.

Thanks,  
Joel

---

<div class="post-metadata">

### Author: ![robert.maynard](https://discourse.cmake.org/user_avatar/discourse.cmake.org/robert.maynard/32/4_2.png) [@robert.maynard](https://discourse.cmake.org/u/robert.maynard)
#### Post date: [November 4, 2020, 4:54pm UTC](https://discourse.cmake.org/t/string-escaping-with-target-compile-options/2117/2 "2020-11-04T16:54:03Z")

</div>

What you can do is use [CMake string literals](https://cmake.org/cmake/help/latest/manual/cmake-language.7.html#bracket-argument) so that zero escaping or expansion occurs:

```auto
target_compile_options(my_awesome_target PRIVATE
  [=[/wd"1234"]=]
  [=['echo 1234']=]
)

```

This will make sure the compiler is given `/wd"1234"` and `'echo 1234'`

---

<div class="post-metadata">

### Author: ![JoelLinn](https://discourse.cmake.org/user_avatar/discourse.cmake.org/joellinn/32/926_2.png) [@JoelLinn](https://discourse.cmake.org/u/JoelLinn)
#### Post date: [November 4, 2020, 6:59pm UTC](https://discourse.cmake.org/t/string-escaping-with-target-compile-options/2117/3 "2020-11-04T18:59:43Z")

</div>

Thank your very much, I didn’t find that before.  
Unfortunately it still escapes the quotes.  
My guess is it always is added to the internal `COMPILE_OPTIONS` as entered but is escaped when the makefile is generated
