Support for os abstraction.

This commit is contained in:
James Goppert
2015-09-07 23:58:31 -04:00
parent 1d6b31d196
commit 29520c0834
5 changed files with 156 additions and 78 deletions
+21 -25
View File
@@ -56,6 +56,9 @@
# Functions/Macros # Functions/Macros
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# #
# * Use px4_parse_function_args to parse functions and check for required
# arguments.
#
# * Never use macros. They allow overwriting global variables and this # * Never use macros. They allow overwriting global variables and this
# makes variable declarations hard to locate. # makes variable declarations hard to locate.
# #
@@ -107,9 +110,17 @@ set(package-contact "px4users@googlegroups.com")
# #
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
include(px4_${OS}_utils)
include(px4_utils) set(px4_required_functions
include(px4_nuttx_utils) px4_os_add_firmware
px4_os_prebuild_targets
px4_os_add_flags
)
foreach(cmd ${px4_required_functions})
if(NOT COMMAND ${cmd})
message(FATAL_ERROR "cmake/px4_${OS}_utils.cmake must implement ${cmd}")
endif()
endforeach()
#============================================================================= #=============================================================================
# parameters # parameters
@@ -124,8 +135,8 @@ set_property(CACHE BOARD PROPERTY STRINGS px4fmu-v2 sitl)
set(LABEL "simple" CACHE STRING "module set label") set(LABEL "simple" CACHE STRING "module set label")
set_property(CACHE LABEL PROPERTY STRINGS simple default) set_property(CACHE LABEL PROPERTY STRINGS simple default)
set(NUTTX_BUILD_THREADS "4" CACHE STRING set(THREADS "4" CACHE STRING
"number of threads to use when building NuttX") "number of threads to use for external build processes")
set(required_toolchain_variables set(required_toolchain_variables
CMAKE_C_COMPILER_ID CMAKE_C_COMPILER_ID
@@ -159,27 +170,14 @@ add_custom_target(submodule_clean
#============================================================================= #=============================================================================
# external libraries # external libraries
# #
if(${OS} STREQUAL "nuttx") px4_os_prebuild_targets(OUT prebuild_targets
px4_nuttx_add_export(OUT nuttx_export BOARD ${BOARD}
CONFIG ${BOARD} THREADS ${THREADS})
THREADS ${NUTTX_BUILD_THREADS}
DEPENDS git_nuttx)
endif()
#============================================================================= #=============================================================================
# build flags # build flags
# #
px4_os_add_flags(
px4_add_common_flags(
C_FLAGS c_flags
CXX_FLAGS cxx_flags
EXE_LINKER_FLAGS exe_linker_flags
INCLUDE_DIRS include_dirs
LINK_DIRS link_dirs
DEFINITIONS definitions)
if(${OS} STREQUAL "nuttx")
px4_add_nuttx_flags(
BOARD ${BOARD} BOARD ${BOARD}
C_FLAGS c_flags C_FLAGS c_flags
CXX_FLAGS cxx_flags CXX_FLAGS cxx_flags
@@ -187,12 +185,10 @@ if(${OS} STREQUAL "nuttx")
INCLUDE_DIRS include_dirs INCLUDE_DIRS include_dirs
LINK_DIRS link_dirs LINK_DIRS link_dirs
DEFINITIONS definitions) DEFINITIONS definitions)
endif()
px4_join(OUT CMAKE_EXE_LINKER_FLAGS LIST "${exe_linker_flags}" GLUE " ") px4_join(OUT CMAKE_EXE_LINKER_FLAGS LIST "${exe_linker_flags}" GLUE " ")
px4_join(OUT CMAKE_C_FLAGS LIST "${c_flags}" GLUE " ") px4_join(OUT CMAKE_C_FLAGS LIST "${c_flags}" GLUE " ")
px4_join(OUT CMAKE_CXX_FLAGS LIST "${cxx_flags}" GLUE " ") px4_join(OUT CMAKE_CXX_FLAGS LIST "${cxx_flags}" GLUE " ")
include_directories(${include_dirs}) include_directories(${include_dirs})
link_directories(${link_dirs}) link_directories(${link_dirs})
add_definitions(${definitions}) add_definitions(${definitions})
+82 -18
View File
@@ -31,9 +31,28 @@
# #
############################################################################ ############################################################################
#=============================================================================
#
# Defined functions in this file
#
# OS Specific Functions
#
# * px4_nuttx_add_firmware
# * px4_nuttx_generate_builtin_commands
# * px4_nuttx_add_export
# * px4_nuttx_generate_romfs
#
# Required OS Inteface Functions
#
# * px4_os_add_flags
# * px4_os_prebuild_targets
#
include(px4_utils) include(px4_utils)
#---------------------------------------------------------------------------- #=============================================================================
#
# px4_nuttx_add_firmware # px4_nuttx_add_firmware
# #
# This function adds a nuttx firmware target. # This function adds a nuttx firmware target.
@@ -53,7 +72,6 @@ include(px4_utils)
# Example: # Example:
# px4_nuttx_add_firmware(TARGET fw_test EXE test) # px4_nuttx_add_firmware(TARGET fw_test EXE test)
# #
#----------------------------------------------------------------------------
function(px4_nuttx_add_firmware) function(px4_nuttx_add_firmware)
px4_parse_function_args( px4_parse_function_args(
NAME px4_nuttx_add_firmware NAME px4_nuttx_add_firmware
@@ -74,7 +92,8 @@ function(px4_nuttx_add_firmware)
) )
endfunction() endfunction()
#---------------------------------------------------------------------------- #=============================================================================
#
# px4_nuttx_generate_builtin_commands # px4_nuttx_generate_builtin_commands
# #
# This function generates the builtin_commands.c src for nuttx # This function generates the builtin_commands.c src for nuttx
@@ -91,9 +110,9 @@ endfunction()
# OUT : generated builtin_commands.c src # OUT : generated builtin_commands.c src
# #
# Example: # Example:
# px4_nuttx_generate_builtin_commands(OUT <generated-src> MODULE_LIST px4_simple_app) # px4_nuttx_generate_builtin_commands(
# OUT <generated-src> MODULE_LIST px4_simple_app)
# #
#----------------------------------------------------------------------------
function(px4_nuttx_generate_builtin_commands) function(px4_nuttx_generate_builtin_commands)
px4_parse_function_args( px4_parse_function_args(
NAME px4_nuttx_generate_builtin_commands NAME px4_nuttx_generate_builtin_commands
@@ -127,11 +146,12 @@ function(px4_nuttx_generate_builtin_commands)
${OUT}) ${OUT})
endfunction() endfunction()
#---------------------------------------------------------------------------- #=============================================================================
#
# px4_nuttx_add_export # px4_nuttx_add_export
# #
# This function generates a nuttx export. # This function generates a nuttx export.
#
# Usage: # Usage:
# px4_nuttx_add_export( # px4_nuttx_add_export(
# OUT <out-target> # OUT <out-target>
@@ -148,7 +168,6 @@ endfunction()
# Example: # Example:
# px4_nuttx_add_export(OUT nuttx_export CONFIG px4fmu-v2) # px4_nuttx_add_export(OUT nuttx_export CONFIG px4fmu-v2)
# #
#----------------------------------------------------------------------------
function(px4_nuttx_add_export) function(px4_nuttx_add_export)
px4_parse_function_args( px4_parse_function_args(
@@ -215,7 +234,8 @@ function(px4_nuttx_add_export)
endfunction() endfunction()
#---------------------------------------------------------------------------- #=============================================================================
#
# px4_nuttx_generate_romfs # px4_nuttx_generate_romfs
# #
# The functions generates the ROMFS filesystem for nuttx. # The functions generates the ROMFS filesystem for nuttx.
@@ -232,7 +252,6 @@ endfunction()
# Example: # Example:
# px4_nuttx_generate_romfs(OUT my_romfs ROOT "ROMFS/my_board") # px4_nuttx_generate_romfs(OUT my_romfs ROOT "ROMFS/my_board")
# #
#----------------------------------------------------------------------------
function(px4_nuttx_generate_romfs) function(px4_nuttx_generate_romfs)
px4_parse_function_args( px4_parse_function_args(
@@ -257,13 +276,14 @@ function(px4_nuttx_generate_romfs)
endfunction() endfunction()
#---------------------------------------------------------------------------- #=============================================================================
# px4_add_nuttx_flags #
# px4_add_flags
# #
# Set ths nuttx build flags. # Set ths nuttx build flags.
# #
# Usage: # Usage:
# px4_add_nuttx_flags( # px4_add_flags(
# C_FLAGS <inout-variable> # C_FLAGS <inout-variable>
# CXX_FLAGS <inout-variable> # CXX_FLAGS <inout-variable>
# EXE_LINKER_FLAGS <inout-variable> # EXE_LINKER_FLAGS <inout-variable>
@@ -273,7 +293,7 @@ endfunction()
# #
# Input: # Input:
# BOARD : flags depend on board/nuttx config # BOARD : flags depend on board/nuttx config
#
# Input/Output: (appends to existing variable) # Input/Output: (appends to existing variable)
# C_FLAGS : c compile flags variable # C_FLAGS : c compile flags variable
# CXX_FLAGS : c++ compile flags variable # CXX_FLAGS : c++ compile flags variable
@@ -283,24 +303,32 @@ endfunction()
# DEFINITIONS : definitions # DEFINITIONS : definitions
# #
# Example: # Example:
# px4_add_nuttx_flags( # px4_add_flags(
# C_FLAGS CMAKE_C_FLAGS # C_FLAGS CMAKE_C_FLAGS
# CXX_FLAGS CMAKE_CXX_FLAGS # CXX_FLAGS CMAKE_CXX_FLAGS
# EXE_LINKER_FLAG CMAKE_EXE_LINKER_FLAGS # EXE_LINKER_FLAG CMAKE_EXE_LINKER_FLAGS
# INCLUDES <list>) # INCLUDES <list>)
# #
#---------------------------------------------------------------------------- function(px4_add_flags)
function(px4_add_nuttx_flags)
set(inout_vars set(inout_vars
C_FLAGS CXX_FLAGS EXE_LINKER_FLAGS INCLUDE_DIRS LINK_DIRS DEFINITIONS) C_FLAGS CXX_FLAGS EXE_LINKER_FLAGS INCLUDE_DIRS LINK_DIRS DEFINITIONS)
px4_parse_function_args( px4_parse_function_args(
NAME px4_add_nuttx_flags NAME px4_add_flags
ONE_VALUE ${inout_vars} BOARD ONE_VALUE ${inout_vars} BOARD
REQUIRED ${inout_vars} BOARD REQUIRED ${inout_vars} BOARD
ARGN ${ARGN}) ARGN ${ARGN})
px4_add_common_flags(
BOARD ${BOARD}
C_FLAGS ${C_FLAGS}
CXX_FLAGS ${CXX_FLAGS}
EXE_LINKER_FLAGS ${EXE_LINKER_FLAGS}
INCLUDE_DIRS ${INCLUDE_DIRS}
LINK_DIRS ${LINK_DIRS}
DEFINITIONS ${DEFINITIONS})
set(nuttx_export_dir ${CMAKE_BINARY_DIR}/${BOARD}/NuttX/nuttx-export) set(nuttx_export_dir ${CMAKE_BINARY_DIR}/${BOARD}/NuttX/nuttx-export)
set(added_include_dirs set(added_include_dirs
${nuttx_export_dir}/include ${nuttx_export_dir}/include
@@ -341,8 +369,44 @@ function(px4_add_nuttx_flags)
foreach(var ${inout_vars}) foreach(var ${inout_vars})
string(TOLOWER ${var} lower_var) string(TOLOWER ${var} lower_var)
set(${${var}} ${${${var}}} ${added_${lower_var}} PARENT_SCOPE) set(${${var}} ${${${var}}} ${added_${lower_var}} PARENT_SCOPE)
message(STATUS "nuttx: set(${${var}} ${${${var}}} ${added_${lower_var}} PARENT_SCOPE)")
endforeach() endforeach()
endfunction() endfunction()
#=============================================================================
#
# px4_prebuild_targets
#
# This function generates os dependent targets
# Usage:
# px4_os_prebuild_targets(
# OUT <out-list_of_targets>
# BOARD <in-string>
# )
#
# Input:
# BOARD : board
# THREADS : number of threads for building
#
# Output:
# OUT : the target list
#
# Example:
# px4_os_prebuild_targets(OUT target_list BOARD px4fmu-v2)
#
function(px4_prebuild_targets)
px4_parse_function_args(
NAME px4_add_os_libraries
ONE_VALUE OUT BOARD THREADS
REQUIRED OUT BOARD
ARGN ${ARGN})
px4_nuttx_add_export(OUT nuttx_export
CONFIG ${BOARD}
THREADS ${THREADS}
DEPENDS git_nuttx)
add_custom_target(${OUT} DEPENDS nuttx_export)
endfunction()
# vim: set noet fenc=utf-8 ff=unix nowrap: # vim: set noet fenc=utf-8 ff=unix nowrap:
+48 -29
View File
@@ -31,9 +31,26 @@
# #
############################################################################ ############################################################################
#=============================================================================
#
# Defined functions in this file
#
# utility functions
#
# * px4_parse_function_args
# * px4_add_git_submodule
# * px4_prepend_string
# * px4_join
# * px4_add_module
# * px4_generate_messages
# * px4_add_upload
# * px4_add_common_flags
#
include(CMakeParseArguments) include(CMakeParseArguments)
#---------------------------------------------------------------------------- #=============================================================================
#
# px4_parse_function_args # px4_parse_function_args
# #
# This function simpliies usage of the cmake_parse_arguments module. # This function simpliies usage of the cmake_parse_arguments module.
@@ -78,7 +95,6 @@ include(CMakeParseArguments)
# name: hello # name: hello
# list: a b c # list: a b c
# #
#----------------------------------------------------------------------------
function(px4_parse_function_args) function(px4_parse_function_args)
cmake_parse_arguments(IN "" "NAME" "OPTIONS;ONE_VALUE;MULTI_VALUE;REQUIRED;ARGN" "${ARGN}") cmake_parse_arguments(IN "" "NAME" "OPTIONS;ONE_VALUE;MULTI_VALUE;REQUIRED;ARGN" "${ARGN}")
cmake_parse_arguments(OUT "${IN_OPTIONS}" "${IN_ONE_VALUE}" "${IN_MULTI_VALUE}" "${IN_ARGN}") cmake_parse_arguments(OUT "${IN_OPTIONS}" "${IN_ONE_VALUE}" "${IN_MULTI_VALUE}" "${IN_ARGN}")
@@ -95,13 +111,14 @@ function(px4_parse_function_args)
endforeach() endforeach()
endfunction() endfunction()
#---------------------------------------------------------------------------- #=============================================================================
# add_git_submodule #
# px4_add_git_submodule
# #
# This function add a git submodule target. # This function add a git submodule target.
# #
# Usage: # Usage:
# add_git_submodule(TARGET <target> PATH <path>) # px4_add_git_submodule(TARGET <target> PATH <path>)
# #
# Input: # Input:
# PATH : git submodule path # PATH : git submodule path
@@ -110,9 +127,8 @@ endfunction()
# TARGET : git target # TARGET : git target
# #
# Example: # Example:
# add_git_submodule(TARGET git_nuttx PATH "NuttX") # px4_add_git_submodule(TARGET git_nuttx PATH "NuttX")
# #
#----------------------------------------------------------------------------
function(px4_add_git_submodule) function(px4_add_git_submodule)
px4_parse_function_args( px4_parse_function_args(
NAME px4_add_git_submodule NAME px4_add_git_submodule
@@ -131,7 +147,8 @@ function(px4_add_git_submodule)
) )
endfunction() endfunction()
#---------------------------------------------------------------------------- #=============================================================================
#
# px4_prepend_string # px4_prepend_string
# #
# This function prepends a string to a list # This function prepends a string to a list
@@ -152,7 +169,6 @@ endfunction()
# path/to/src/file1.cpp # path/to/src/file1.cpp
# path/to/src/file2.cpp # path/to/src/file2.cpp
# #
#----------------------------------------------------------------------------
function(px4_prepend_string) function(px4_prepend_string)
px4_parse_function_args( px4_parse_function_args(
NAME px4_prepend_string NAME px4_prepend_string
@@ -167,7 +183,8 @@ function(px4_prepend_string)
set(${OUT} ${${OUT}} PARENT_SCOPE) set(${OUT} ${${OUT}} PARENT_SCOPE)
endfunction() endfunction()
#---------------------------------------------------------------------------- #=============================================================================
#
# px4_join # px4_join
# #
# This function joins a list with a given separator. If list is not # This function joins a list with a given separator. If list is not
@@ -188,7 +205,6 @@ endfunction()
# test_join would then be: # test_join would then be:
# "a;b;c" # "a;b;c"
# #
#----------------------------------------------------------------------------
function(px4_join) function(px4_join)
px4_parse_function_args( px4_parse_function_args(
NAME px4_join NAME px4_join
@@ -200,7 +216,8 @@ function(px4_join)
set(${OUT} ${_TMP_STR} PARENT_SCOPE) set(${OUT} ${_TMP_STR} PARENT_SCOPE)
endfunction() endfunction()
#---------------------------------------------------------------------------- #=============================================================================
#
# px4_add_module # px4_add_module
# #
# This function builds a static library from a module description. # This function builds a static library from a module description.
@@ -236,7 +253,6 @@ endfunction()
# git_nuttx # git_nuttx
# ) # )
# #
#----------------------------------------------------------------------------
function(px4_add_module) function(px4_add_module)
px4_parse_function_args( px4_parse_function_args(
NAME px4_add_module NAME px4_add_module
@@ -264,11 +280,12 @@ function(px4_add_module)
set_target_properties(${MODULE} PROPERTIES LINK_INTERFACE_MULTIPLICITY 4) set_target_properties(${MODULE} PROPERTIES LINK_INTERFACE_MULTIPLICITY 4)
endfunction() endfunction()
#---------------------------------------------------------------------------- #=============================================================================
#
# px4_generate_messages # px4_generate_messages
# #
# This function generates source code from ROS msg definitions. # This function generates source code from ROS msg definitions.
#
# Usage: # Usage:
# px4_generate_messages(TARGET <target> MSGS <msg-files>) # px4_generate_messages(TARGET <target> MSGS <msg-files>)
# #
@@ -286,7 +303,6 @@ endfunction()
# [ DEPENDS <dependencies> ] # [ DEPENDS <dependencies> ]
# ) # )
# #
#----------------------------------------------------------------------------
function(px4_generate_messages) function(px4_generate_messages)
px4_parse_function_args( px4_parse_function_args(
NAME px4_generate_messages NAME px4_generate_messages
@@ -349,11 +365,12 @@ function(px4_generate_messages)
DEPENDS ${msg_multi_files_out} ${msg_files_out}) DEPENDS ${msg_multi_files_out} ${msg_files_out})
endfunction() endfunction()
#---------------------------------------------------------------------------- #=============================================================================
#
# px4_add_upload # px4_add_upload
# #
# This function generates source code from ROS msg definitions. # This function generates source code from ROS msg definitions.
#
# Usage: # Usage:
# px4_add_upload(OUT <target> BUNDLE <file.px4>) # px4_add_upload(OUT <target> BUNDLE <file.px4>)
# #
@@ -370,7 +387,6 @@ endfunction()
# BUNDLE main.px4 # BUNDLE main.px4
# ) # )
# #
#----------------------------------------------------------------------------
function(px4_add_upload) function(px4_add_upload)
px4_parse_function_args( px4_parse_function_args(
NAME px4_generate_messages NAME px4_generate_messages
@@ -403,13 +419,15 @@ function(px4_add_upload)
) )
endfunction() endfunction()
#---------------------------------------------------------------------------- #=============================================================================
#
# px4_add_common_flags # px4_add_common_flags
# #
# Set ths default build flags. # Set ths default build flags.
# #
# Usage: # Usage:
# px4_add_common_flags( # px4_add_common_flags(
# BOARD <in-string>
# C_FLAGS <inout-variable> # C_FLAGS <inout-variable>
# CXX_FLAGS <inout-variable> # CXX_FLAGS <inout-variable>
# EXE_LINKER_FLAGS <inout-variable> # EXE_LINKER_FLAGS <inout-variable>
@@ -417,6 +435,9 @@ endfunction()
# LINK_DIRS <inout-variable> # LINK_DIRS <inout-variable>
# DEFINITIONS <inout-variable>) # DEFINITIONS <inout-variable>)
# #
# Input:
# BOARD : board
#
# Input/Output: (appends to existing variable) # Input/Output: (appends to existing variable)
# C_FLAGS : c compile flags variable # C_FLAGS : c compile flags variable
# CXX_FLAGS : c++ compile flags variable # CXX_FLAGS : c++ compile flags variable
@@ -427,12 +448,12 @@ endfunction()
# #
# Example: # Example:
# px4_add_common_flags( # px4_add_common_flags(
# BOARD px4fmu-v2
# C_FLAGS CMAKE_C_FLAGS # C_FLAGS CMAKE_C_FLAGS
# CXX_FLAGS CMAKE_CXX_FLAGS # CXX_FLAGS CMAKE_CXX_FLAGS
# EXE_LINKER_FLAG CMAKE_EXE_LINKER_FLAGS # EXE_LINKER_FLAG CMAKE_EXE_LINKER_FLAGS
# INCLUDES <list>) # INCLUDES <list>)
# #
#----------------------------------------------------------------------------
function(px4_add_common_flags) function(px4_add_common_flags)
set(inout_vars set(inout_vars
@@ -440,8 +461,8 @@ function(px4_add_common_flags)
px4_parse_function_args( px4_parse_function_args(
NAME px4_add_common_flags NAME px4_add_common_flags
ONE_VALUE ${inout_vars} ONE_VALUE ${inout_vars} BOARD
REQUIRED ${inout_vars} REQUIRED ${inout_vars} BOARD
ARGN ${ARGN}) ARGN ${ARGN})
set(warnings set(warnings
@@ -569,8 +590,10 @@ function(px4_add_common_flags)
set(added_link_dirs) # none used currently set(added_link_dirs) # none used currently
string(TOUPPER ${BOARD} board_upper)
string(REPLACE "-" "_" board_config ${board_upper})
set(added_definitions set(added_definitions
-DCONFIG_ARCH_BOARD_${BOARD_CONFIG} -DCONFIG_ARCH_BOARD_${board_config}
) )
set(added_exe_link_flags set(added_exe_link_flags
@@ -582,13 +605,9 @@ function(px4_add_common_flags)
foreach(var ${inout_vars}) foreach(var ${inout_vars})
string(TOLOWER ${var} lower_var) string(TOLOWER ${var} lower_var)
set(${${var}} ${${${var}}} ${added_${lower_var}} PARENT_SCOPE) set(${${var}} ${${${var}}} ${added_${lower_var}} PARENT_SCOPE)
message(STATUS "set(${${var}} ${${${var}}} ${added_${lower_var}} PARENT_SCOPE)")
endforeach() endforeach()
endfunction() endfunction()
# vim: set noet fenc=utf-8 ff=unix nowrap: # vim: set noet fenc=utf-8 ff=unix nowrap:
+1 -1
View File
@@ -64,7 +64,7 @@ if (${OS} STREQUAL "nuttx")
px4_nuttx_add_firmware(OUT fw_main.px4 EXE main) px4_nuttx_add_firmware(OUT fw_main.px4 EXE main)
px4_add_upload(OUT upload OS ${OS} BOARD ${BOARD} BUNDLE fw_main.px4) px4_add_upload(OUT upload OS ${OS} BOARD ${BOARD} BUNDLE fw_main.px4)
px4_nuttx_generate_romfs(OUT romfs.img ROOT ROMFS/px4fmu_common) px4_generate_romfs(OUT romfs.img ROOT ROMFS/px4fmu_common)
endif() endif()
+3 -4
View File
@@ -33,10 +33,9 @@
set(depends set(depends
msg_gen msg_gen
) )
if(${OS} STREQUAL "nuttx")
list(APPEND depends if (prebuild_targets)
nuttx_export list(APPEND depends prebuild_targets)
)
endif() endif()
px4_add_module( px4_add_module(