file(GENERATE OUTPUT ...) CONDITION problem

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?

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}>"

Thank you, perfect!