Post-compilation step


I have a project with several custom toolchains. When using one of the toolchains and building Release I have to do som post-compile processing of the object-files before linking, so currently I have a PRE_LINK custom command inside an if-block in the code that is common for all toolchains which calls a cmake-script with all the object files as argument (-DFILES=$<TARGET_OBJECTS:${PROJECT_NAME}>) if the toolchain is X and build type is Release.

I would rather have this functionality specified in the toolchain file, so that the post-compile is done after each compilation. But I’ve hit a brick wall here and have no idea on how to solve this, or if it is even possible, and any help would be appreciated.

Expressed in makefile-ish its something like this I’m after:

%.obj : %.c
    cc %.c -o %.obj
    strip %.obj

I’m not sure that such a thing is possible as-is. You might be able to leverage the CMAKE_<LANG>_COMPILER_LAUNCHER variable to use a script to do this (though you’ll likely have to extract the output file manually).