This question already has an answer here:
-
CMake's execute_process and arbitrary shell scripts
2 answers
I wanted to extract a string from a header in an execute_process
.
But there is a bug with the command and I try a lot of things, always the same error.
execute_process
(
COMMAND
cat $(version_h) | grep -a "define myVersion " | cut -d " " -f3 | cut -d '"' -f2`
OUTPUT_VARIABLE _Version)
If I write the command in the console line, there is no problem.
The error says: "Parse error. Function missing ending ")". Instead found unterminated string with text "
"
execute_process()
only deals with processes and their arguments, i.e. there is no shell involved.
So, you have two main options:
execute_process(COMMAND bash -c "..." OUTPUT_VARIABLE _Version)
execute_process(COMMAND cat ... COMMAND grep ... COMMAND cut ... COMMAND cut ... OUTPUT_VARIABLE _Version)
In the second version, the standard output and standard inputs of the commands chain together.
If you want to do anything more complex, you'll have to create a separate script and invoke it in a process-, not shell-, oriented way, i.e. option 1.
The problem was that I need to remove a quote character and I guess there is a confusion with Cmake and the bash command.
execute_process(COMMAND cat ... COMMAND grep ... COMMAND cut ... COMMAND cut -c2- COMMAND rev COMMAND cut -c2- COMMAND rev OUTPUT_VARIABLE _Version)