The problem is that if I delete foo.sym, in order for it to be created again it's not enough with running the custom command steps as we have stripped the file and the debug symbols are gone: we need to relink the executable so the debug information is available again.
The ninja generator makes this situation possible with the use of byproducts. By adding BYPRODUCTS foo.sym to the custom command if I change foo.sym the target is relinked. Unfortunately the GNU Makefiles generator ignores byproducts, so I want to relink the executable I need to remove it. Also the byproducts are added to ninja's clean target, but not for GNU Makefiles.
I have tried to achieve the same result with a custom command:
But I get the same results, the target does not get relinked. Also, it seems that there is an issue of some sort because every time I type make the steps to create the file foo.sym are executed, resulting in an error message from objcopy ('debuglink section already exists'). If I touch the CMakeLists.txt file (by adding a space, removing it and saving), make after that correctly does not execute the steps to create foo.sym. I understand that targets created by add_custom_target are always out of date, but I thought there shouldn't be a need to re-run the custom command.
1) Is is possible to achieve what I want (relink the target if a file created after POST_BUILD is deleted) with GNU Make files?
2) As the documentation says that byproducts are ignored but the files marked as GENERATED, shouldn't GENERATED files created by POST_BUILD be added as a trigger for a new link?
3) Byproducts are added to the clean target in ninja, but in GNU Makefiles you need to add them to ADDITIONAL_MAKE_CLEAN_FILES. Shouldn't GENERATED files in POST_BUILD be automatically added to the make clean target? At least it will give parity between ninja and make's behaviors.
4) Is my issue with foo_symbols not being executed after touching CMakelists.txt a bug?