Search code examples
cmakecmake-custom-command

When is cmakes add_custom_command POST_BUILD being triggered?


Lets consider that I have registered a custom command for a target:

add_custom_command(TARGET ${target_name} POST_BUILD
                   COMMAND cmake -E copy_if_different ${file_path} ${dest_file}
                   COMMENT "exporting ${file_path} to ${dest_file}"
                   VERBATIM)

What I am struggling to find out is when the command is actually being run. Always after the target has been checked like this ?

[ 10%] Built target libzmq

Even if 'nothing has to be done' ?

Or just in case that for the target something had to be done ?


Solution

  • Documentation:

    The command becomes part of the target and will only execute when the
    target itself is built. If the target is already built, the command will
    not execute.