[DOC] Missing documentation: file(READ|STRINGS). Read in CMake variables are escaped and taken as literal values.
I am reading in a file which contains a literal string "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/somefile.h>"
I am passing this string around via cmake_parse_arguments
etc. to finally reach a target_sources(sometarget INTERFACE ${SOMESTRING})
with SOMESTRING
being "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/somefile.h>"
set via cmake_parse_arguments
in somefunction
and orginally obtain by a file(READ ${someinputfile} _somecontents)
passed to somefunction(${_somecontents})
My expection would be that ${CMAKE_CURRENT_SOURCE_DIR}
would be evaluated when passed from file(READ ${someinputfile} _somecontents)
to somefunction(${_somecontents})
but apparently it is not since CMake errors that it literally cannot find the file ${CMAKE_CURRENT_SOURCE_DIR}/include/somefile.h
. (The $ is nowhere escaped with )
Is this a bug or is this behavior somewhere documented and expected? Is there another way to achieve the desired behavior without a silly workaround?
My current workaround is to use $<TARGET_PROPERTY:SOURCE_DIR>
instead but I would like to support abitary other variables. My second workaround would be to do a literal string replacement after file(READ ${someinputfile} _somecontents)
with string(REPLACE [[${WHITELISTVAR}]] "${WHITELISTVAR}" _somecontents "${_somecontents}")