Running postbuild tasks with ninja

Hi,

We have been using the visual studio generators and it seems to work for the most part but there are a few issues that we are trying to solve that are not supported with the visual studio generators. We have been looking at using Ninja instead. It seems to solve these problems but it has its own issues. With visual studio we use POST_BUILD command to kick off the the signing and then copying the files (after signing completes) to a know folder structure. This code is quite complex and has extensive use of generator expressions to try to figure out the where the files get copied for each target.

Now that we are looking into using Ninja we are running into issues with the post build, My understanding is that ninja is starting the postbuild once the target is built but it does not wait for the linker to complete. Therefore these post build targets are unable to find the final created files.

I have tried to add dependencies in the target that post build runs but this causes circular dependencies that Ninja cannot deal with. I have also tried to make the Ninja post build wait for the target to link but this does not seem to work in all of our cases.

add_custom_command(TARGET ${TARGET_NAME}
    POST_BUILD
    DEPENDS $<TARGET_FILE:${TARGET_NAME}>
    COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target ${postbuild_target} --config $<CONFIG>
    COMMENT "Running postbuild ${TARGET_NAME}")

This works fine with the VS generators. Does anyone have any suggestions to how to make Ninja wait for the linker to complete before we start the post build task.

If this is not the right approach how do other people do signing or other post build tasks with ninja. In our case we have some windows files system drivers that need to be signed in order to get deployed in our test environment. Therefore since signing (test signing is ok) is required we want this to happen as part of the build of the specified target. Requiring the entire build to have a signing phase is too slow in order to just build thee filters especially with active development. Any help or suggestions would be greatly appreciated.

Thanks

This is probably a different type of signing than you are using, but here is a method I use to sign binary executables with gpg. Particularly this line

Thanks for the info but we are already do doing something similar to this which does work however. However it does not wait for the original target to be linked in some cases so the final target will be compiled and symbol file exist but the linker has not completed. I need a way to ensure that POST_BUILD is not started until the linker has completed.

Thanks
Noah