cmake execute_process COMMAND

时间:2017-04-28 15:40:10

标签: bash cmake

CMakeList.txt:

set(MAKE_CMD "${CMAKE_CURRENT_SOURCE_DIR}/makeHeaders.sh ${CMAKE_CURRENT_SOURCE_DIR} ${INC_DIR}")
MESSAGE("COMMAND: ${MAKE_CMD}")
execute_process(COMMAND "${MAKE_CMD}"   
   RESULT_VARIABLE CMD_ERROR
   OUTPUT_FILE CMD_OUTPUT)
MESSAGE( STATUS "CMD_ERROR:" ${CMD_ERROR})
MESSAGE( STATUS "CMD_OUTPUT:" ${CMD_OUTPUT})

cmake .. OUTPUT:

COMMAND: /home/src/makeHeaders.sh /home/src /home/include
-- CMD_ERROR:No such file or directory
-- CMD_OUTPUT:

如果我复制cmake打印出来的COMMAND,将其粘贴在命令行上,它可以正常工作

这里是makeHeaders.sh

#!/bin/bash
echo In makeHeaders.sh
echo first: $1
echo second $2
echo Making fxsizec.h
echo grep VERSION $1/config/6/cfs.c | grep '^#define' | grep -v 'PGM_V' > $2/fxsizec.h  
echo Making fxsizeo.h
echo grep VERSION $1/opaid/WRS.c | grep '^#define' | grep -v 'PGM_V' |awk '{print $$1 " OA"$$2 " "$$3}' > $2/fxsizeo.h

grep VERSION $1/config/6/cfs.c | grep '^#define' | grep -v 'PGM_V' > $2/fxsizec.h  
grep VERSION $1/opaid/WRS.c | grep '^#define' | grep -v 'PGM_V' |awk '{print $$1 " OA"$$2 " "$$3}' > $2/fxsizeo.h

1 个答案:

答案 0 :(得分:3)

不要将args设置为命令变量的一部分。您可以在execute_process中传递它们:

set(MAKE_CMD "${CMAKE_CURRENT_SOURCE_DIR}/makeHeaders.sh")
MESSAGE("COMMAND: ${MAKE_CMD} ${CMAKE_CURRENT_SOURCE_DIR} ${INC_DIR}")
execute_process(COMMAND ${MAKE_CMD} ${CMAKE_CURRENT_SOURCE_DIR} ${INC_DIR}
   RESULT_VARIABLE CMD_ERROR
      OUTPUT_FILE CMD_OUTPUT)
  MESSAGE( STATUS "CMD_ERROR:" ${CMD_ERROR})
  MESSAGE( STATUS "CMD_OUTPUT:" ${CMD_OUTPUT})

修改 除了上面的答案,如果你想将参数添加到命令变量,你可以这样做:

set(MAKE_CMD "${CMAKE_CURRENT_SOURCE_DIR}/makeHeaders.sh")
list(APPEND MAKE_CMD ${CMAKE_CURRENT_SOURCE_DIR})