Usage of object libraries

Ive got a project Im converting over to CMake. One of the more unusual things that it involves are some custom binary config data objects it creates from object files. In the old make project it would take the .o’s, objcopy them then create a single binary from them using specific offsets and add a CRC.

Im trying to work out how I can do this using CMake without spiralling into a hole of weird complexity. I’ve got as far as figuring out I can use an
add_library(target OBJECT …)

which to begin with seems to get me started. However, next step is running objcopy on each .o in turn to create binary data files.

Initially I tried using add_custom_command() but it appears you can’t use “$<TARGET_OBJECTS:objlib>” as a dependency… As a bodge I’ve running a foreach on the list of sources, using a string regex replace to generate a .o name then adding it as a dependency in add_custom_command()… This seems to work, but now im stuck as I can’t work out how to get the path of the .o file where it was created. in the custom command it seems I can now see “$<TARGET_OBJECTS:objlib>” but it’s a list of all the obj paths, not just the one I want…

Anyone got any ideas on where to go from here? I feel like I might be completely misunderstanding cmake’s design intent… Is it really this hard?

That GenEx should be perfectly fine as dependency in a custom command.

As the content of GenEx is not available during configuration, you need to postpone your evaluation to build time.
I suggest to write the file list via file(GENERATE) into a file first. Then use a (CMake) script as custom command. In that script read that file list and do your obcopy calls in a for-loop.