CMAKE:在运行自定义命令后执行文件复制
我有一个如下所示的构建脚本片段:
foreach(...)
...
add_custom_command( OUTPUT ${fn_c} ${fn_s} ${fn_p_c} {fn_p_h}
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --proto_path=${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${proto_var} --cpp_out=. --plugin=protoc-gen-RBLRPC=${CMAKE_BINARY_DIR}/tools/protoc-gen-RBLRPC --RBLRPC_out=.
DEPENDS ${proto_var}
)
if(${M_S_} OR ${M_C_})
set(MARSHALL_RPC_FILES ${MARSHALL_RPC_FILES} ${fn_p_c})
message(status "copy marshall -------------------")
file(COPY ${CMAKE_CURRENT_BINARY_DIR}/${fn_c}
${CMAKE_CURRENT_BINARY_DIR}/${fn_s}
${CMAKE_CURRENT_BINARY_DIR}/${fn_p_h} DESTINATION ${CMAKE_SOURCE_DIR}/include/rpc/marshall)
endif()
...
endforeach(...)
在执行自定义命令之前不会生成复制的文件,但是 cmake 会在第一次传递脚本时尝试复制文件。我欢迎任何解决这个问题的建议,而不需要彻底改变我的脚本。
I have a build script fragment that looks as follows:
foreach(...)
...
add_custom_command( OUTPUT ${fn_c} ${fn_s} ${fn_p_c} {fn_p_h}
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --proto_path=${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${proto_var} --cpp_out=. --plugin=protoc-gen-RBLRPC=${CMAKE_BINARY_DIR}/tools/protoc-gen-RBLRPC --RBLRPC_out=.
DEPENDS ${proto_var}
)
if(${M_S_} OR ${M_C_})
set(MARSHALL_RPC_FILES ${MARSHALL_RPC_FILES} ${fn_p_c})
message(status "copy marshall -------------------")
file(COPY ${CMAKE_CURRENT_BINARY_DIR}/${fn_c}
${CMAKE_CURRENT_BINARY_DIR}/${fn_s}
${CMAKE_CURRENT_BINARY_DIR}/${fn_p_h} DESTINATION ${CMAKE_SOURCE_DIR}/include/rpc/marshall)
endif()
...
endforeach(...)
The copied files are not generated untill the custom comand is executed, however cmake attempts to copy the files upon first pass over the script. I'd welcome any suggestions to solve this problem , without drastically changing my scrips.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要使用
file(COPY...)
函数,而是将以下命令添加到您的add_custom_command
中:但是对于您要执行的操作,我建议您保持源代码树干净,直接添加使用构建目录中生成的文件。例如,如果您想从单个源树创建两个不同的构建树,那么这就会中断。
编辑:
CMAKE_COMMAND 记录在在线手册页文档的变量部分中(搜索 CMAKE_COMMAND 而不是 ${CMAKE_COMMAND}。
在命令行上
CMAKE -E
将显示可用的可移植命令列表。Don't use
file(COPY...)
function, but add the following command to youradd_custom_command
:But for what you're going to do, I would suggest you keep your source tree clean, add directly use the generated files from the build directory. That would break, for instance, if you want to make two different build tree from a single source tree.
edit :
CMAKE_COMMAND is documented in the variable section of the online man-page documentation, (search for CMAKE_COMMAND and not ${CMAKE_COMMAND}.
On the command line
CMAKE -E
will show you a list of portable commands useable.