cmake: don't post-process build/src/arch/xtensa/sof-platf in place

No build target should ever change files in place. This causes subtle
and time-consuming issues:

- The most obvious, logical issue is making incremental builds
  impossible: if the build stops at the "in-place" step for any reason
  then the build system does not know where to resume.

- When working on the build system itself, the file
  `build/src/arch/xtensa/sof-platf` after `make `prepare_sof_post_process`
  is different from the one after `make sof_post_process` which is
  confusing and time-consuming.

- Additional confusion in this case (not addressed by this commit): the
  final build/sof.ri is NOT generated from build/sof but from
  build/src/arch/xtensa/sof-platf instead.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
This commit is contained in:
Marc Herbert 2021-10-08 21:57:57 +00:00 committed by Liam Girdwood
parent 9823983a0f
commit 05fef94149
1 changed files with 14 additions and 4 deletions

View File

@ -241,15 +241,19 @@ endif()
target_link_libraries(sof_ld_flags INTERFACE "-Wl,-Map=sof.map")
target_link_libraries(sof_ld_flags INTERFACE "-T${PROJECT_BINARY_DIR}/${platform_ld_script}")
# Copy the linker output from the top-level to this subdirectory
add_custom_target(
prepare_sof_post_process
# "global" .ELF target used everywhere and declared and produced at the top
DEPENDS sof
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/sof sof-${fw_name}
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/sof sof-pre
)
# contains steps that should be performed before fw image is ready for being
# processed by tools like rimage and MEU
add_custom_target(sof_post_process DEPENDS prepare_sof_post_process)
add_custom_target(sof_post_process
DEPENDS process_base_module
)
# contains extra output that should be generated for bin target
add_custom_target(bin_extras)
@ -295,18 +299,24 @@ if(build_bootloader)
set(bootloader_binary_path bootloader-${fw_name})
# Add 'base_module' section to sof ELF
add_custom_target(
process_base_module
COMMAND ${CMAKE_OBJCOPY} -O binary -j .data ${PROJECT_BINARY_DIR}/src/platform/${platform_folder}/base_module mod-${fw_name}.bin
COMMAND ${CMAKE_OBJCOPY} --add-section .module=mod-${fw_name}.bin --set-section-flags .module=load,readonly sof-${fw_name}
COMMAND ${CMAKE_OBJCOPY} --add-section .module=mod-${fw_name}.bin --set-section-flags .module=load,readonly sof-pre sof-${fw_name}
DEPENDS prepare_sof_post_process base_module bootloader_dump
VERBATIM
USES_TERMINAL
)
add_dependencies(sof_post_process process_base_module)
else()
set(bootloader_binary_path)
# Do nothing / pass-through
add_custom_target(process_base_module
COMMAND ${CMAKE_COMMAND} -E copy sof-pre sof-${fw_name}
DEPENDS prepare_sof_post_process
)
endif()
if(CONFIG_BUILD_VM_ROM)