我有一个外部项目,需要构建几个命令:
ExternalProject_Add(
xmlrpc_build
PREFIX ${XMLRPC_ROOT}
SOURCE_DIR ${XMLRPC_ROOT}
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND ""
BUILD_COMMAND ./configure --enable-curl-client CURL_CONFIG=${CURL_CONFIG} COMMAND export CFLAGS=`${CURL_CONFIG} --cflags` COMMAND make -j8
INSTALL_COMMAND ""
)
不幸的是,cmake逃脱了`,所以命令格式不正确:
export "CFLAGS=\`/xxx/curl-config" "--cflags\`"
我累了把它放进"",但没有运气:
BUILD_COMMAND ./configure --enable-curl-client CURL_CONFIG=${CURL_CONFIG} COMMAND "export CFLAGS=`${CURL_CONFIG} --cflags`" COMMAND make -j8
export "CFLAGS=\`/xxx/curl-config" "--cflags\`"
使用$()而不是“不要帮助”的组合:
BUILD_COMMAND ./configure --enable-curl-client CURL_CONFIG=${CURL_CONFIG} COMMAND "export CFLAGS=$(${CURL_CONFIG} --cflags)" COMMAND make -j8
"export CFLAGS=\$(/xxx/curl-config --cflags)"
BUILD_COMMAND ./configure --enable-curl-client CURL_CONFIG=${CURL_CONFIG} COMMAND export CFLAGS=$(${CURL_CONFIG} --cflags) COMMAND make -j8
export "CFLAGS=\$" "(" /xxx/curl-config --cflags ")"
有没有办法从子流程中获取结果并将其分配给变量?
编辑:从另一个问题尝试解决方案但仍然没有运气:
set(blah "`${CURL_CONFIG} --cflags`")
BUILD_COMMAND ./configure --enable-curl-client CURL_CONFIG=${CURL_CONFIG} COMMAND export CFLAGS=${blah} COMMAND make -j8
export "CFLAGS=\`/xxx/curl-config --cflags\`"
或:
BUILD_COMMAND ./configure --enable-curl-client CURL_CONFIG=${CURL_CONFIG} COMMAND [=[export CFLAGS=`${CURL_CONFIG} --cflags`]=] COMMAND make -j8
"export CFLAGS=\`\${CURL_CONFIG} --cflags\`"
答案 0 :(得分:0)
为什么不预先调用它来代替${CURL_CONFIG} --cflags
内联External_Project_Add()
命令?
find_program(CURL_CONFIG curl-config)
execute_process(COMMAND ${CURL_CONFIG} --cflags
OUTPUT_VARIABLE CURL_CONFIG_CFLAGS)
ExternalProject_Add(
xmlrpc_build
PREFIX ${XMLRPC_ROOT}
SOURCE_DIR ${XMLRPC_ROOT}
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND CFLAGS="${CURL_CONFIG_CFLAGS}" ./configure --enable-curl-client CURL_CONFIG=${CURL_CONFIG}
BUILD_COMMAND CFLAGS="${CURL_CONFIG_CFLAGS}" make -j8
INSTALL_COMMAND ""
)
答案 1 :(得分:0)
通过一个糟糕的解决方法让它工作(如果没有黑客,这样的琐事是不可能的):
add_custom_target(
xmlrpc_build_curl_config
COMMAND echo -n CFLAGS= > curl_cflags COMMAND ${CURL_CONFIG} --cflags >> curl_cflags
DEPENDS curl
WORKING_DIRECTORY "${XMLRPC_ROOT}"
VERBATIM
)
ExternalProject_Add(
xmlrpc_build
PREFIX ${XMLRPC_ROOT}
SOURCE_DIR ${XMLRPC_ROOT}
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND ""
BUILD_COMMAND ./configure --enable-curl-client CURL_CONFIG=${CURL_CONFIG} COMMAND cat curl_cflags | xargs env COMMAND make -j8
INSTALL_COMMAND ""
)
add_dependencies(xmlrpc_build xmlrpc_build_curl_config)