Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using cmake variable in execute_process command in cmake file

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.

like image 766
theadnangondal Avatar asked Jan 20 '15 11:01

theadnangondal


1 Answers

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)
like image 170
Angew is no longer proud of SO Avatar answered Sep 20 '22 11:09

Angew is no longer proud of SO