1. ホーム
  2. bash

[解決済み] cmake execute_process COMMAND [重複]。

2022-02-14 19:42:28

質問

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

解決方法は?

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})

EDIT 上記の回答に加えて、コマンド変数に引数を追加したい場合は、次のようにすることができます。

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