0

I have a Visual Studio 2019 CMake project and i need to run a postbuild script which copys a file (The file is not generated by the build process). What i did so far is add a custom command in CMake with

add_custom_command(TARGET testExec POST_BUILD COMMAND "../postbuild.bat")

The postbuild.bat would copy the file. This works great most of the time but when my build fails due to some compile error, the postbuild script won't be executed.

How can i run the postbuild script even if the build fails ? I know there is a similar question here but sadly no proper solution. If there is a way to configure a postbuild event directly inside a Visual Studio CMake project this would also be suitable, but it seems like this is not possible (because in a cmake project i don't have a project file).

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Michael
  • 147
  • 7

1 Answers1

1

Since The copied file is not generated by the build you can use PRE_BUILD. On Visual Studio Generators, it runs before any other rules are executed within the target.(https://cmake.org/cmake/help/latest/command/add_custom_command.html).

The other solution could be to use add_custom_command(OUTPUT as the file seems independent of the build.

yflelion
  • 1,698
  • 2
  • 5
  • 16