intel_adsp: cmake: add_custom_command(.mod) to fix incremental build

Now building twice back to back does not build anything the second time
when CONFIG_CLEANUP_INTERMEDIATE_FILES (which obviously breaks
incremental builds) is also turned off.

Fixes commit 2906d1aa51cc ("soc/intel_adsp: Build bootloader with Zephyr")

Properly implementing custom commands requires BOTH
`add_custom_command()` and an `add_custom_target()` wrapper with some
careful DEPENDS wizardry between them.

https://cmake.org/cmake/help/latest/command/add_custom_target.html
> Use the add_custom_command() command to generate a file with
> dependencies.

The documentation of add_custom_command() also similarly refers to
add_custom_target()

When this is not done properly, the build is cursed in various, very
time-consuming ways which are not officially documented but here
instead:
https://samthursfield.wordpress.com/2015/11/21/cmake-dependencies-between-targets-and-files-and-custom-commands

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
1 file changed