Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] NuttX cmake wrapper #7397

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
[submodule "mavlink/include/mavlink/v2.0"]
path = mavlink/include/mavlink/v2.0
url = https://github.com/mavlink/c_library_v2.git
[submodule "NuttX"]
path = NuttX
url = https://github.com/PX4/PX4NuttX.git
[submodule "src/modules/uavcan/libuavcan"]
path = src/modules/uavcan/libuavcan
url = https://github.com/UAVCAN/libuavcan.git
Expand Down Expand Up @@ -40,3 +37,9 @@
[submodule "src/lib/micro-CDR"]
path = src/lib/micro-CDR
url = https://github.com/eProsima/micro-CDR.git
[submodule "platforms/nuttx/NuttX/nuttx"]
path = platforms/nuttx/NuttX/nuttx
url = https://github.com/PX4-NuttX/nuttx.git
[submodule "platforms/nuttx/NuttX/apps"]
path = platforms/nuttx/NuttX/apps
url = https://github.com/PX4-NuttX/apps.git
62 changes: 18 additions & 44 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,8 @@
#
#=============================================================================

if (${CMAKE_VERSION} VERSION_LESS 3.1.0)
message("Not a valid CMake version")
message("On Ubuntu >= 16.04, install or upgrade via:")
message(" sudo apt-get install cmake")
message("")
message("Official website: https://cmake.org/download/")
message(FATAL_ERROR "Update CMake and try again" )
endif()
# check submodules before we do anything
execute_process(COMMAND Tools/check_submodules.sh WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

# Warning: Changing this modifies CMake's internal workings
# and leads to wrong toolchain detection
Expand All @@ -115,15 +109,14 @@ cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
set(PX4_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(PX4_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")

execute_process(
COMMAND Tools/check_submodules.sh
WORKING_DIRECTORY ${PX4_SOURCE_DIR}
)
define_property(GLOBAL PROPERTY PX4_LIBRARIES
BRIEF_DOCS "PX4 libs"
FULL_DOCS "List of all PX4 module libraries"
)

#=============================================================================
# configuration
#
# must come before project to set toolchain

set(CONFIG "posix_sitl_default" CACHE STRING "desired configuration")

Expand All @@ -145,7 +138,6 @@ if (NOT EXTERNAL_MODULES_LOCATION STREQUAL "")
endif()

list(APPEND CMAKE_MODULE_PATH "${PX4_SOURCE_DIR}/cmake")
message(STATUS "CMAKE_MODULE_PATH: ${CMAKE_MODULE_PATH}")
set(config_module "configs/${CONFIG}")
include(${config_module})

Expand Down Expand Up @@ -176,16 +168,17 @@ message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
#
include(common/px4_git)

# version info from git
execute_process(
COMMAND git describe --always --tags
OUTPUT_VARIABLE git_tag
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND Tools/tag_to_version.py --root ${PX4_SOURCE_DIR}
OUTPUT_VARIABLE version
WORKING_DIRECTORY ${PX4_SOURCE_DIR}
)

execute_process(
COMMAND Tools/tag_to_version.py --root ${PX4_SOURCE_DIR}
OUTPUT_VARIABLE git_version
COMMAND git describe --always --tags
OUTPUT_VARIABLE git_tag
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${PX4_SOURCE_DIR}
)

Expand All @@ -206,8 +199,6 @@ px4_add_git_submodule(TARGET git_nuttx PATH "NuttX")
px4_add_git_submodule(TARGET git_uavcan PATH "src/modules/uavcan/libuavcan")
px4_add_git_submodule(TARGET git_micro_cdr PATH "src/lib/micro-CDR")

px4_create_git_hash_header()

#=============================================================================

message(STATUS "PX4 VERSION: ${git_tag}")
Expand All @@ -225,16 +216,11 @@ add_definitions(-DBUILD_URI=${BUILD_URI})
# Define GNU standard installation directories
include(GNUInstallDirs)

# Add support for external project building
include(ExternalProject)

# Setup install paths
if (NOT CMAKE_INSTALL_PREFIX)
if (${OS} STREQUAL "posix")
if (${OS} STREQUAL "posix")
if (NOT CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Install path prefix" FORCE)
endif()
endif()
if (CMAKE_INSTALL_PREFIX)
message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
endif()

Expand Down Expand Up @@ -361,9 +347,9 @@ px4_os_add_flags(
LINK_DIRS link_dirs
DEFINITIONS definitions)

px4_join(OUT CMAKE_EXE_LINKER_FLAGS LIST "${exe_linker_flags}" GLUE " ")
px4_join(OUT CMAKE_C_FLAGS LIST "${c_flags};${optimization_flags}" GLUE " ")
px4_join(OUT CMAKE_CXX_FLAGS LIST "${cxx_flags};${optimization_flags}" GLUE " ")
px4_join(OUT CMAKE_EXE_LINKER_FLAGS LIST "${CMAKE_EXE_LINKER_FLAGS};${exe_linker_flags}" GLUE " ")
px4_join(OUT CMAKE_C_FLAGS LIST "${CMAKE_C_FLAGS};${c_flags};${optimization_flags}" GLUE " ")
px4_join(OUT CMAKE_CXX_FLAGS LIST "${CMAKE_CXX_FLAGS};${cxx_flags};${optimization_flags}" GLUE " ")

include_directories(${include_dirs})
#message("INCLUDE_DIRS=${include_dirs}")
Expand All @@ -381,10 +367,8 @@ px4_generate_messages(TARGET msg_gen
MSG_FILES ${msg_files}
OS ${OS}
INCLUDES ${msg_include_paths}
DEPENDS git_genmsg git_gencpp git_micro_cdr prebuild_targets
DEPENDS prebuild_targets
)
include_directories("${PX4_SOURCE_DIR}/src/lib/micro-CDR/include"
"${PX4_BINARY_DIR}/src/lib/micro-CDR/include/microcdr")

px4_generate_airframes_xml(BOARD ${BOARD})

Expand Down Expand Up @@ -439,7 +423,6 @@ endif()
#=============================================================================
# subdirectories
#
set(module_libraries)
foreach(module ${config_module_list})
string(REGEX MATCH "^[./]" external_module ${module})
if (external_module)
Expand All @@ -449,19 +432,10 @@ foreach(module ${config_module_list})
else()
add_subdirectory(src/${module})
endif()
px4_mangle_name(${module} mangled_name)
list(APPEND module_libraries ${mangled_name})
endforeach()

# Keep track of external shared libs required for modules
set(module_external_libraries "${module_external_libraries}" CACHE INTERNAL "module_external_libraries")

add_subdirectory(src/firmware/${OS})

if (config_io_board)
add_subdirectory(src/modules/px4iofirmware)
endif()

#=============================================================================
# generate custom target to print for all executable and module cmake targets
#
Expand Down
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ qgc_firmware: px4fmu_firmware misc_qgc_extra_firmware sizes

# px4fmu NuttX firmware
px4fmu_firmware: \
check_px4fmu-v1_default \
check_px4io-v2_default \
check_px4fmu-v2_default \
check_px4fmu-v3_default \
check_px4fmu-v4_default \
Expand Down Expand Up @@ -219,14 +219,14 @@ alt_firmware: \
checks_bootloaders: \
check_esc35-v1_bootloader \
check_px4cannode-v1_bootloader \
check_px4esc-v1_bootloader \
check_px4flow-v2_bootloader \
check_s2740vc-v1_bootloader \
# not fitting in flash check_zubaxgnss-v1_bootloader \
check_px4esc-v1_bootloader \
check_zubaxgnss-v1_bootloader \
sizes

sizes:
@-find build_* -name firmware_nuttx -type f | xargs size 2> /dev/null || :
@-find build_* -name *.elf -type f | xargs size 2> /dev/null || :

# All default targets that don't require a special build environment
check: check_posix_sitl_default px4fmu_firmware misc_qgc_extra_firmware alt_firmware checks_bootloaders tests check_format
Expand Down Expand Up @@ -369,7 +369,6 @@ cppcheck: posix_sitl_default

clean:
@rm -rf $(SRC_DIR)/build_*/
-@$(MAKE) --no-print-directory -C NuttX/nuttx clean

submodulesclean:
@git submodule foreach --quiet --recursive git clean -ff -x -d
Expand Down
1 change: 0 additions & 1 deletion NuttX
Submodule NuttX deleted from 44ad7e
46 changes: 4 additions & 42 deletions cmake/common/px4_base.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,6 @@ function(px4_add_module)
REQUIRED MODULE
ARGN ${ARGN})

if (EXTERNAL)
px4_mangle_name("${EXTERNAL_MODULES_LOCATION}/src/${MODULE}" MODULE)
endif()

px4_add_library(${MODULE} STATIC EXCLUDE_FROM_ALL ${SRCS})

# set defaults if not set
Expand All @@ -219,16 +215,14 @@ function(px4_add_module)
if(NOT ${property})
set(${property} ${${property}_DEFAULT})
endif()
set_target_properties(${MODULE} PROPERTIES ${property}
${${property}})
set_target_properties(${MODULE} PROPERTIES ${property} ${${property}})
endforeach()

# default stack max to stack main
if(NOT STACK_MAX)
set(STACK_MAX ${STACK_MAIN})
endif()
set_target_properties(${MODULE} PROPERTIES STACK_MAX
${STACK_MAX})
set_target_properties(${MODULE} PROPERTIES STACK_MAX ${STACK_MAX})

if(${OS} STREQUAL "qurt" )
set_property(TARGET ${MODULE} PROPERTY POSITION_INDEPENDENT_CODE TRUE)
Expand Down Expand Up @@ -270,7 +264,6 @@ function(px4_add_module)
set_target_properties(${MODULE} PROPERTIES ${prop} ${${prop}})
endif()
endforeach()

endfunction()

#=============================================================================
Expand Down Expand Up @@ -481,14 +474,6 @@ function(px4_add_common_flags)
-D__STDC_FORMAT_MACROS
)

if (NOT (APPLE AND (${CMAKE_C_COMPILER_ID} MATCHES ".*Clang.*")))
set(added_exe_linker_flags
-Wl,--warn-common
-Wl,--gc-sections
#,--print-gc-sections
)
endif()

# output
foreach(var ${inout_vars})
string(TOLOWER ${var} lower_var)
Expand All @@ -498,31 +483,6 @@ function(px4_add_common_flags)

endfunction()

#=============================================================================
#
# px4_mangle_name
#
# Convert a path name to a module name
#
# Usage:
# px4_mangle_name(dirname newname)
#
# Input:
# dirname : path to module dir
#
# Output:
# newname : module name
#
# Example:
# px4_mangle_name(${dirpath} mangled_name)
# message(STATUS "module name is ${mangled_name}")
#
function(px4_mangle_name dirname newname)
set(tmp)
string(REPLACE "/" "__" tmp ${dirname})
set(${newname} ${tmp} PARENT_SCOPE)
endfunction()

#=============================================================================
#
# px4_strip_optimization
Expand Down Expand Up @@ -590,6 +550,8 @@ function(px4_add_library target)
px4_add_optimization_flags_for_target(${target})
# Pass variable to the parent px4_add_module.
set(_no_optimization_for_target ${_no_optimization_for_target} PARENT_SCOPE)

set_property(GLOBAL APPEND PROPERTY PX4_LIBRARIES ${target})
endfunction()

#=============================================================================
Expand Down
54 changes: 0 additions & 54 deletions cmake/common/px4_git.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -82,57 +82,3 @@ function(px4_add_git_submodule)
DEPENDS ${PX4_BINARY_DIR}/git_init_${NAME}.stamp
)
endfunction()

#=============================================================================
#
# px4_create_git_hash_header
#
# Create a header file containing the git hash of the current tree
#
# Usage:
# px4_create_git_hash_header()
#
# Example:
# px4_create_git_hash_header()
#
function(px4_create_git_hash_header)
px4_parse_function_args(
NAME px4_create_git_hash_header
ARGN ${ARGN})

set(px4_git_ver_header ${PX4_BINARY_DIR}/build_git_version.h)

# check if px4 source is a git repo
if(EXISTS ${PX4_SOURCE_DIR}/.git)
if (IS_DIRECTORY ${PX4_SOURCE_DIR}/.git)
# standard git repo
set(git_dir_path ${PX4_SOURCE_DIR}/.git)
else()
# git submodule
file(READ ${PX4_SOURCE_DIR}/.git git_dir_path)
string(STRIP ${git_dir_path} git_dir_path)
string(REPLACE "gitdir: " "" git_dir_path ${git_dir_path})
get_filename_component(git_dir_path ${git_dir_path} ABSOLUTE)
endif()
else()
message(FATAL_ERROR "is not a git repository")
endif()
if(NOT IS_DIRECTORY "${git_dir_path}")
message(FATAL_ERROR "${git_dir_path} is not a directory")
endif()

set(deps
${PX4_SOURCE_DIR}/Tools/px_update_git_header.py
${git_dir_path}/index
${git_dir_path}/HEAD)

add_custom_command(
OUTPUT ${px4_git_ver_header}
COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/px_update_git_header.py ${px4_git_ver_header} > ${PX4_BINARY_DIR}/git_header.log
DEPENDS ${deps}
WORKING_DIRECTORY ${PX4_SOURCE_DIR}
COMMENT "Generating git hash header"
)
set_source_files_properties(${px4_git_ver_header} PROPERTIES GENERATED TRUE)
add_custom_target(ver_gen ALL DEPENDS ${px4_git_ver_header})
endfunction()
8 changes: 7 additions & 1 deletion cmake/common/px4_metadata.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function(px4_generate_messages)
REQUIRED MSG_FILES OS TARGET
ARGN ${ARGN})

if("${config_nuttx_config}" STREQUAL "bootloader")
if("${nuttx_config_type}" STREQUAL "bootloader")
# do nothing for bootloaders
else()

Expand Down Expand Up @@ -162,6 +162,12 @@ function(px4_generate_messages)
${msg_multi_files_out}
${msg_files_out}
)

target_include_directories(${TARGET}
PRIVATE ${PX4_SOURCE_DIR}/src/lib/micro-CDR/include
PRIVATE ${PX4_BINARY_DIR}/src/lib/micro-CDR/include/microcdr
)
target_link_libraries(${TARGET} PRIVATE lib__micro-CDR)
endif()
endfunction()

Expand Down
Loading