# file(GENERATE OUTPUT ...) CONDITION problem

**URL:** https://discourse.cmake.org/t/file-generate-output-condition-problem/3462
**Category:** Code
**Created:** [June 1, 2021, 10:00pm UTC](https://discourse.cmake.org/t/file-generate-output-condition-problem/3462 "2021-06-01T22:00:05Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![mbee](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/50afbb/32.png) [@mbee](https://discourse.cmake.org/u/mbee)
#### Post date: [June 1, 2021, 10:00pm UTC](https://discourse.cmake.org/t/file-generate-output-condition-problem/3462/1 "2021-06-01T22:00:06Z")

</div>

In order to expand some generator expressions, I’m using the file interface:

```
file(GENERATE OUTPUT "$<TARGET_FILE_DIR:${target}>/eh_support/${_outname}"
CONTENT 
"
set(eh_userfile_id ${eh_userfile_id})
include(${EH_FRAMEWORK_DIR}/eh_supportlib.cmake)
include(${_abs_path})
## Condition: $<IN_LIST:$<CONFIG>,${EH_CONFIGURATIONS}>
# Calling unique ${function_name}:
${function_name}_${id}(${target} $<TARGET_FILE_DIR:${target}>)
"
#CONDITION $<IN_LIST:$<CONFIG>,${EH_CONFIGURATIONS}>
)

```

This is working, as long as I don’t use the CONDITION flag. If I remove the last comment from above, cmake fails with:

` file Incorrect arguments to GENERATE subcommand.`

It doesn’t matter, if I provide the list hardwired or as variable (${EH\_CONFIGURATIONS}==“RelWithDebInfo;Debug”) - the error is the same. Strange thing is, the exact same expression resolves correctly to 0 or 1 inside the commands CONTENT section for the written output without CONDITION. Also the generator expression behind OUTPUT expands.

What is wrong with this code? Is there another way to limit the number of configurations for which the file is created?

---

<div class="post-metadata">

### Author: ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)
#### Post date: [June 2, 2021, 8:37am UTC](https://discourse.cmake.org/t/file-generate-output-condition-problem/3462/2 "2021-06-02T08:37:53Z")

</div>

Since `EH_CONFIGURATIONS` is a list, it contains semi-colons. When expanded at configure time, these semi-colons are interpreted as separators between arguments of the `file()` command. You should quote the expansion to keep it as one argument:

```
CONDITION "$<IN_LIST:$<CONFIG>,${EH_CONFIGURATIONS}>"
```

---

<div class="post-metadata">

### Author: ![mbee](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/50afbb/32.png) [@mbee](https://discourse.cmake.org/u/mbee)
#### Post date: [June 2, 2021, 8:53am UTC](https://discourse.cmake.org/t/file-generate-output-condition-problem/3462/3 "2021-06-02T08:53:20Z")

</div>

Thank you, perfect!
