How to add raw binary to be merged?

Hi, I’m starting to use CMake and I was wondering if I can mix a raw binary with linking using CMake.
This is useful for firmware development and it is used by UEFI tools (EDK2) using scripts.
Do we have a custom command that can do the trick as well?

Do you want it passed to the linker or embedded as a binary blob? I don’t think there’s an easy way for the former (adding it as a source file may work though; CMake might need to detect it as a certain LANGUAGE or something to put it through the $<TARGET_OBJECTS> codepath).

If the second, there are a number around. VTK has its own module to do this. But I don’t think CMake has any (VTK’s is probably a decent starting point though).

Hi Ben, thank you for the prompt reply. I was looking for an option to do what EDK2 does.
It uses rules for the build framework to include the raw binary (the reset vector).

[Rule.Common.SEC.RESET_VECTOR]
FILE RAW = $(NAMED_GUID) {
RAW BIN Align = 16 |.bin
}

Basically it would have the elf content for the compiled ASM and C code and then in the end, top of the file, the raw binary with the jump to the startup code.

Thank you!

I don’t know of any way to do that off-hand. You’ll likely need a linker script or set of flags to do it. target_link_options (new in CMake 3.13) would be the best way to add them, but target_link_libraries can likely be abused for older versions.