2011-11-02 158 views

回答

14

從CMake的文檔:

add_custom_command(TARGET target 
       PRE_BUILD | PRE_LINK | POST_BUILD` 
       COMMAND command1 [ARGS] [args1...] 
       [COMMAND command2 [ARGS] [args2...] ...] 
       [WORKING_DIRECTORY dir] 
       [COMMENT comment] [VERBATIM]) 

This defines a new command that will be associated with building the specified 
target. When the command will happen is determined by which of the following 
is specified: 

PRE_BUILD - run before all other dependencies 
PRE_LINK - run after other dependencies 
POST_BUILD - run after the target has been built 

Note that the PRE_BUILD option is only supported on Visual Studio 7 or later. 
For all other generators PRE_BUILD will be treated as PRE_LINK. 

例如,如果你的目標是一個名爲MyProject和你想要的建築後的參數-1 -2運行命令SomeCommand,添加以下行後您add_executableadd_library呼叫,因爲目標已經被定義爲:

add_custom_command(TARGET MyProject 
        POST_BUILD 
        COMMAND SomeCommand ARGS "-1 -2" 
        COMMENT "Running SomeCommand") 

莫見https://cmake.org/cmake/help/v2.8.8/cmake.html#command:add_custom_command詳細瞭解如何使用add_custom_command()

+0

非常感謝... –

+0

結構良好,非常有用的答案。 :d – MABVT

相關問題