We can use a cmake config file to import targets. For example given machinary including foobarConfig.cmake.in
set(FOOBAR_VERSION @VERSION@)
@PACKAG
Oops. This is embarrassing. I'd moved the generation code into a shell script and forgot to escape the variables!
cat - >CMakeLists.txt <=$\n")
EOF
The question is still useful for providing source for the related question though.
To answer my own questions:
How can I find this problem? Avoid similar problems in the future? Create these files in a safe and canonical way?