diff --git a/CMakeLists.txt b/CMakeLists.txt index aace54bd66..fcfb877d0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,6 +56,9 @@ # 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 # 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) - -include(px4_utils) -include(px4_nuttx_utils) +include(px4_${OS}_utils) +set(px4_required_functions + 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 @@ -124,8 +135,8 @@ set_property(CACHE BOARD PROPERTY STRINGS px4fmu-v2 sitl) set(LABEL "simple" CACHE STRING "module set label") set_property(CACHE LABEL PROPERTY STRINGS simple default) -set(NUTTX_BUILD_THREADS "4" CACHE STRING - "number of threads to use when building NuttX") +set(THREADS "4" CACHE STRING + "number of threads to use for external build processes") set(required_toolchain_variables CMAKE_C_COMPILER_ID @@ -159,40 +170,25 @@ add_custom_target(submodule_clean #============================================================================= # external libraries # -if(${OS} STREQUAL "nuttx") - px4_nuttx_add_export(OUT nuttx_export - CONFIG ${BOARD} - THREADS ${NUTTX_BUILD_THREADS} - DEPENDS git_nuttx) -endif() +px4_os_prebuild_targets(OUT prebuild_targets + BOARD ${BOARD} + THREADS ${THREADS}) #============================================================================= # build flags # - -px4_add_common_flags( +px4_os_add_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) - -if(${OS} STREQUAL "nuttx") - px4_add_nuttx_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) - -endif() - 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_CXX_FLAGS LIST "${cxx_flags}" GLUE " ") + include_directories(${include_dirs}) link_directories(${link_dirs}) add_definitions(${definitions}) diff --git a/cmake/px4_nuttx_utils.cmake b/cmake/px4_nuttx_utils.cmake index 25f3cf0692..df10da85df 100644 --- a/cmake/px4_nuttx_utils.cmake +++ b/cmake/px4_nuttx_utils.cmake @@ -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) -#---------------------------------------------------------------------------- +#============================================================================= +# # px4_nuttx_add_firmware # # This function adds a nuttx firmware target. @@ -53,7 +72,6 @@ include(px4_utils) # Example: # px4_nuttx_add_firmware(TARGET fw_test EXE test) # -#---------------------------------------------------------------------------- function(px4_nuttx_add_firmware) px4_parse_function_args( NAME px4_nuttx_add_firmware @@ -74,7 +92,8 @@ function(px4_nuttx_add_firmware) ) endfunction() -#---------------------------------------------------------------------------- +#============================================================================= +# # px4_nuttx_generate_builtin_commands # # This function generates the builtin_commands.c src for nuttx @@ -91,9 +110,9 @@ endfunction() # OUT : generated builtin_commands.c src # # Example: -# px4_nuttx_generate_builtin_commands(OUT MODULE_LIST px4_simple_app) +# px4_nuttx_generate_builtin_commands( +# OUT MODULE_LIST px4_simple_app) # -#---------------------------------------------------------------------------- function(px4_nuttx_generate_builtin_commands) px4_parse_function_args( NAME px4_nuttx_generate_builtin_commands @@ -127,11 +146,12 @@ function(px4_nuttx_generate_builtin_commands) ${OUT}) endfunction() -#---------------------------------------------------------------------------- +#============================================================================= +# # px4_nuttx_add_export # # This function generates a nuttx export. - +# # Usage: # px4_nuttx_add_export( # OUT @@ -148,7 +168,6 @@ endfunction() # Example: # px4_nuttx_add_export(OUT nuttx_export CONFIG px4fmu-v2) # -#---------------------------------------------------------------------------- function(px4_nuttx_add_export) px4_parse_function_args( @@ -215,7 +234,8 @@ function(px4_nuttx_add_export) endfunction() -#---------------------------------------------------------------------------- +#============================================================================= +# # px4_nuttx_generate_romfs # # The functions generates the ROMFS filesystem for nuttx. @@ -232,7 +252,6 @@ endfunction() # Example: # px4_nuttx_generate_romfs(OUT my_romfs ROOT "ROMFS/my_board") # -#---------------------------------------------------------------------------- function(px4_nuttx_generate_romfs) px4_parse_function_args( @@ -257,13 +276,14 @@ function(px4_nuttx_generate_romfs) endfunction() -#---------------------------------------------------------------------------- -# px4_add_nuttx_flags +#============================================================================= +# +# px4_add_flags # # Set ths nuttx build flags. # # Usage: -# px4_add_nuttx_flags( +# px4_add_flags( # C_FLAGS # CXX_FLAGS # EXE_LINKER_FLAGS @@ -273,7 +293,7 @@ endfunction() # # Input: # BOARD : flags depend on board/nuttx config - +# # Input/Output: (appends to existing variable) # C_FLAGS : c compile flags variable # CXX_FLAGS : c++ compile flags variable @@ -283,24 +303,32 @@ endfunction() # DEFINITIONS : definitions # # Example: -# px4_add_nuttx_flags( +# px4_add_flags( # C_FLAGS CMAKE_C_FLAGS # CXX_FLAGS CMAKE_CXX_FLAGS # EXE_LINKER_FLAG CMAKE_EXE_LINKER_FLAGS # INCLUDES ) # -#---------------------------------------------------------------------------- -function(px4_add_nuttx_flags) +function(px4_add_flags) set(inout_vars C_FLAGS CXX_FLAGS EXE_LINKER_FLAGS INCLUDE_DIRS LINK_DIRS DEFINITIONS) px4_parse_function_args( - NAME px4_add_nuttx_flags + NAME px4_add_flags ONE_VALUE ${inout_vars} BOARD REQUIRED ${inout_vars} BOARD 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(added_include_dirs ${nuttx_export_dir}/include @@ -341,8 +369,44 @@ function(px4_add_nuttx_flags) foreach(var ${inout_vars}) string(TOLOWER ${var} lower_var) set(${${var}} ${${${var}}} ${added_${lower_var}} PARENT_SCOPE) + message(STATUS "nuttx: set(${${var}} ${${${var}}} ${added_${lower_var}} PARENT_SCOPE)") endforeach() endfunction() +#============================================================================= +# +# px4_prebuild_targets +# +# This function generates os dependent targets + +# Usage: +# px4_os_prebuild_targets( +# OUT +# BOARD +# ) +# +# 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: diff --git a/cmake/px4_utils.cmake b/cmake/px4_utils.cmake index 3d3b5563e8..5333c454a8 100644 --- a/cmake/px4_utils.cmake +++ b/cmake/px4_utils.cmake @@ -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) -#---------------------------------------------------------------------------- +#============================================================================= +# # px4_parse_function_args # # This function simpliies usage of the cmake_parse_arguments module. @@ -78,7 +95,6 @@ include(CMakeParseArguments) # name: hello # list: a b c # -#---------------------------------------------------------------------------- function(px4_parse_function_args) 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}") @@ -95,13 +111,14 @@ function(px4_parse_function_args) endforeach() endfunction() -#---------------------------------------------------------------------------- -# add_git_submodule +#============================================================================= +# +# px4_add_git_submodule # # This function add a git submodule target. # # Usage: -# add_git_submodule(TARGET PATH ) +# px4_add_git_submodule(TARGET PATH ) # # Input: # PATH : git submodule path @@ -110,9 +127,8 @@ endfunction() # TARGET : git target # # Example: -# add_git_submodule(TARGET git_nuttx PATH "NuttX") +# px4_add_git_submodule(TARGET git_nuttx PATH "NuttX") # -#---------------------------------------------------------------------------- function(px4_add_git_submodule) px4_parse_function_args( NAME px4_add_git_submodule @@ -131,7 +147,8 @@ function(px4_add_git_submodule) ) endfunction() -#---------------------------------------------------------------------------- +#============================================================================= +# # px4_prepend_string # # This function prepends a string to a list @@ -152,7 +169,6 @@ endfunction() # path/to/src/file1.cpp # path/to/src/file2.cpp # -#---------------------------------------------------------------------------- function(px4_prepend_string) px4_parse_function_args( NAME px4_prepend_string @@ -167,7 +183,8 @@ function(px4_prepend_string) set(${OUT} ${${OUT}} PARENT_SCOPE) endfunction() -#---------------------------------------------------------------------------- +#============================================================================= +# # px4_join # # This function joins a list with a given separator. If list is not @@ -188,7 +205,6 @@ endfunction() # test_join would then be: # "a;b;c" # -#---------------------------------------------------------------------------- function(px4_join) px4_parse_function_args( NAME px4_join @@ -200,7 +216,8 @@ function(px4_join) set(${OUT} ${_TMP_STR} PARENT_SCOPE) endfunction() -#---------------------------------------------------------------------------- +#============================================================================= +# # px4_add_module # # This function builds a static library from a module description. @@ -236,7 +253,6 @@ endfunction() # git_nuttx # ) # -#---------------------------------------------------------------------------- function(px4_add_module) px4_parse_function_args( NAME px4_add_module @@ -264,11 +280,12 @@ function(px4_add_module) set_target_properties(${MODULE} PROPERTIES LINK_INTERFACE_MULTIPLICITY 4) endfunction() -#---------------------------------------------------------------------------- +#============================================================================= +# # px4_generate_messages # # This function generates source code from ROS msg definitions. - +# # Usage: # px4_generate_messages(TARGET MSGS ) # @@ -286,7 +303,6 @@ endfunction() # [ DEPENDS ] # ) # -#---------------------------------------------------------------------------- function(px4_generate_messages) px4_parse_function_args( NAME px4_generate_messages @@ -349,11 +365,12 @@ function(px4_generate_messages) DEPENDS ${msg_multi_files_out} ${msg_files_out}) endfunction() -#---------------------------------------------------------------------------- +#============================================================================= +# # px4_add_upload # # This function generates source code from ROS msg definitions. - +# # Usage: # px4_add_upload(OUT BUNDLE ) # @@ -370,7 +387,6 @@ endfunction() # BUNDLE main.px4 # ) # -#---------------------------------------------------------------------------- function(px4_add_upload) px4_parse_function_args( NAME px4_generate_messages @@ -403,13 +419,15 @@ function(px4_add_upload) ) endfunction() -#---------------------------------------------------------------------------- +#============================================================================= +# # px4_add_common_flags # # Set ths default build flags. # # Usage: # px4_add_common_flags( +# BOARD # C_FLAGS # CXX_FLAGS # EXE_LINKER_FLAGS @@ -417,6 +435,9 @@ endfunction() # LINK_DIRS # DEFINITIONS ) # +# Input: +# BOARD : board +# # Input/Output: (appends to existing variable) # C_FLAGS : c compile flags variable # CXX_FLAGS : c++ compile flags variable @@ -427,12 +448,12 @@ endfunction() # # Example: # px4_add_common_flags( +# BOARD px4fmu-v2 # C_FLAGS CMAKE_C_FLAGS # CXX_FLAGS CMAKE_CXX_FLAGS # EXE_LINKER_FLAG CMAKE_EXE_LINKER_FLAGS # INCLUDES ) # -#---------------------------------------------------------------------------- function(px4_add_common_flags) set(inout_vars @@ -440,8 +461,8 @@ function(px4_add_common_flags) px4_parse_function_args( NAME px4_add_common_flags - ONE_VALUE ${inout_vars} - REQUIRED ${inout_vars} + ONE_VALUE ${inout_vars} BOARD + REQUIRED ${inout_vars} BOARD ARGN ${ARGN}) set(warnings @@ -569,8 +590,10 @@ function(px4_add_common_flags) set(added_link_dirs) # none used currently + string(TOUPPER ${BOARD} board_upper) + string(REPLACE "-" "_" board_config ${board_upper}) set(added_definitions - -DCONFIG_ARCH_BOARD_${BOARD_CONFIG} + -DCONFIG_ARCH_BOARD_${board_config} ) set(added_exe_link_flags @@ -582,13 +605,9 @@ function(px4_add_common_flags) foreach(var ${inout_vars}) string(TOLOWER ${var} lower_var) set(${${var}} ${${${var}}} ${added_${lower_var}} PARENT_SCOPE) + message(STATUS "set(${${var}} ${${${var}}} ${added_${lower_var}} PARENT_SCOPE)") endforeach() endfunction() - - - - - # vim: set noet fenc=utf-8 ff=unix nowrap: diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d2a80d939f..6584e136cb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -64,7 +64,7 @@ if (${OS} STREQUAL "nuttx") px4_nuttx_add_firmware(OUT fw_main.px4 EXE main) 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() diff --git a/src/platforms/common/CMakeLists.txt b/src/platforms/common/CMakeLists.txt index 0bc74e228a..7d486c9709 100644 --- a/src/platforms/common/CMakeLists.txt +++ b/src/platforms/common/CMakeLists.txt @@ -33,10 +33,9 @@ set(depends msg_gen ) -if(${OS} STREQUAL "nuttx") - list(APPEND depends - nuttx_export - ) + +if (prebuild_targets) + list(APPEND depends prebuild_targets) endif() px4_add_module(