9

I know how to run a command after (or before) building a target with add_custom_command :

add_custom_command(TARGET my_target POST_BUILD    
    COMMAND echo "custom command"      
)

But I want to ALWAYS run this command, after the target has been build or after it failed to build.

Here, when the target fails to build, the command is not launched.

Is it possible to achieve this with cmake?

michael.t
  • 210
  • 1
  • 3
  • 8
  • The answer would depend on what you want to do. Can you give an example of a `POST_BUILD` step you want to do even when the build fails? Generally speaking - for makefile generators - you are doing something like ignoring the compiler/linker return values in CMake not by using `add_custom_command()` but using e.g. the [`RULE_LAUNCH_LINK`](https://cmake.org/cmake/help/latest/prop_gbl/RULE_LAUNCH_LINK.html) global/directory/target property. See e.g. [here](http://stackoverflow.com/questions/9765547/how-to-customize-cmake-output). – Florian Aug 22 '16 at 14:00
  • I want to copy files with the cp command. I don't want to use an external script just be able to run a cp command each time after the build tails or succeeds. – michael.t Aug 23 '16 at 06:34
  • 1
    Ok, is the file you want to copy an output of your build process and/or an input to another build step? This would be important to setup the dependency checking correctly. And - if we e.g. are talking about makefiles and you don't want to use external scripts - you probably still need to do something like `make -i` (see [here](http://public.kitware.com/pipermail/cmake/2009-October/032454.html)). Or maybe you can give an `makefile` code snippet of what you expect CMake to generate. – Florian Aug 23 '16 at 07:35

0 Answers0