mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-03 02:21:36 +08:00
NuttX build in place
- cmake NuttX build wrapper compile in place instead of copying source tree to build directory
- slightly faster skipping necessary copying (depending on system)
- allows debugging in place
- easier to work directly in NuttX following official documentation
- simplifies overall build which should make it easier to resolve any remaining NuttX dependency issues in the build system
- the downside is switching back and forth between different builds always require rebuilding NuttX, but I think this is worth the improved developer experience
- also no longer builds px4io and bootloader in every single build, for most users these rarely change and we're wasting a lot of build time
This commit is contained in:
@@ -56,113 +56,35 @@ set(NUTTX_CONFIG_DIR ${PX4_BOARD_DIR}/nuttx-config CACHE FILEPATH "PX4 NuttX con
|
||||
set(NUTTX_DEFCONFIG ${NUTTX_CONFIG_DIR}/${NUTTX_CONFIG}/defconfig CACHE FILEPATH "path to defconfig" FORCE)
|
||||
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${NUTTX_DEFCONFIG})
|
||||
|
||||
set(NUTTX_SRC_DIR ${PX4_SOURCE_DIR}/platforms/nuttx/NuttX)
|
||||
set(NUTTX_DIR ${PX4_BINARY_DIR}/NuttX/nuttx CACHE FILEPATH "NuttX directory" FORCE)
|
||||
set(NUTTX_APPS_DIR ${PX4_BINARY_DIR}/NuttX/apps CACHE FILEPATH "NuttX apps directory" FORCE)
|
||||
set(NUTTX_SRC_DIR ${PX4_SOURCE_DIR}/platforms/nuttx/NuttX)
|
||||
set(NUTTX_DIR ${PX4_SOURCE_DIR}/platforms/nuttx/NuttX/nuttx CACHE FILEPATH "NuttX directory" FORCE)
|
||||
set(NUTTX_APPS_DIR ${PX4_SOURCE_DIR}/platforms/nuttx/NuttX/apps CACHE FILEPATH "NuttX apps directory" FORCE)
|
||||
|
||||
px4_add_git_submodule(TARGET git_nuttx PATH "${NUTTX_SRC_DIR}/nuttx")
|
||||
px4_add_git_submodule(TARGET git_nuttx_apps PATH "${NUTTX_SRC_DIR}/apps")
|
||||
|
||||
if(CMAKE_HOST_APPLE OR CMAKE_HOST_WIN32)
|
||||
# copy with rsync and create file dependencies
|
||||
set(NUTTX_COPY_CMD "rsync")
|
||||
set(NUTTX_COPY_CMD_OPTS)
|
||||
list(APPEND NUTTX_COPY_CMD_OPTS
|
||||
-rp
|
||||
--inplace
|
||||
)
|
||||
else()
|
||||
# copy with hard links
|
||||
# archive, recursive, force, link (hardlinks)
|
||||
set(NUTTX_COPY_CMD "cp")
|
||||
set(NUTTX_COPY_CMD_OPTS "-aRfl")
|
||||
endif()
|
||||
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${PX4_BINARY_DIR}/NuttX)
|
||||
|
||||
###############################################################################
|
||||
# NuttX: copy to build directory
|
||||
###############################################################################
|
||||
if((NOT EXISTS ${PX4_BINARY_DIR}/NuttX/nuttx_copy.stamp) OR (NOT EXISTS ${PX4_BINARY_DIR}/NuttX/nuttx/Kconfig))
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${PX4_BINARY_DIR}/NuttX/nuttx)
|
||||
file(RELATIVE_PATH CP_SRC ${CMAKE_SOURCE_DIR} ${NUTTX_SRC_DIR}/nuttx)
|
||||
file(RELATIVE_PATH CP_DST ${CMAKE_SOURCE_DIR} ${PX4_BINARY_DIR}/NuttX)
|
||||
execute_process(COMMAND ${NUTTX_COPY_CMD} ${NUTTX_COPY_CMD_OPTS} ${CP_SRC} ${CP_DST} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
|
||||
|
||||
# replace NuttX .git with actual git repo location (absolute path)
|
||||
execute_process(
|
||||
COMMAND git rev-parse --absolute-git-dir
|
||||
OUTPUT_VARIABLE nuttx_git_dir
|
||||
WORKING_DIRECTORY ${NUTTX_SRC_DIR}/nuttx
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E remove ${PX4_BINARY_DIR}/NuttX/nuttx/.git)
|
||||
file(WRITE ${PX4_BINARY_DIR}/NuttX/nuttx/.git "gitdir: ${nuttx_git_dir}")
|
||||
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E touch ${PX4_BINARY_DIR}/NuttX/nuttx_copy.stamp)
|
||||
endif()
|
||||
|
||||
###############################################################################
|
||||
# NuttX apps: copy to build directory
|
||||
###############################################################################
|
||||
if((NOT EXISTS ${PX4_BINARY_DIR}/NuttX/apps_copy.stamp) OR (NOT EXISTS ${PX4_BINARY_DIR}/NuttX/apps/Kconfig))
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${PX4_BINARY_DIR}/NuttX/apps)
|
||||
file(RELATIVE_PATH CP_SRC ${CMAKE_SOURCE_DIR} ${NUTTX_SRC_DIR}/apps)
|
||||
file(RELATIVE_PATH CP_DST ${CMAKE_SOURCE_DIR} ${PX4_BINARY_DIR}/NuttX)
|
||||
execute_process(COMMAND ${NUTTX_COPY_CMD} ${NUTTX_COPY_CMD_OPTS} ${CP_SRC} ${CP_DST} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E touch ${PX4_BINARY_DIR}/NuttX/apps_copy.stamp)
|
||||
endif()
|
||||
|
||||
###############################################################################
|
||||
# board nuttx-config
|
||||
###############################################################################
|
||||
|
||||
# If the board provides a Kconfig Use it or create an empty one
|
||||
if((NOT EXISTS ${PX4_BINARY_DIR}/NuttX/nuttx_config_kconfig.stamp) OR (NOT EXISTS ${NUTTX_DIR}/boards/dummy/Kconfig))
|
||||
if(EXISTS ${NUTTX_CONFIG_DIR}/Kconfig)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${NUTTX_CONFIG_DIR}/Kconfig ${NUTTX_DIR}/boards/dummy/Kconfig)
|
||||
else()
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E touch ${NUTTX_DIR}/boards/dummy/Kconfig)
|
||||
endif()
|
||||
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E touch ${PX4_BINARY_DIR}/NuttX/nuttx_config_kconfig.stamp)
|
||||
endif()
|
||||
|
||||
if((NOT EXISTS ${PX4_BINARY_DIR}/NuttX/nuttx_copy_config_dir.stamp) OR (NOT EXISTS ${PX4_BINARY_DIR}/NuttX/nuttx-config/drivers/Kconfig))
|
||||
# copy board's nuttx-config to NuttX/nuttx-config
|
||||
file(RELATIVE_PATH CP_SRC ${CMAKE_SOURCE_DIR} ${PX4_BOARD_DIR}/nuttx-config)
|
||||
file(RELATIVE_PATH CP_DST ${CMAKE_SOURCE_DIR} ${PX4_BINARY_DIR}/NuttX)
|
||||
execute_process(COMMAND ${NUTTX_COPY_CMD} ${NUTTX_COPY_CMD_OPTS} ${CP_SRC} ${CP_DST} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
|
||||
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${PX4_BINARY_DIR}/NuttX/nuttx-config/drivers)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E touch ${PX4_BINARY_DIR}/NuttX/nuttx-config/drivers/Kconfig)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${PX4_BINARY_DIR}/NuttX/nuttx-config/src)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${NUTTX_SRC_DIR}/nsh_romfsimg.h ${PX4_BINARY_DIR}/NuttX/nuttx-config/include/nsh_romfsimg.h)
|
||||
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E touch ${PX4_BINARY_DIR}/NuttX/nuttx_copy_config_dir.stamp)
|
||||
endif()
|
||||
|
||||
# make olddefconfig (inflate defconfig to full .config)
|
||||
if((NOT EXISTS ${PX4_BINARY_DIR}/NuttX/nuttx_olddefconfig.stamp) OR (NOT EXISTS ${PX4_BINARY_DIR}/NuttX/nuttx/.config))
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${NUTTX_SRC_DIR}/Make.defs.in ${NUTTX_DIR}/Make.defs) # Create a temporary Toplevel Make.defs for the oldconfig step
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${NUTTX_DEFCONFIG} ${NUTTX_DIR}/.config)
|
||||
execute_process(
|
||||
COMMAND ${NUTTX_SRC_DIR}/tools/px4_nuttx_make_olddefconfig.sh
|
||||
WORKING_DIRECTORY ${NUTTX_DIR}
|
||||
OUTPUT_FILE nuttx_olddefconfig.log
|
||||
RESULT_VARIABLE ret
|
||||
)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E touch ${PX4_BINARY_DIR}/NuttX/nuttx_olddefconfig.stamp)
|
||||
# remove temporary top level Make.defs
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E remove -f ${NUTTX_DIR}/Make.defs)
|
||||
endif()
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${NUTTX_CONFIG_DIR}/src) # needed for NuttX build
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${NUTTX_SRC_DIR}/Make.defs.in ${NUTTX_DIR}/Make.defs) # Create a temporary Toplevel Make.defs for the oldconfig step
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${NUTTX_DEFCONFIG} ${NUTTX_DIR}/.config)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${NUTTX_DEFCONFIG} ${NUTTX_DIR}/defconfig)
|
||||
|
||||
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${NUTTX_DIR}/defconfig)
|
||||
|
||||
execute_process(
|
||||
COMMAND ${NUTTX_SRC_DIR}/tools/px4_nuttx_make_olddefconfig.sh
|
||||
WORKING_DIRECTORY ${NUTTX_DIR}
|
||||
OUTPUT_FILE ${CMAKE_CURRENT_BINARY_DIR}/nuttx_olddefconfig.log
|
||||
RESULT_VARIABLE ret
|
||||
)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${NUTTX_DIR}/.config ${PX4_BINARY_DIR}/NuttX/nuttx/.config)
|
||||
|
||||
###############################################################################
|
||||
# NuttX cmake defconfig
|
||||
###############################################################################
|
||||
|
||||
# parse nuttx config options for cmake
|
||||
file(STRINGS ${NUTTX_DIR}/.config ConfigContents)
|
||||
file(STRINGS ${PX4_BINARY_DIR}/NuttX/nuttx/.config ConfigContents)
|
||||
foreach(NameAndValue ${ConfigContents})
|
||||
# Strip leading spaces
|
||||
string(REGEX REPLACE "^[ ]+" "" NameAndValue ${NameAndValue})
|
||||
|
||||
Reference in New Issue
Block a user