# percent signs in target\_compile\_definitions on Windows

**URL:** https://discourse.cmake.org/t/percent-signs-in-target-compile-definitions-on-windows/4489
**Category:** Code
**Tags:** os:windows
**Created:** [November 16, 2021, 12:41pm UTC](https://discourse.cmake.org/t/percent-signs-in-target-compile-definitions-on-windows/4489 "2021-11-16T12:41:45Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jobor](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jobor/32/1230_2.png) [@jobor](https://discourse.cmake.org/u/jobor)
#### Post date: [November 16, 2021, 12:41pm UTC](https://discourse.cmake.org/t/percent-signs-in-target-compile-definitions-on-windows/4489/1 "2021-11-16T12:41:45Z")

</div>

Consider a target with compile definitions like this

```cmake
target_compile_definitions(myapp PRIVATE
	TESTCASE_BUILDDIR="${CMAKE_BINARY_DIR}/foo%2bar"))

```

This works fine on Linux, but on Windows there will be errors. For example, MSVC’s cl.exe yields “cl : Command line error D8038 : invalid argument”.

According to MS docs at [/D (Preprocessor Definitions) | Microsoft Docs](https://docs.microsoft.com/en-us/cpp/build/reference/d-preprocessor-definitions?view=msvc-160#remarks) percent sign should be written as doubled percent sign when passing it to the compiler with -D.

A more thorough explanation of the issue can be found in this blog post: [Percent-sign in preprocessor definition breaks CMake Visual Studio generator](https://peter.bloomfield.online/percent-sign-in-preprocessor-definition-breaks-cmake-visual-studio-generator/)

Given that target\_compile\_definitions already does some escaping, should it also take care of doubling the percent sign on Windows?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 16, 2021, 1:29pm UTC](https://discourse.cmake.org/t/percent-signs-in-target-compile-definitions-on-windows/4489/2 "2021-11-16T13:29:30Z")

</div>

Yes, this sounds like something that CMake should be doing. Please [file an issue](https://gitlab.kitware.com/cmake/cmake/-/issues).

---

<div class="post-metadata">

### Author: ![jobor](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jobor/32/1230_2.png) [@jobor](https://discourse.cmake.org/u/jobor)
#### Post date: [November 16, 2021, 3:17pm UTC](https://discourse.cmake.org/t/percent-signs-in-target-compile-definitions-on-windows/4489/3 "2021-11-16T15:17:27Z")

</div>

[https://gitlab.kitware.com/cmake/cmake/-/issues/22918](https://gitlab.kitware.com/cmake/cmake/-/issues/22918)
