CMAKE: performing a file copy AFTER a custom command has run
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 开发者_如何学Pythoncomand 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.
Don't use file(COPY...)
function, but add the following command to your add_custom_command
:
COMMAND ${CMAKE_COMMAND} copy ${CMAKE_CURRENT_BINARY_DIR}/${fn_c}
${CMAKE_SOURCE_DIR}/include/rpc/marshall
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.
精彩评论