file(CONFIGURE) fails for content containing <
Give this CMakeLists.txt
:
cmake_minimum_required(VERSION 3.18)
project(file-configure)
set(file_content [=[
<version>
1.0
</version>
]=])
# works fine
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/file_content.xml.in "${file_content}")
configure_file(${CMAKE_CURRENT_BINARY_DIR}/file_content.xml.in ${CMAKE_CURRENT_BINARY_DIR}/file_content.xml)
# fails with:
# file CONFIGURE called with CONTENT containing a "<". This character is not
# allowed.
file(CONFIGURE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/file_content2.xml CONTENT "${file_content}")
The file(CONFIGURE)
documentation is saying:
Generate an output file using the input given by CONTENT and substitute variable values referenced as @VAR@ or ${VAR} contained therein. The substitution rules behave the same as the configure_file() command. In order to match configure_file()’s behavior, generator expressions are not supported for both OUTPUT and CONTENT.
Since file(CONFIGURE)
has nothing to do with generator expressions it should be fine to have <
characters in it.