How to run a .bat file from cmake?

How to run a .bat file from cmake in a pre-join or post-build event?

+5
source share
2 answers

You can use add_custom_commandfor example.

if(WIN32)
  add_custom_command(TARGET <Your target>
                       POST_BUILD
                       COMMAND cmd //C <path to .bat file> <ARGS> )

endif()


add_custom_commandRun details

cmake --help-command add_custom_command
+11
source

This also works. If you are reading or creating a file inside a bat script, be sure to specify the exact path inside the bat script.

ADD_CUSTOM_TARGET( myCustomTarget COMMAND cmd /c E:/Myfiles/mytxt.bat ) ADD_DEPENDENCIES(myTarget myCustomTarget)

myTarget will be executed after myCustomTarget

Peace!!!:)

+2
source

All Articles