Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cmake to add VS2010 Project custom Build Events

Is there a way I can set CMake to generate a VS2010 Project file that has Pre Build or Post Build event in them?

Thanks.

like image 486
Darshan R Avatar asked Nov 02 '11 22:11

Darshan R


1 Answers

From the CMake documentation:

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.

For example, if your target is named MyProject and you want to run the command SomeCommand with argument -1 -2 after the building, add the following line after your add_executable or add_library call, because the target has to be defined:

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

See https://cmake.org/cmake/help/v2.8.8/cmake.html#command:add_custom_command for more details on how to use add_custom_command().

like image 190
fmorency Avatar answered Oct 10 '22 21:10

fmorency