mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-31 18:47:21 +08:00
Add support for compiling modules into kernel side
Define __KERNEL__ macro during compilation and place the module in separate library Remove default library linking to m or libc on NuttX. Add these in platform layer instead, since they are different on kernel and user side Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
This commit is contained in:
@@ -125,6 +125,11 @@ define_property(GLOBAL PROPERTY PX4_MODULE_LIBRARIES
|
|||||||
FULL_DOCS "List of all PX4 module libraries"
|
FULL_DOCS "List of all PX4 module libraries"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
define_property(GLOBAL PROPERTY PX4_KERNEL_MODULE_LIBRARIES
|
||||||
|
BRIEF_DOCS "PX4 kernel side module libs"
|
||||||
|
FULL_DOCS "List of all PX4 kernel module libraries"
|
||||||
|
)
|
||||||
|
|
||||||
define_property(GLOBAL PROPERTY PX4_MODULE_PATHS
|
define_property(GLOBAL PROPERTY PX4_MODULE_PATHS
|
||||||
BRIEF_DOCS "PX4 module paths"
|
BRIEF_DOCS "PX4 module paths"
|
||||||
FULL_DOCS "List of paths to all PX4 modules"
|
FULL_DOCS "List of paths to all PX4 modules"
|
||||||
@@ -142,6 +147,7 @@ set(CONFIG "px4_sitl_default" CACHE STRING "desired configuration")
|
|||||||
|
|
||||||
include(px4_add_module)
|
include(px4_add_module)
|
||||||
set(config_module_list)
|
set(config_module_list)
|
||||||
|
set(config_kernel_list)
|
||||||
|
|
||||||
include(px4_config)
|
include(px4_config)
|
||||||
include(px4_add_board)
|
include(px4_add_board)
|
||||||
|
|||||||
@@ -147,6 +147,9 @@ function(px4_add_board)
|
|||||||
CRYPTO
|
CRYPTO
|
||||||
KEYSTORE
|
KEYSTORE
|
||||||
MULTI_VALUE
|
MULTI_VALUE
|
||||||
|
KERNEL_DRIVERS
|
||||||
|
KERNEL_MODULES
|
||||||
|
KERNEL_SYSTEMCMDS
|
||||||
DRIVERS
|
DRIVERS
|
||||||
MODULES
|
MODULES
|
||||||
SYSTEMCMDS
|
SYSTEMCMDS
|
||||||
@@ -296,6 +299,28 @@ function(px4_add_board)
|
|||||||
###########################################################################
|
###########################################################################
|
||||||
# Modules (includes drivers, examples, modules, systemcmds)
|
# Modules (includes drivers, examples, modules, systemcmds)
|
||||||
set(config_module_list)
|
set(config_module_list)
|
||||||
|
set(config_kernel_list)
|
||||||
|
|
||||||
|
if(KERNEL_DRIVERS)
|
||||||
|
foreach(driver ${KERNEL_DRIVERS})
|
||||||
|
list(APPEND config_module_list drivers/${driver})
|
||||||
|
list(APPEND config_kernel_list drivers/${driver})
|
||||||
|
endforeach()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(KERNEL_MODULES)
|
||||||
|
foreach(module ${KERNEL_MODULES})
|
||||||
|
list(APPEND config_module_list modules/${module})
|
||||||
|
list(APPEND config_kernel_list modules/${module})
|
||||||
|
endforeach()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(KERNEL_SYSTEMCMDS)
|
||||||
|
foreach(systemcmd ${KERNEL_SYSTEMCMDS})
|
||||||
|
list(APPEND config_module_list systemcmds/${systemcmd})
|
||||||
|
list(APPEND config_kernel_list systemcmds/${systemcmd})
|
||||||
|
endforeach()
|
||||||
|
endif()
|
||||||
|
|
||||||
if(DRIVERS)
|
if(DRIVERS)
|
||||||
foreach(driver ${DRIVERS})
|
foreach(driver ${DRIVERS})
|
||||||
@@ -326,5 +351,6 @@ function(px4_add_board)
|
|||||||
list(APPEND config_module_list ${board_support_src_rel}/src)
|
list(APPEND config_module_list ${board_support_src_rel}/src)
|
||||||
|
|
||||||
set(config_module_list ${config_module_list} PARENT_SCOPE)
|
set(config_module_list ${config_module_list} PARENT_SCOPE)
|
||||||
|
set(config_kernel_list ${config_kernel_list} PARENT_SCOPE)
|
||||||
|
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|||||||
@@ -43,14 +43,10 @@ function(px4_add_library target)
|
|||||||
|
|
||||||
target_compile_definitions(${target} PRIVATE MODULE_NAME="${target}")
|
target_compile_definitions(${target} PRIVATE MODULE_NAME="${target}")
|
||||||
|
|
||||||
# all PX4 libraries have access to parameters and uORB
|
add_dependencies(${target} uorb_headers parameters)
|
||||||
add_dependencies(${target} uorb_headers)
|
|
||||||
target_link_libraries(${target} PRIVATE prebuild_targets parameters_interface px4_platform uorb_msgs)
|
|
||||||
|
|
||||||
# TODO: move to platform layer
|
# all PX4 libraries have access to uORB
|
||||||
if ("${PX4_PLATFORM}" MATCHES "nuttx")
|
target_link_libraries(${target} PRIVATE prebuild_targets uorb_msgs)
|
||||||
target_link_libraries(${target} PRIVATE m nuttx_c)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set_property(GLOBAL APPEND PROPERTY PX4_MODULE_PATHS ${CMAKE_CURRENT_SOURCE_DIR})
|
set_property(GLOBAL APPEND PROPERTY PX4_MODULE_PATHS ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
px4_list_make_absolute(ABS_SRCS ${CMAKE_CURRENT_SOURCE_DIR} ${ARGN})
|
px4_list_make_absolute(ABS_SRCS ${CMAKE_CURRENT_SOURCE_DIR} ${ARGN})
|
||||||
|
|||||||
@@ -153,9 +153,26 @@ function(px4_add_module)
|
|||||||
# all modules can potentially use parameters and uORB
|
# all modules can potentially use parameters and uORB
|
||||||
add_dependencies(${MODULE} uorb_headers)
|
add_dependencies(${MODULE} uorb_headers)
|
||||||
|
|
||||||
|
# Check if the modules source dir exists in config_kernel_list
|
||||||
|
# in this case, treat is as a kernel side component for
|
||||||
|
# protected build
|
||||||
|
get_target_property(MODULE_SOURCE_DIR ${MODULE} SOURCE_DIR)
|
||||||
|
file(RELATIVE_PATH module ${PROJECT_SOURCE_DIR}/src ${MODULE_SOURCE_DIR})
|
||||||
|
|
||||||
|
list (FIND config_kernel_list ${module} _index)
|
||||||
|
if (${_index} GREATER -1)
|
||||||
|
set (KERNEL TRUE)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(NOT DYNAMIC)
|
if(NOT DYNAMIC)
|
||||||
target_link_libraries(${MODULE} PRIVATE prebuild_targets parameters_interface px4_layer px4_platform systemlib)
|
target_link_libraries(${MODULE} PRIVATE prebuild_targets parameters_interface px4_platform systemlib perf)
|
||||||
|
if (${PX4_PLATFORM} STREQUAL "nuttx" AND NOT CONFIG_BUILD_FLAT AND KERNEL)
|
||||||
|
target_link_libraries(${MODULE} PRIVATE px4_kernel_layer uORB_kernel)
|
||||||
|
set_property(GLOBAL APPEND PROPERTY PX4_KERNEL_MODULE_LIBRARIES ${MODULE})
|
||||||
|
else()
|
||||||
|
target_link_libraries(${MODULE} PRIVATE px4_layer uORB)
|
||||||
set_property(GLOBAL APPEND PROPERTY PX4_MODULE_LIBRARIES ${MODULE})
|
set_property(GLOBAL APPEND PROPERTY PX4_MODULE_LIBRARIES ${MODULE})
|
||||||
|
endif()
|
||||||
set_property(GLOBAL APPEND PROPERTY PX4_MODULE_PATHS ${CMAKE_CURRENT_SOURCE_DIR})
|
set_property(GLOBAL APPEND PROPERTY PX4_MODULE_PATHS ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
px4_list_make_absolute(ABS_SRCS ${CMAKE_CURRENT_SOURCE_DIR} ${SRCS})
|
px4_list_make_absolute(ABS_SRCS ${CMAKE_CURRENT_SOURCE_DIR} ${SRCS})
|
||||||
set_property(GLOBAL APPEND PROPERTY PX4_SRC_FILES ${ABS_SRCS})
|
set_property(GLOBAL APPEND PROPERTY PX4_SRC_FILES ${ABS_SRCS})
|
||||||
@@ -195,6 +212,10 @@ function(px4_add_module)
|
|||||||
target_compile_options(${MODULE} PRIVATE ${COMPILE_FLAGS})
|
target_compile_options(${MODULE} PRIVATE ${COMPILE_FLAGS})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if (KERNEL)
|
||||||
|
target_compile_options(${MODULE} PRIVATE -D__KERNEL__)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(INCLUDES)
|
if(INCLUDES)
|
||||||
target_include_directories(${MODULE} PRIVATE ${INCLUDES})
|
target_include_directories(${MODULE} PRIVATE ${INCLUDES})
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
Reference in New Issue
Block a user