From 2ac199d0ebe292206cd219c35d702e885442c000 Mon Sep 17 00:00:00 2001 From: Ville Juven Date: Mon, 20 Jan 2025 12:34:08 +0200 Subject: [PATCH 1/3] nuttx/CMakeLists.txt: Fix dependency for boot/init (again) The dependency should be to nuttx_app_bins target, since nsh is deleted from the /bin folder (to not allow users to execute it). Otherwise the nsh target will always be re-build (as it does not exist). Using nuttx_app_bins as the dependency fixes it, and when the content of nsh is changed it also re-triggers all relevant targets. --- platforms/nuttx/CMakeLists.txt | 2 +- platforms/nuttx/NuttX/CMakeLists.txt | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/platforms/nuttx/CMakeLists.txt b/platforms/nuttx/CMakeLists.txt index 07c9a3d9089d..fdd823f64e35 100644 --- a/platforms/nuttx/CMakeLists.txt +++ b/platforms/nuttx/CMakeLists.txt @@ -258,7 +258,7 @@ if (CONFIG_BUILD_KERNEL) COMMAND mv ${PX4_BINARY_DIR}/bin/nsh ${PX4_BINARY_DIR}/init COMMAND install -D ${PX4_BINARY_DIR}/init -t ${PX4_BINARY_DIR}/boot COMMAND rm -f ${PX4_BINARY_DIR}/init - DEPENDS ${PX4_BINARY_DIR}/bin/nsh + DEPENDS nuttx_app_bins ) add_custom_target(boot_bins DEPENDS ${PX4_BINARY_DIR}/boot/init) diff --git a/platforms/nuttx/NuttX/CMakeLists.txt b/platforms/nuttx/NuttX/CMakeLists.txt index 042d175900e5..e48507409f0e 100644 --- a/platforms/nuttx/NuttX/CMakeLists.txt +++ b/platforms/nuttx/NuttX/CMakeLists.txt @@ -277,7 +277,6 @@ if (CONFIG_BUILD_KERNEL) ELFLDNAME="${LDSCRIPT}" USERLIBS="${userlibs}" > ${CMAKE_CURRENT_BINARY_DIR}/nuttx_apps_install.log COMMAND touch nuttx_install.stamp - BYPRODUCTS ${PX4_BINARY_DIR}/bin/nsh DEPENDS ${nuttx_userlibs} nuttx_startup ) add_custom_target(nuttx_app_bins DEPENDS nuttx_install.stamp) From cdb1e4bec7bc0b7e529ff786cc68064c295ee4a5 Mon Sep 17 00:00:00 2001 From: Ville Juven Date: Mon, 20 Jan 2025 14:01:37 +0200 Subject: [PATCH 2/3] bin_romfs.cmake: Simplify the stripped_bins rule a bit The only broken dependency after this change is: ${OUTDIR}/${OUTPREFIX}_romfsimg.h The file path is a symbolic link and for some reason CMake / Ninja does not understand this. Maybe it will get fixed some day. --- platforms/nuttx/cmake/bin_romfs.cmake | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/platforms/nuttx/cmake/bin_romfs.cmake b/platforms/nuttx/cmake/bin_romfs.cmake index 113344dfbc0a..1380d021b475 100644 --- a/platforms/nuttx/cmake/bin_romfs.cmake +++ b/platforms/nuttx/cmake/bin_romfs.cmake @@ -82,6 +82,8 @@ function(make_bin_romfs) # Strip the elf files to reduce romfs image size + set(stripped_deps) + if (${STRIPPED} STREQUAL "y") # Preserve the files with debug symbols @@ -97,10 +99,8 @@ function(make_bin_romfs) DEPENDS ${DEPS} debug_${OUTPREFIX} WORKING_DIRECTORY ${BINDIR} ) - else() - add_custom_command(OUTPUT ${OUTPREFIX}_stripped_bins - COMMAND touch ${BINDIR} - ) + + list(APPEND stripped_deps ${OUTPREFIX}_stripped_bins) endif() # Make sure we have what we need @@ -128,7 +128,7 @@ function(make_bin_romfs) ${SED} 's/^unsigned char/const unsigned char/g' >${OUTPREFIX}_romfsimg.h COMMAND mv ${OUTPREFIX}_romfsimg.h ${OUTDIR}/${OUTPREFIX}_romfsimg.h COMMAND rm -f ${OUTPREFIX}_romfs.img - DEPENDS ${OUTDIR} ${DEPS} ${OUTPREFIX}_stripped_bins + DEPENDS ${OUTDIR} ${DEPS} ${stripped_deps} ) add_custom_target(${OUTPREFIX}_romfsimg DEPENDS ${OUTDIR}/${OUTPREFIX}_romfsimg.h) From 668ea5fe6b6258608b95219378a50395829dd1d9 Mon Sep 17 00:00:00 2001 From: Ville Juven Date: Tue, 21 Jan 2025 15:28:30 +0200 Subject: [PATCH 3/3] bin_romfs.cmake: Fix stripping and saving the files with debug symbols --- platforms/nuttx/cmake/bin_romfs.cmake | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/platforms/nuttx/cmake/bin_romfs.cmake b/platforms/nuttx/cmake/bin_romfs.cmake index 1380d021b475..6d39205868f2 100644 --- a/platforms/nuttx/cmake/bin_romfs.cmake +++ b/platforms/nuttx/cmake/bin_romfs.cmake @@ -87,20 +87,24 @@ function(make_bin_romfs) if (${STRIPPED} STREQUAL "y") # Preserve the files with debug symbols - add_custom_target(debug_${OUTPREFIX} + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${OUTPREFIX}_copy.stamp COMMAND cp -r ${BINDIR}/. ${BINDIR}_debug + COMMAND touch ${CMAKE_CURRENT_BINARY_DIR}/${OUTPREFIX}_copy.stamp DEPENDS ${DEPS} ) + add_custom_target(${OUTPREFIX}_copy DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OUTPREFIX}_copy.stamp) + # Then strip the binaries in place - add_custom_command(OUTPUT ${OUTPREFIX}_stripped_bins + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${OUTPREFIX}_stripped.stamp COMMAND for f in * \; do if [ -f "$$f" ]; then ${CMAKE_STRIP} $$f --strip-unneeded \; fi \; done - DEPENDS ${DEPS} debug_${OUTPREFIX} + COMMAND touch ${CMAKE_CURRENT_BINARY_DIR}/${OUTPREFIX}_stripped.stamp + DEPENDS ${DEPS} ${OUTPREFIX}_copy WORKING_DIRECTORY ${BINDIR} ) - list(APPEND stripped_deps ${OUTPREFIX}_stripped_bins) + list(APPEND stripped_deps ${CMAKE_CURRENT_BINARY_DIR}/${OUTPREFIX}_stripped.stamp) endif() # Make sure we have what we need @@ -128,7 +132,7 @@ function(make_bin_romfs) ${SED} 's/^unsigned char/const unsigned char/g' >${OUTPREFIX}_romfsimg.h COMMAND mv ${OUTPREFIX}_romfsimg.h ${OUTDIR}/${OUTPREFIX}_romfsimg.h COMMAND rm -f ${OUTPREFIX}_romfs.img - DEPENDS ${OUTDIR} ${DEPS} ${stripped_deps} + DEPENDS ${DEPS} ${stripped_deps} ) add_custom_target(${OUTPREFIX}_romfsimg DEPENDS ${OUTDIR}/${OUTPREFIX}_romfsimg.h)