Cmake添加VS2010项目自定义构建事件

Dar*_*n R 10 cmake visual-studio-2010

有没有办法我可以设置CMake生成一个VS2010项目文件,其中包含Pre Build或Post Build事件?

谢谢.

fmo*_*ncy 18

从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.
Run Code Online (Sandbox Code Playgroud)

例如,如果您的目标已命名,MyProject并且您希望在构建之后运行SomeCommand带有参数的命令,请您或之后-1 -2添加以下行,因为必须定义目标:add_executableadd_library

add_custom_command(TARGET MyProject
                   POST_BUILD
                   COMMAND SomeCommand ARGS "-1 -2"
                   COMMENT "Running SomeCommand")
Run Code Online (Sandbox Code Playgroud)

有关如何使用的更多详细信息,请参阅https://cmake.org/cmake/help/v2.8.8/cmake.html#command:add_custom_commandadd_custom_command().