cmake fix ROMFS build dependencies

This commit is contained in:
Daniel Agar 2019-04-03 09:56:58 -04:00
parent 296d7900a0
commit 0c226e9b64
1 changed files with 44 additions and 28 deletions

View File

@ -78,7 +78,12 @@ file(GLOB jinja_templates ${PX4_SOURCE_DIR}/Tools/serial/*.jinja)
if (px4_constrained_flash_build)
set(added_arguments --constrained-flash)
endif()
add_custom_command(OUTPUT ${romfs_gen_root_dir}/init.d/rcS ${romfs_gen_root_dir}/init.d/rc.serial ${romfs_gen_root_dir}/init.d/rc.autostart
add_custom_command(
OUTPUT
${romfs_gen_root_dir}/init.d/rcS
${romfs_gen_root_dir}/init.d/rc.serial
${romfs_gen_root_dir}/init.d/rc.autostart
romfs_copy.stamp
COMMAND ${CMAKE_COMMAND} -E remove_directory ${romfs_gen_root_dir}
# TODO: we should only copy the files in ${romfs_copy_files}
COMMAND ${CMAKE_COMMAND} -E copy_directory ${romfs_src_dir} ${romfs_gen_root_dir}
@ -95,6 +100,7 @@ add_custom_command(OUTPUT ${romfs_gen_root_dir}/init.d/rcS ${romfs_gen_root_dir}
--rc-dir ${romfs_gen_root_dir}/init.d
--serial-ports ${board_serial_ports} ${added_arguments}
--config-files ${module_config_files} #--verbose
COMMAND ${CMAKE_COMMAND} -E touch romfs_copy.stamp
DEPENDS
${jinja_templates}
${module_config_files}
@ -138,16 +144,20 @@ foreach(board_rc_file ${OPTIONAL_BOARD_RC})
if(EXISTS "${PX4_BOARD_DIR}/init/${board_rc_file}")
message(STATUS "ROMFS: Adding ${board_rc_file}")
add_custom_command(OUTPUT ${romfs_gen_root_dir}/init.d/${board_rc_file}
add_custom_command(
OUTPUT
${romfs_gen_root_dir}/init.d/${board_rc_file}
${board_rc_file}.stamp
COMMAND ${CMAKE_COMMAND} -E copy ${PX4_BOARD_DIR}/init/${board_rc_file} ${romfs_gen_root_dir}/init.d/${board_rc_file}
COMMAND ${CMAKE_COMMAND} -E touch ${board_rc_file}.stamp
DEPENDS
${PX4_BOARD_DIR}/init/${board_rc_file}
${romfs_gen_root_dir}/init.d/rcS
romfs_copy.stamp
COMMENT "ROMFS: copying ${board_rc_file}"
)
list(APPEND extras_dependencies
${romfs_gen_root_dir}/init.d/${board_rc_file}
${board_rc_file}.stamp
)
endif()
@ -159,8 +169,7 @@ add_custom_command(OUTPUT romfs_extras.stamp
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PX4_BINARY_DIR}/romfs_extras/ ${romfs_gen_root_dir}/extras/
COMMAND ${CMAKE_COMMAND} -E touch romfs_extras.stamp
DEPENDS
${romfs_gen_root_dir}/init.d/rcS
${romfs_gen_root_dir}/init.d/rc.autostart
romfs_copy.stamp
${extras_dependencies}
COMMENT "ROMFS: copying extras"
)
@ -170,8 +179,7 @@ add_custom_command(
COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/px_romfs_pruner.py --folder ${romfs_gen_root_dir} --board ${PX4_BOARD}
COMMAND ${CMAKE_COMMAND} -E touch romfs_pruned.stamp
DEPENDS
${romfs_gen_root_dir}/init.d/rcS
${romfs_gen_root_dir}/init.d/rc.autostart
romfs_copy.stamp
romfs_extras.stamp
${PX4_SOURCE_DIR}/Tools/px_romfs_pruner.py
COMMENT "ROMFS: pruning"
@ -184,7 +192,7 @@ if("${CONFIG_FS_CROMFS}" STREQUAL "y")
COMMAND ${CMAKE_COMMAND} -E copy gencromfs ${CMAKE_BINARY_DIR}/gencromfs
DEPENDS ${PX4_SOURCE_DIR}/platforms/nuttx/NuttX/nuttx/tools/gencromfs.c
WORKING_DIRECTORY ${NUTTX_DIR}/tools
)
)
# create nsh_romfsimg.c
add_custom_command(OUTPUT nsh_romfsimg.c
@ -192,37 +200,45 @@ if("${CONFIG_FS_CROMFS}" STREQUAL "y")
COMMAND ${CMAKE_BINARY_DIR}/gencromfs ${romfs_gen_root_dir} nsh_romfsimg.c
DEPENDS
${CMAKE_BINARY_DIR}/gencromfs
${romfs_gen_root_dir}/init.d/rcS
${romfs_gen_root_dir}/init.d/rc.autostart
romfs_extras.stamp
romfs_pruned.stamp
COMMENT "ROMFS: generating image"
)
)
else()
# create romfs.img
find_program(GENROMFS genromfs)
if(NOT GENROMFS)
message(FATAL_ERROR "genromfs not found")
message(FATAL_ERROR "genromfs not found")
endif()
add_custom_command(OUTPUT romfs.img romfs.txt
add_custom_command(
OUTPUT
romfs.img
romfs.txt
COMMAND ${CMAKE_COMMAND} -E remove -f romfs.img romfs.txt
COMMAND ${GENROMFS} -f romfs.img -d ${romfs_gen_root_dir} -V "NSHInitVol" -v > romfs.txt 2>&1
DEPENDS romfs_pruned.stamp
COMMENT "ROMFS: generating image"
)
)
# create nsh_romfsimg.c
find_program(XXD xxd)
if(NOT XXD)
message(FATAL_ERROR "xxd not found")
endif()
add_custom_command(OUTPUT nsh_romfsimg.c
COMMAND ${CMAKE_COMMAND} -E remove -f nsh_romfsimg.c
COMMAND ${XXD} -i romfs.img nsh_romfsimg.c
COMMAND sed 's/unsigned/const unsigned/g' nsh_romfsimg.c > nsh_romfsimg.c.tmp && ${CMAKE_COMMAND} -E rename nsh_romfsimg.c.tmp nsh_romfsimg.c
DEPENDS romfs.img
)
# create nsh_romfsimg.c
find_program(XXD xxd)
if(NOT XXD)
message(FATAL_ERROR "xxd not found")
endif()
find_program(SED sed)
if(NOT SED)
message(FATAL_ERROR "sed not found")
endif()
add_custom_command(OUTPUT nsh_romfsimg.c
COMMAND ${CMAKE_COMMAND} -E remove -f nsh_romfsimg.c
COMMAND ${XXD} -i romfs.img nsh_romfsimg.c
COMMAND ${SED} 's/unsigned/const unsigned/g' nsh_romfsimg.c > nsh_romfsimg.c.tmp && ${CMAKE_COMMAND} -E rename nsh_romfsimg.c.tmp nsh_romfsimg.c
DEPENDS romfs.img
)
endif()
@ -248,5 +264,5 @@ if(SHELLCHECK_PATH)
DEPENDS ${romfs_gen_root_dir}/init.d/rc.autostart
WORKING_DIRECTORY ${romfs_gen_root_dir}
USES_TERMINAL
)
)
endif()