Skip to content

Commit

Permalink
NuttX upgrade cmake wrapper (#7873)
Browse files Browse the repository at this point in the history
* NuttX cmake

* px4_macros:Pass the stringified predicate as second arg to static assert

   CC_ASSERT mapes to the c++ static_assert or provides the same
   funtionality for c via the other macros. The c++ static assert
   takes 2 argumants the prdicate and a message. This fixes the
   lacking second argument.

* Updated nuttx and apps submodule to upstream nuttx 7.21+==master

   This is the latest uptake of upstream nuttx and apps.

* ROMFS generate with xxd instead of objcopy

* delete nuttx-patches

* NuttX update submodules to latest px4_nuttx-master

* fix nuttx apps and board dependency

* docker_run update to latest container 2017-08-29

* cmake ROMFS portable sed usage

* NuttX update submodules to latest px4_nuttx-master
  • Loading branch information
dagar authored and David Sidrane committed Aug 29, 2017
1 parent ea7b831 commit 0fa5da3
Show file tree
Hide file tree
Showing 162 changed files with 3,218 additions and 4,290 deletions.
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 = git@github.com:PX4-NuttX/nuttx.git
[submodule "platforms/nuttx/NuttX/apps"]
path = platforms/nuttx/NuttX/apps
url = git@github.com:PX4-NuttX/apps.git
70 changes: 23 additions & 47 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,18 @@ 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}
)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PX4_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PX4_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PX4_BINARY_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 +142,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 +172,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 @@ -202,12 +199,10 @@ px4_add_git_submodule(TARGET git_jmavsim PATH "Tools/jMAVSim")
px4_add_git_submodule(TARGET git_matrix PATH "src/lib/matrix")
px4_add_git_submodule(TARGET git_mavlink PATH "mavlink/include/mavlink/v1.0")
px4_add_git_submodule(TARGET git_mavlink2 PATH "mavlink/include/mavlink/v2.0")
px4_add_git_submodule(TARGET git_nuttx PATH "NuttX")
px4_add_git_submodule(TARGET git_nuttx PATH "platforms/nuttx/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,18 +220,12 @@ 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()

#=============================================================================
# require px4 module interface
Expand Down Expand Up @@ -361,12 +350,11 @@ 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}")
link_directories(${link_dirs})
add_definitions(${definitions})

Expand All @@ -381,10 +369,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 +425,6 @@ endif()
#=============================================================================
# subdirectories
#
set(module_libraries)
foreach(module ${config_module_list})
string(REGEX MATCH "^[./]" external_module ${module})
if (external_module)
Expand All @@ -449,19 +434,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
2 changes: 1 addition & 1 deletion Debug/poor-mans-profiler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ do
shift
done

[[ -z "$elf" ]] && die "Please specify the ELF file location, e.g.: build_px4fmu-v4_default/src/firmware/nuttx/firmware_nuttx"
[[ -z "$elf" ]] && die "Please specify the ELF file location, e.g.: build/px4fmu-v4_default/src/firmware/nuttx/firmware_nuttx"

#
# Temporary files
Expand Down
43 changes: 21 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ endif
# make px4fmu-v2_default test (builds and tests)
#
# This tells cmake to build the nuttx px4fmu-v2 default config in the
# directory build_nuttx_px4fmu-v2_default and then call make
# directory build/nuttx_px4fmu-v2_default and then call make
# in that directory with the target upload.

# explicity set default build target
Expand Down Expand Up @@ -132,7 +132,7 @@ endif
# --------------------------------------------------------------------
# describe how to build a cmake config
define cmake-build
+@$(eval BUILD_DIR = $(SRC_DIR)/build_$@$(BUILD_DIR_SUFFIX))
+@$(eval BUILD_DIR = $(SRC_DIR)/build/$@$(BUILD_DIR_SUFFIX))
+@if [ $(PX4_CMAKE_GENERATOR) = "Ninja" ] && [ -e $(BUILD_DIR)/Makefile ]; then rm -rf $(BUILD_DIR); fi
+@if [ ! -e $(BUILD_DIR)/CMakeCache.txt ]; then mkdir -p $(BUILD_DIR) && cd $(BUILD_DIR) && cmake $(2) -G"$(PX4_CMAKE_GENERATOR)" -DCONFIG=$(1) $(CMAKE_ARGS) || (rm -rf $(BUILD_DIR)); fi
+@(cd $(BUILD_DIR) && $(PX4_MAKE) $(PX4_MAKE_ARGS) $(ARGS))
Expand Down 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 @@ -228,7 +228,7 @@ checks_bootloaders: \
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 @@ -276,25 +276,25 @@ s3put_firmware: Firmware.zip
s3put_qgc_firmware: s3put_px4fmu_firmware s3put_misc_qgc_extra_firmware

s3put_px4fmu_firmware: px4fmu_firmware
@find $(SRC_DIR)/build_* -name "*.px4" -exec $(SRC_DIR)/Tools/s3put.sh "{}" \;
@find $(SRC_DIR)/build -name "*.px4" -exec $(SRC_DIR)/Tools/s3put.sh "{}" \;

s3put_misc_qgc_extra_firmware: misc_qgc_extra_firmware
@find $(SRC_DIR)/build_* -name "*.px4" -exec $(SRC_DIR)/Tools/s3put.sh "{}" \;
@find $(SRC_DIR)/build -name "*.px4" -exec $(SRC_DIR)/Tools/s3put.sh "{}" \;

s3put_metadata: px4_metadata
@$(SRC_DIR)/Tools/s3put.sh airframes.md
@$(SRC_DIR)/Tools/s3put.sh airframes.xml
@$(SRC_DIR)/Tools/s3put.sh build_posix_sitl_default/parameters.xml
@$(SRC_DIR)/Tools/s3put.sh build/posix_sitl_default/parameters.xml
@$(SRC_DIR)/Tools/s3put.sh parameters.md

s3put_scan-build: scan-build
@cd $(SRC_DIR) && ./Tools/s3put.sh `find build_scan-build -mindepth 1 -maxdepth 1 -type d`/
@cd $(SRC_DIR) && ./Tools/s3put.sh `find build/scan-build -mindepth 1 -maxdepth 1 -type d`/

s3put_cppcheck: cppcheck
@cd $(SRC_DIR) && ./Tools/s3put.sh cppcheck/

s3put_coverage: tests_coverage
@cd $(SRC_DIR) && ./Tools/s3put.sh build_posix_sitl_default/coverage-html/
@cd $(SRC_DIR) && ./Tools/s3put.sh build/posix_sitl_default/coverage-html/

# Astyle
# --------------------------------------------------------------------
Expand Down Expand Up @@ -327,7 +327,7 @@ coveralls_upload:
--exclude=src/lib/ecl \
--exclude=src/lib/Matrix \
--exclude=src/modules/uavcan/libuavcan \
--root . --build-root build_posix_sitl_default/ --follow-symlinks
--root . --build-root build/posix_sitl_default/ --follow-symlinks

codecov_upload:
@/bin/bash -c "bash <(curl -s https://codecov.io/bash)"
Expand All @@ -337,41 +337,40 @@ codecov_upload:
.PHONY: posix_sitl_default-clang scan-build clang-tidy clang-tidy-fix clang-tidy-quiet cppcheck

posix_sitl_default-clang:
@mkdir -p $(SRC_DIR)/build_posix_sitl_default-clang
@cd $(SRC_DIR)/build_posix_sitl_default-clang && cmake .. -GNinja -DCONFIG=posix_sitl_default -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
@cd $(SRC_DIR)/build_posix_sitl_default-clang && ninja
@mkdir -p $(SRC_DIR)/build/posix_sitl_default-clang
@cd $(SRC_DIR)/build/posix_sitl_default-clang && cmake $(SRC_DIR) -GNinja -DCONFIG=posix_sitl_default -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
@cd $(SRC_DIR)/build/posix_sitl_default-clang && ninja

scan-build:
@export CCC_CC=clang
@export CCC_CXX=clang++
@mkdir -p $(SRC_DIR)/build_posix_sitl_default-scan-build
@cd $(SRC_DIR)/build_posix_sitl_default-scan-build && scan-build cmake .. -GNinja -DCONFIG=posix_sitl_default
@scan-build -o $(SRC_DIR)/build_scan-build cmake --build $(SRC_DIR)/build_posix_sitl_default-scan-build
@mkdir -p $(SRC_DIR)/build/posix_sitl_default-scan-build
@cd $(SRC_DIR)/build/posix_sitl_default-scan-build && scan-build cmake .. -GNinja -DCONFIG=posix_sitl_default
@scan-build -o $(SRC_DIR)/build/scan-build cmake --build $(SRC_DIR)/build/posix_sitl_default-scan-build

clang-tidy: posix_sitl_default-clang
@cd build_posix_sitl_default-clang && run-clang-tidy-4.0.py -header-filter=".*\.hpp" -j$(j) -p .
@cd build/posix_sitl_default-clang && run-clang-tidy-4.0.py -header-filter=".*\.hpp" -j$(j) -p .

# to automatically fix a single check at a time, eg modernize-redundant-void-arg
# % run-clang-tidy-4.0.py -fix -j4 -checks=-\*,modernize-redundant-void-arg -p .
clang-tidy-fix: posix_sitl_default-clang
@cd build_posix_sitl_default-clang && run-clang-tidy-4.0.py -header-filter=".*\.hpp" -j$(j) -fix -p .
@cd build/posix_sitl_default-clang && run-clang-tidy-4.0.py -header-filter=".*\.hpp" -j$(j) -fix -p .

# modified version of run-clang-tidy.py to return error codes and only output relevant results
clang-tidy-quiet: posix_sitl_default-clang
@cd build_posix_sitl_default-clang && $(SRC_DIR)/Tools/run-clang-tidy.py -header-filter=".*\.hpp" -j$(j) -p .
@cd build/posix_sitl_default-clang && $(SRC_DIR)/Tools/run-clang-tidy.py -header-filter=".*\.hpp" -j$(j) -p .

# TODO: Fix cppcheck errors then try --enable=warning,performance,portability,style,unusedFunction or --enable=all
cppcheck: posix_sitl_default
@cppcheck -i$(SRC_DIR)/src/examples --std=c++11 --std=c99 --std=posix --project=build_posix_sitl_default/compile_commands.json --xml-version=2 2> cppcheck-result.xml
@cppcheck -i$(SRC_DIR)/src/examples --std=c++11 --std=c99 --std=posix --project=build/posix_sitl_default/compile_commands.json --xml-version=2 2> cppcheck-result.xml
@cppcheck-htmlreport --source-encoding=ascii --file=cppcheck-result.xml --report-dir=cppcheck --source-dir=$(SRC_DIR)/src/

# Cleanup
# --------------------------------------------------------------------
.PHONY: clean submodulesclean distclean

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

submodulesclean:
@git submodule foreach --quiet --recursive git clean -ff -x -d
Expand Down
1 change: 0 additions & 1 deletion NuttX
Submodule NuttX deleted from ba1850
45 changes: 45 additions & 0 deletions ROMFS/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

message(STATUS "ROMFS: ${config_romfs_root}")

set(romfs_temp_dir ${PX4_BINARY_DIR}/ROMFS/${config_romfs_root})
set(romfs_src_dir ${PX4_SOURCE_DIR}/ROMFS/${config_romfs_root})

# directory setup
# copy all romfs files, process airframes, prune comments
file(GLOB_RECURSE init_airframes ${PX4_SOURCE_DIR}/ROMFS/${config_romfs_root}/*/[1-9]*)
add_custom_command(OUTPUT ${romfs_temp_dir}/init.d/rcS ${romfs_temp_dir}/init.d/rc.autostart
COMMAND cmake -E copy_directory ${romfs_src_dir} ${romfs_temp_dir}
COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/px_process_airframes.py
-a ${romfs_temp_dir}/init.d
-s ${romfs_temp_dir}/init.d/rc.autostart
--board ${BOARD}
COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/px_romfs_pruner.py
--folder ${romfs_temp_dir} --board ${BOARD}
DEPENDS
${romfs_src_files}
${init_airframes}
${PX4_SOURCE_DIR}/ROMFS/${config_romfs_root}/init.d/rcS
${PX4_SOURCE_DIR}/Tools/px_process_airframes.py
)

set(romfs_dependencies)
list(APPEND romfs_dependencies
${romfs_temp_dir}/init.d/rcS
${romfs_temp_dir}/init.d/rc.autostart
)

# create romfs.bin
add_custom_command(OUTPUT romfs.img
COMMAND ${GENROMFS} -f romfs.img -d ${romfs_temp_dir} -V "NSHInitVol" -v > romfs.txt 2>&1
DEPENDS ${romfs_dependencies}
)

# create romfs.o
add_custom_command(OUTPUT nsh_romfsimg.c
COMMAND xxd -i romfs.img nsh_romfsimg.c
COMMAND sed 's/unsigned/const unsigned/g' nsh_romfsimg.c > nsh_romfsimg.c.tmp && mv nsh_romfsimg.c.tmp nsh_romfsimg.c
DEPENDS romfs.img
)

add_library(romfs STATIC nsh_romfsimg.c)
set_target_properties(romfs PROPERTIES LINKER_LANGUAGE C)
Loading

0 comments on commit 0fa5da3

Please sign in to comment.