in my project I need to read content from a file VERSION ( a simple string line without spaces or newlines ), adding quotes (") at begin and end of file, and write it in a new file VERSION_Q. E.g, if VERSION is 3.0, VERSION_Q will be “3.0”
I have inserted the line in the add_custom_command block:
You probably can achieve that with a one-liner too, but I would do it like this:
file(READ "${VERSION_FILE}" VERSION_CONTENT)
# the file might (should) contain a empty line in the end of it
string(STRIP "${VERSION_CONTENT}" VERSION_CONTENT)
# perform some other checks like a RegEx for the version format
# ...
file(WRITE "${VERSION_Q_FILE}" "\"${VERSION_CONTENT}\"\n")
Thank you, @retif and @jtxa . Both proposals are valid, I have selected @retif one since I prefer more simpler commands.
I would like ask a new question now: how I can introduce dependencies?
In my project, a source file depends upon the VERSION_Q_FILE, that depends in turn upon the VERSION_FILE. I have tryed to write it using add_dependencies command, but I cannot formulate them correctly.
I apologize: I am removing it and opening a new topic.