I am using execute_process() function in cmake. 
message(" FLAGS = ${FLAGS}")
message(" SCATTERFILE = ${SCATTERFILE}")
set ( EXECUTE_COMMAND "arm-none-eabi-gcc ${FLAGS}  -E -P -x c-header ${SCATTERFILE} -o ~/ttt.ld" )
message("EXECUTE_COMMAND = ${EXECUTE_COMMAND}")
execute_process(COMMAND  ${EXECUTE_COMMAND} RESULT_VARIABLE rv )
Everything is displayed perfectly as a result of message() command, but it causes errors when it is run while parsing cmake. I think the FLAGS variable is not expanding as expected  while parsing. When I run the same EXECUTE_COMMAND which is displayed as a result of message command in the terminal it runs perfectly. what could be the issue ?
Edit:
I have removed ${FLAGS} from 
set ( EXECUTE_COMMAND "arm-none-eabi-gcc ${FLAGS}  -E -P -x c-header ${SCATTERFILE} -o ~/ttt.ld" )`
now I am using
set ( EXECUTE_COMMAND "arm-none-eabi-gcc   -E -P -x c-header ${SCATTERFILE} " )
The output is:
EXECUTE_COMMAND arm-none-eabi-gcc   -E -P -x c-header ~/scatterFile.scatter rv: No such File or directory. 
If I simply enter this command on the terminal,
arm-none-eabi-gcc -E -P -x c-header ~/scatterFile.scatter
it executes and gives the expected results.
The problem is you're trying to execute a program named "arm-none-eabi-gcc -E -P -x c-header ~/scatterFile.scatter rv". Notice the syntax of execute_process():
COMMAND <cmd1> [args1...]
To make it even clearer, the documentatin could actually write it as:
COMMAND cmd1 [arg1 [arg1 ...]]
CMake expects the command name as one CMake argument and each command-line argument as another separate CMake argument. You're enclosing everything in quotes, however, which turns it into one CMake argument (containing lots of spaces). Change your code as follows:
set (EXECUTE_COMMAND arm-none-eabi-gcc ${FLAGS} -E -P -x c-header ${SCATTERFILE} -o ~/ttt.ld)
execute_process(COMMAND ${EXECUTE_COMMAND} RESULT_VARIABLE rv)
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With