cmake organize code coverage handling and base

This commit is contained in:
Daniel Agar 2017-06-01 08:47:33 -04:00
parent 17c1114b3e
commit 24b26e53b9
20 changed files with 1027 additions and 940 deletions

13
.gitignore vendored
View File

@ -31,15 +31,6 @@ cscope.in.out
cscope.po.out
Firmware.sublime-workspace
user.sublime*
Images/*.bin
Images/*.px4
mavlink/include/mavlink/v0.9/
/nuttx-configs/px4io-v2/src/.depend
/nuttx-configs/px4io-v2/src/Make.dep
/nuttx-configs/px4io-v2/src/libboard.a
/nuttx-configs/px4io-v1/src/.depend
/nuttx-configs/px4io-v1/src/Make.dep
/nuttx-configs/px4io-v1/src/libboard.a
/Documentation/doxy.log
/Documentation/html/
/Documentation/doxygen*objdb*tmp
@ -82,10 +73,6 @@ vectorcontrol/
.idea
cmake-build-*/
# gcov code coverage
coverage-html/
coverage.info
posix-configs/SITL/init/test/*_generated
parameters.md

View File

@ -39,7 +39,7 @@ matrix:
sudo: required
services:
- docker
env: BUILD_TARGET=cppcheck PX4_DOCKER_REPO=px4io/px4-dev-base:ubuntu17.04
env: BUILD_TARGET=cppcheck
- os: linux
sudo: required
services:
@ -104,7 +104,11 @@ after_success:
fi
# coveralls code coverage report
- if [[ "${BUILD_TARGET}" = "tests_coverage" && "${TRAVIS_PULL_REQUEST}" = "false" ]]; then
./Tools/docker_run.sh 'cpp-coveralls -l coverage.info';
./Tools/docker_run.sh 'make coveralls_upload';
fi
# codecov code coverage report
- if [[ "${BUILD_TARGET}" = "tests_coverage" && "${TRAVIS_PULL_REQUEST}" = "false" ]]; then
./Tools/docker_run.sh 'make codecov_upload';
fi
addons:

View File

@ -55,24 +55,6 @@
#
# * For else, endif, endfunction, etc, never put the name of the statement
#
# Instead of the very confusing:
# if (${var} STREQUAL "1") <-- condition now becomes if name
# # do somthing
# elseif (${var} STREQUAL "2") <-- another condition
# # do somthing
# else (${var} STREQUAL "1") <-- tag is referring to name of if
# # do somthing
# endif (${var} STREQUAL "1") <-- tag is referring to name of if
#
# Do this:
# if (${var} STREQUAL "1") <-- condition now becomes if name
# # do somthing
# elseif (${var} STREQUAL "2") <-- another condition
# # do somthing
# else () <-- leave blank
# # do somthing
# endif () <-- leave blank
#
# Functions/Macros
# ---------------------------------------------------------------------------
#
@ -101,7 +83,7 @@
#
# * Setting a global variable in a CMakeLists.txt file is ok, because
# each CMakeLists.txt file has scope in the current directory and all
# subdirecties, so it is not truly global.
# subdirectories, so it is not truly global.
#
# * All toolchain files should be included in the cmake
# directory and named Toolchain-"name".cmake.
@ -117,7 +99,7 @@
#
#=============================================================================
if("${CMAKE_VERSION}" VERSION_LESS 3.1.0)
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")
@ -139,14 +121,18 @@ execute_process(
)
#=============================================================================
# parameters
# configuration
#
# must come before project to set toolchain
set(CMAKE_BUILD_TYPE "" CACHE STRING "build type")
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY
STRINGS ";Debug;Release;RelWithDebInfo;MinSizeRel")
set(CONFIG "posix_sitl_default" CACHE STRING "desired configuration")
string(REPLACE "_" ";" config_args ${CONFIG})
list(GET config_args 0 OS)
list(GET config_args 1 BOARD)
list(GET config_args 2 LABEL)
set(target_name "${OS}-${BOARD}-${LABEL}")
file(GLOB_RECURSE configs RELATIVE cmake/configs "cmake/configs/*.cmake")
set_property(CACHE CONFIG PROPERTY STRINGS ${configs})
@ -154,33 +140,76 @@ set(THREADS "4" CACHE STRING "number of threads to use for external build proces
set(DEBUG_PORT "/dev/ttyACM0" CACHE STRING "debugging port")
set(EXTERNAL_MODULES_LOCATION "" CACHE STRING "External modules source location")
if(NOT EXTERNAL_MODULES_LOCATION STREQUAL "")
if (NOT EXTERNAL_MODULES_LOCATION STREQUAL "")
get_filename_component(EXTERNAL_MODULES_LOCATION "${EXTERNAL_MODULES_LOCATION}" ABSOLUTE)
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})
include(common/coverage)
include(common/sanitizers)
# CMake build type
# Debug Release RelWithDebInfo MinSizeRel Coverage
if (NOT CMAKE_BUILD_TYPE)
if (${OS} STREQUAL "nuttx")
set(PX4_BUILD_TYPE "MinSizeRel")
elseif (${OS} STREQUAL "qurt")
set(PX4_BUILD_TYPE "MinSizeRel")
elseif (${OS} STREQUAL "bebop")
set(PX4_BUILD_TYPE "MinSizeRel")
else()
set(PX4_BUILD_TYPE "RelWithDebInfo")
endif()
set(CMAKE_BUILD_TYPE ${PX4_BUILD_TYPE} CACHE STRING "Build type" FORCE)
endif()
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug;Release;RelWithDebInfo;MinSizeRel;Coverage")
message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
#=============================================================================
# configuration
# git
#
# must come before project to set toolchain
include(common/px4_git)
string(REPLACE "_" ";" config_args ${CONFIG})
list(GET config_args 0 OS)
list(GET config_args 1 BOARD)
list(GET config_args 2 LABEL)
set(target_name "${OS}-${BOARD}-${LABEL}")
# version info from git
execute_process(
COMMAND Tools/tag_to_version.py --root ${PX4_SOURCE_DIR}
OUTPUT_VARIABLE version
WORKING_DIRECTORY ${PX4_SOURCE_DIR}
)
execute_process(
COMMAND git describe --always --tags
OUTPUT_VARIABLE git_tag
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${PX4_SOURCE_DIR}
)
execute_process(
COMMAND Tools/tag_to_version.py --root ${PX4_SOURCE_DIR}
OUTPUT_VARIABLE git_version
WORKING_DIRECTORY ${PX4_SOURCE_DIR}
)
px4_add_git_submodule(TARGET git_cmake_hexagon PATH "cmake/cmake_hexagon")
px4_add_git_submodule(TARGET git_driverframework PATH "src/lib/DriverFramework")
px4_add_git_submodule(TARGET git_ecl PATH "src/lib/ecl")
px4_add_git_submodule(TARGET git_gazebo PATH "Tools/sitl_gazebo")
px4_add_git_submodule(TARGET git_gencpp PATH "Tools/gencpp")
px4_add_git_submodule(TARGET git_genmsg PATH "Tools/genmsg")
px4_add_git_submodule(TARGET git_gps_devices PATH "src/drivers/gps/devices")
px4_add_git_submodule(TARGET git_gtest PATH "unittests/gtest")
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_uavcan PATH "src/modules/uavcan/libuavcan")
px4_create_git_hash_header()
#=============================================================================
message(STATUS "PX4 VERSION: ${git_tag}")
message(STATUS "CONFIG: ${target_name}")
@ -200,7 +229,7 @@ include(GNUInstallDirs)
include(ExternalProject)
# Setup install paths
if(NOT CMAKE_INSTALL_PREFIX)
if (NOT CMAKE_INSTALL_PREFIX)
if (${OS} STREQUAL "posix")
set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Install path prefix" FORCE)
endif()
@ -209,38 +238,25 @@ if (CMAKE_INSTALL_PREFIX)
message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
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})
# cmake modules
include(ExternalProject)
#=============================================================================
# require px4 module interface
set(px4_required_interface
px4_os_prebuild_targets
px4_os_add_flags
)
foreach(cmd ${px4_required_interface})
if(NOT COMMAND ${cmd})
if (NOT COMMAND ${cmd})
message(FATAL_ERROR "${config_module} must implement ${cmd}")
endif()
endforeach()
set(px4_required_config
config_module_list
)
set(px4_required_config config_module_list)
foreach(conf ${px4_required_config})
if(NOT DEFINED ${conf})
if (NOT DEFINED ${conf})
message(FATAL_ERROR "cmake/${config_module} must define ${conf}")
endif()
endforeach()
# List the DriverFramework drivers
if(DEFINED config_df_driver_list)
message("DF Drivers: ${config_df_driver_list}")
endif()
# force static lib build
set(BUILD_SHARED_LIBS OFF)
@ -249,7 +265,7 @@ set(BUILD_SHARED_LIBS OFF)
#
option(CCACHE "Use ccache if available" OFF)
find_program(CCACHE_PROGRAM ccache)
if(CCACHE AND CCACHE_PROGRAM)
if (CCACHE AND CCACHE_PROGRAM)
message(STATUS "Enabled ccache: ${CCACHE_PROGRAM}")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
endif()
@ -302,9 +318,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(required_variables
CMAKE_C_COMPILER_ID
)
set(required_variables CMAKE_C_COMPILER_ID CMAKE_CXX_COMPILER_ID)
foreach(var ${required_variables})
if (NOT ${var})
message(FATAL_ERROR "Toolchain/config must define ${var}")
@ -327,43 +341,6 @@ execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version
STRING(REGEX MATCH "[^\n]*" cxx_compiler_version_short ${cxx_compiler_version})
message(STATUS "C++ compiler: ${cxx_compiler_version_short}")
#=============================================================================
# git
#
px4_add_git_submodule(TARGET git_cmake_hexagon PATH "cmake/cmake_hexagon")
px4_add_git_submodule(TARGET git_driverframework PATH "src/lib/DriverFramework")
px4_add_git_submodule(TARGET git_ecl PATH "src/lib/ecl")
px4_add_git_submodule(TARGET git_gazebo PATH "Tools/sitl_gazebo")
px4_add_git_submodule(TARGET git_gencpp PATH "Tools/gencpp")
px4_add_git_submodule(TARGET git_genmsg PATH "Tools/genmsg")
px4_add_git_submodule(TARGET git_gtest PATH "unittests/gtest")
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_uavcan PATH "src/modules/uavcan/libuavcan")
add_custom_target(submodule_clean
WORKING_DIRECTORY ${PX4_SOURCE_DIR}
COMMAND git submodule deinit -f .
COMMAND rm -rf .git/modules/*
)
#=============================================================================
# misc targets
#
add_custom_target(check_format
COMMAND Tools/check_code_style.sh
WORKING_DIRECTORY ${PX4_SOURCE_DIR}
)
add_custom_target(config
COMMAND cmake-gui .
WORKING_DIRECTORY ${PX4_BINARY_DIR}
)
#=============================================================================
# external libraries
#
@ -394,9 +371,11 @@ link_directories(${link_dirs})
add_definitions(${definitions})
#=============================================================================
# source code generation
# message, parameter, and airframe generation
#
include(common/px4_metadata)
add_subdirectory(msg)
px4_generate_messages(TARGET msg_gen
MSG_FILES ${msg_files}
@ -404,21 +383,31 @@ px4_generate_messages(TARGET msg_gen
INCLUDES ${msg_include_paths}
DEPENDS git_genmsg git_gencpp prebuild_targets
)
px4_generate_parameters_xml(OUT parameters.xml
BOARD ${BOARD}
MODULES ${config_module_list}
OVERRIDES ${PARAM_DEFAULT_OVERRIDES})
px4_generate_airframes_xml(OUT airframes.xml BOARD ${BOARD})
add_custom_target(xml_gen
DEPENDS parameters.xml airframes.xml)
if(NOT "${config_nuttx_config}" STREQUAL "bootloader")
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/airframes.xml
${CMAKE_CURRENT_BINARY_DIR}/parameters.xml
DESTINATION .)
px4_generate_airframes_xml(OUT airframes.xml BOARD ${BOARD})
add_custom_target(xml_gen DEPENDS parameters.xml airframes.xml)
#=============================================================================
# DriverFramework
#
# List the DriverFramework drivers
if (DEFINED config_df_driver_list)
message("DF Drivers: ${config_df_driver_list}")
endif()
set(df_driver_libs)
foreach(driver ${config_df_driver_list})
add_subdirectory(src/lib/DriverFramework/drivers/${driver})
list(APPEND df_driver_libs df_${driver})
message("Adding DF driver: ${driver}")
endforeach()
#=============================================================================
# external projects
#
@ -433,20 +422,10 @@ include_directories(${ep_base}/Install/include)
execute_process(COMMAND cmake -E make_directory ${ep_base}/Install/lib)
execute_process(COMMAND cmake -E make_directory ${ep_base}/Install/include)
#=============================================================================
# DriverFramework Drivers
#
set(df_driver_libs)
foreach(driver ${config_df_driver_list})
add_subdirectory(src/lib/DriverFramework/drivers/${driver})
list(APPEND df_driver_libs df_${driver})
message("Adding DF driver: ${driver}")
endforeach()
#=============================================================================
# external modules
#
if(NOT EXTERNAL_MODULES_LOCATION STREQUAL "")
if (NOT EXTERNAL_MODULES_LOCATION STREQUAL "")
message(STATUS "External modules: ${EXTERNAL_MODULES_LOCATION}")
add_subdirectory("${EXTERNAL_MODULES_LOCATION}/src" external_modules_src)
@ -467,7 +446,7 @@ endif()
set(module_libraries)
foreach(module ${config_module_list})
string(REGEX MATCH "^[./]" external_module ${module})
if(external_module)
if (external_module)
STRING(REGEX REPLACE "//" "/" EXT_MODULE ${module})
STRING(REGEX REPLACE "/" "__" EXT_MODULE_PREFIX ${EXT_MODULE})
add_subdirectory(${module} ${PX4_BINARY_DIR}/${EXT_MODULE_PREFIX})
@ -476,7 +455,6 @@ foreach(module ${config_module_list})
endif()
px4_mangle_name(${module} mangled_name)
list(APPEND module_libraries ${mangled_name})
#message(STATUS "adding module: ${module}")
endforeach()
# Keep track of external shared libs required for modules
@ -484,10 +462,6 @@ set(module_external_libraries "${module_external_libraries}" CACHE INTERNAL "mod
add_subdirectory(src/firmware/${OS})
#add_dependencies(df_driver_framework nuttx_export_${CONFIG})
if (NOT "${OS}" STREQUAL "nuttx")
endif()
if (config_io_board)
add_subdirectory(src/modules/px4iofirmware)
endif()
@ -495,7 +469,7 @@ endif()
#=============================================================================
# generate custom target to print for all executable and module cmake targets
#
if(all_posix_cmake_targets)
if (all_posix_cmake_targets)
list(SORT all_posix_cmake_targets)
px4_join(OUT posix_cmake_target_list LIST ${all_posix_cmake_targets} GLUE "\\n")
add_custom_target(list_cmake_targets
@ -505,18 +479,13 @@ if(all_posix_cmake_targets)
)
endif()
#=============================================================================
# generate git version
#
px4_create_git_hash_header()
#=============================================================================
# packaging
#
# Important to having packaging at end of cmake file.
#
set(CPACK_PACKAGE_NAME ${PROJECT_NAME}-${CONFIG})
set(CPACK_PACKAGE_VERSION ${version})
set(CPACK_PACKAGE_VERSION ${git_version})
set(CPACK_PACKAGE_CONTACT ${package-contact})
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set(CPACK_DEBIAN_PACKAGE_SECTION "devel")
@ -525,7 +494,7 @@ set(short-description "The px4 autopilot.")
set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${short-description})
set(CPACK_GENERATOR "ZIP")
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${CONFIG}-${git_tag}")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${version}")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${git_version}")
set(CPACK_SOURCE_GENERATOR "ZIP;TBZ2")
set(CPACK_PACKAGING_INSTALL_PREFIX "")
set(CPACK_SET_DESTDIR "OFF")

View File

@ -124,6 +124,9 @@ ifdef EXTERNAL_MODULES_LOCATION
CMAKE_ARGS := -DEXTERNAL_MODULES_LOCATION:STRING=$(EXTERNAL_MODULES_LOCATION)
endif
ifdef PX4_CMAKE_BUILD_TYPE
CMAKE_ARGS += -DCMAKE_BUILD_TYPE=${PX4_CMAKE_BUILD_TYPE}
endif
# Functions
# --------------------------------------------------------------------
@ -131,7 +134,7 @@ endif
define cmake-build
+@$(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
+@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))
endef
@ -178,10 +181,10 @@ excelsior_legacy_default: posix_excelsior_legacy qurt_excelsior_legacy
# Other targets
# --------------------------------------------------------------------
.PHONY: qgc_firmware px4fmu_firmware misc_qgc_extra_firmware alt_firmware checks_bootloaders uavcan_firmware sizes check quick_check
.PHONY: qgc_firmware px4fmu_firmware misc_qgc_extra_firmware alt_firmware checks_bootloaders sizes check quick_check
# QGroundControl flashable NuttX firmware
qgc_firmware: px4fmu_firmware misc_firmware sizes
qgc_firmware: px4fmu_firmware misc_qgc_extra_firmware sizes
# px4fmu NuttX firmware
px4fmu_firmware: \
@ -221,13 +224,6 @@ checks_bootloaders: \
# not fitting in flash check_zubaxgnss-v1_bootloader \
sizes
uavcan_firmware:
$(call colorecho,"Downloading and building Vector control (FOC) firmware for the S2740VC and PX4ESC 1.6")
@rm -rf vectorcontrol
@git clone --quiet --depth 1 https://github.com/thiemar/vectorcontrol.git && cd vectorcontrol
@BOARD=s2740vc_1_0 make --silent --no-print-directory
@BOARD=px4esc_1_6 make --silent --no-print-directory && $(SRC_DIR)/Tools/uavcan_copy.sh)
sizes:
@-find build_* -name firmware_nuttx -type f | xargs size 2> /dev/null || :
@ -262,7 +258,7 @@ px4_metadata: parameters_metadata airframe_metadata
# AWS_ACCESS_KEY_ID
# AWS_SECRET_ACCESS_KEY
# AWS_S3_BUCKET
.PHONY: s3put_firmware s3put_qgc_firmware s3put_px4fmu_firmware s3put_misc_qgc_extra_firmware s3put_px4_metadata s3put_scan-build
.PHONY: s3put_firmware s3put_qgc_firmware s3put_px4fmu_firmware s3put_misc_qgc_extra_firmware s3put_metadata s3put_scan-build s3put_cppcheck s3put_coverage
Firmware.zip:
@rm -rf Firmware.zip
@ -272,7 +268,6 @@ s3put_firmware: Firmware.zip
$(SRC_DIR)/Tools/s3put.sh Firmware.zip
s3put_qgc_firmware: s3put_px4fmu_firmware s3put_misc_qgc_extra_firmware
@find $(SRC_DIR)/build_* -name "*.px4" -exec $(SRC_DIR)/Tools/s3put.sh "{}" \;
s3put_px4fmu_firmware: px4fmu_firmware
@find $(SRC_DIR)/build_* -name "*.px4" -exec $(SRC_DIR)/Tools/s3put.sh "{}" \;
@ -280,7 +275,7 @@ s3put_px4fmu_firmware: px4fmu_firmware
s3put_misc_qgc_extra_firmware: misc_qgc_extra_firmware
@find $(SRC_DIR)/build_* -name "*.px4" -exec $(SRC_DIR)/Tools/s3put.sh "{}" \;
s3put_px4_metadata: px4_metadata
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
@ -293,7 +288,7 @@ s3put_cppcheck: cppcheck
@cd $(SRC_DIR) && ./Tools/s3put.sh cppcheck/
s3put_coverage: tests_coverage
@cd $(SRC_DIR) && ./Tools/s3put.sh coverage-html/
@cd $(SRC_DIR) && ./Tools/s3put.sh build_posix_sitl_default/coverage-html/
# Astyle
# --------------------------------------------------------------------
@ -322,14 +317,19 @@ run_tests_posix:
tests: unittest run_tests_posix
tests_coverage:
@lcov --zerocounters --directory $(SRC_DIR) --quiet
@lcov --capture --initial --directory $(SRC_DIR) --quiet --output-file coverage.info
@$(MAKE) --no-print-directory unittest PX4_CODE_COVERAGE=1 CCACHE_DISABLE=1
@$(MAKE) --no-print-directory posix_sitl_default test_results PX4_CODE_COVERAGE=1 CCACHE_DISABLE=1
@lcov --no-checksum --directory $(SRC_DIR) --capture --quiet --output-file coverage.info
@lcov --remove coverage.info '/usr/*' 'unittests/googletest/*' --quiet --output-file coverage.info
@genhtml --legend --show-details --function-coverage --quiet --output-directory coverage-html coverage.info
@$(MAKE) --no-print-directory posix_sitl_default test_results_junit
@$(MAKE) --no-print-directory posix_sitl_default test_coverage_genhtml PX4_CMAKE_BUILD_TYPE=Coverage
coveralls_upload:
@cpp-coveralls --include src/ \
--exclude src/lib/DriverFramework \
--exclude src/lib/ecl \
--exclude src/lib/Matrix \
--exclude=src/modules/uavcan/libuavcan \
--exclude-pattern ".*/unittests/googletest/.*" \
--root . --build-root build_posix_sitl_default/ --follow-symlinks
codecov_upload:
@/bin/bash -c "bash <(curl -s https://codecov.io/bash)"
# static analyzers (scan-build, clang-tidy, cppcheck)
# --------------------------------------------------------------------

View File

@ -2,7 +2,7 @@
if [[ $@ =~ .*px4fmu.* ]]; then
# nuttx-px4fmu-v{1,2,3,4,5}
PX4_DOCKER_REPO="px4io/px4-dev-nuttx:2017-04-22"
PX4_DOCKER_REPO="px4io/px4-dev-nuttx:2017-06-01"
elif [[ $@ =~ .*rpi.* ]] || [[ $@ =~ .*bebop.* ]]; then
# posix_rpi_cross, posix_bebop_default
PX4_DOCKER_REPO="px4io/px4-dev-raspi:2017-04-22"
@ -12,14 +12,18 @@ elif [[ $@ =~ .*eagle.* ]] || [[ $@ =~ .*excelsior.* ]]; then
elif [[ $@ =~ .*clang.* ]] || [[ $@ =~ .*scan-build.* ]]; then
# clang tools
PX4_DOCKER_REPO="px4io/px4-dev-clang:2017-04-22"
elif [[ $@ =~ .*cppcheck.* ]]; then
# need Ubuntu 17.04 for cppcheck cmake support
# TODO: remove this once px4io/px4-dev-base updates
PX4_DOCKER_REPO=px4io/px4-dev-base:ubuntu17.04
elif [[ $@ =~ .*tests* ]]; then
# run all tests with simulation
PX4_DOCKER_REPO="px4io/px4-dev-simulation:2017-04-22"
PX4_DOCKER_REPO="px4io/px4-dev-simulation:2017-06-01"
fi
# otherwise default to nuttx
if [ -z "$PX4_DOCKER_REPO" ]; then
PX4_DOCKER_REPO="px4io/px4-dev-nuttx:2017-04-22"
PX4_DOCKER_REPO="px4io/px4-dev-nuttx:2017-06-01"
fi
# docker hygiene
@ -46,6 +50,7 @@ docker run -it --rm -w "${SRC_DIR}" \
-e BRANCH_NAME="${BRANCH_NAME}" \
-e CCACHE_DIR="${CCACHE_DIR}" \
-e CI="${CI}" \
-e CODECOV_TOKEN="${CODECOV_TOKEN}" \
-e COVERALLS_REPO_TOKEN="${COVERALLS_REPO_TOKEN}" \
-e DISPLAY="${DISPLAY}" \
-e LOCAL_USER_ID="$(id -u)" \

106
cmake/common/coverage.cmake Normal file
View File

@ -0,0 +1,106 @@
############################################################################
#
# Copyright (c) 2017 PX4 Development Team. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name PX4 nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
find_program(LCOV_PATH lcov)
find_program(GENHTML_PATH genhtml)
# add code coverage build type
set(CMAKE_C_FLAGS_COVERAGE "--coverage -ftest-coverage -fprofile-arcs -O0 -fno-default-inline -fno-inline"
CACHE STRING "Flags used by the C compiler during coverage builds" FORCE)
set(CMAKE_CXX_FLAGS_COVERAGE "--coverage -ftest-coverage -fprofile-arcs -O0 -fno-default-inline -fno-inline -fno-elide-constructors"
CACHE STRING "Flags used by the C++ compiler during coverage builds" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_COVERAGE "--coverage -ftest-coverage -lgcov"
CACHE STRING "Flags used for linking binaries during coverage builds" FORCE)
mark_as_advanced(CMAKE_CXX_FLAGS_COVERAGE CMAKE_C_FLAGS_COVERAGE CMAKE_EXE_LINKER_FLAGS_COVERAGE)
# Param _targetname The name of new the custom make target
# Param _testrunner The name of the target which runs the tests.
#
# Param _outputname lcov output is generated as _outputname.info
# HTML report is generated in _outputname/index.html
# Optional fourth parameter is passed as arguments to _testrunner
# Pass them in list form, e.g.: "-j;2" for -j 2
FUNCTION(SETUP_TARGET_FOR_COVERAGE _targetname _testrunner _outputname)
set(options NONE)
set(oneValueArgs NAME)
set(multiValueArgs EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES)
cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if (NOT LCOV_PATH)
message(FATAL_ERROR "lcov required")
endif()
if (NOT GENHTML_PATH)
message(FATAL_ERROR "genhtml required")
endif()
set(coverage_info "${CMAKE_BINARY_DIR}/coverage.info")
set(coverage_cleaned "${coverage_info}.cleaned")
separate_arguments(test_command UNIX_COMMAND "${_testrunner}")
# Setup target
add_custom_COMMAND(OUTPUT ${coverage_info}
# Cleanup lcov
COMMAND ${LCOV_PATH} --quiet --directory . --zerocounters
# Run tests
COMMAND ${test_command} ${ARGV3}
# Capturing lcov counters and generating report
COMMAND ${LCOV_PATH} --quiet --base-directory ${CMAKE_BINARY_DIR} --directory ${CMAKE_SOURCE_DIR} --capture --output-file ${coverage_info}
DEPENDS px4
USES_TERMINAL
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Running code coverage and generating report."
)
add_custom_target(${_targetname} DEPENDS ${coverage_info})
add_custom_command(OUTPUT ${coverage_cleaned}
COMMAND COMMAND ${LCOV_PATH} --quiet --remove ${coverage_info} 'tests/*' '/usr/*' --output-file ${coverage_cleaned}
DEPENDS ${coverage_info}
)
add_custom_target(${_targetname}_genhtml
COMMAND ${GENHTML_PATH} --quiet -o coverage-html ${coverage_cleaned}
DEPENDS ${coverage_cleaned}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
endfunction() # SETUP_TARGET_FOR_COVERAGE

View File

@ -38,12 +38,8 @@
# 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
# * px4_add_optimization_flags_for_target
# * px4_add_executable
@ -116,81 +112,6 @@ function(px4_parse_function_args)
endforeach()
endfunction()
#=============================================================================
#
# px4_add_git_submodule
#
# This function add a git submodule target.
#
# Usage:
# px4_add_git_submodule(TARGET <target> PATH <path>)
#
# Input:
# PATH : git submodule path
#
# Output:
# TARGET : git target
#
# Example:
# px4_add_git_submodule(TARGET git_nuttx PATH "NuttX")
#
function(px4_add_git_submodule)
px4_parse_function_args(
NAME px4_add_git_submodule
ONE_VALUE TARGET PATH
REQUIRED TARGET PATH
ARGN ${ARGN})
string(REPLACE "/" "_" NAME ${PATH})
add_custom_command(OUTPUT ${PX4_BINARY_DIR}/git_init_${NAME}.stamp
WORKING_DIRECTORY ${PX4_SOURCE_DIR}
COMMAND touch ${PX4_BINARY_DIR}/git_init_${NAME}.stamp
DEPENDS ${PX4_SOURCE_DIR}/.gitmodules
)
add_custom_target(${TARGET}
WORKING_DIRECTORY ${PX4_SOURCE_DIR}
# todo:Not have 2 list of submodules one (see the end of Tools/check_submodules.sh and Firmware/CMakeLists.txt)
# using the list of submodules from the CMake file to drive the test
# COMMAND Tools/check_submodules.sh ${PATH}
DEPENDS ${PX4_BINARY_DIR}/git_init_${NAME}.stamp
)
endfunction()
#=============================================================================
#
# px4_prepend_string
#
# This function prepends a string to a list
#
# Usage:
# px4_prepend_string(OUT <output-list> STR <string> LIST <list>)
#
# Input:
# STR : string to prepend
# LIST : list to prepend to
#
# Output:
# ${OUT} : prepended list
#
# Example:
# px4_prepend_string(OUT test_str STR "path/to/" LIST src/file1.cpp src/file2.cpp)
# test_str would then be:
# path/to/src/file1.cpp
# path/to/src/file2.cpp
#
function(px4_prepend_string)
px4_parse_function_args(
NAME px4_prepend_string
ONE_VALUE OUT STR
MULTI_VALUE LIST
REQUIRED OUT STR LIST
ARGN ${ARGN})
set(${OUT})
foreach(file ${LIST})
list(APPEND ${OUT} ${STR}${file})
endforeach()
set(${OUT} ${${OUT}} PARENT_SCOPE)
endfunction()
#=============================================================================
#
# px4_join
@ -248,7 +169,7 @@ endfunction()
# STACK : deprecated use stack main instead
# STACK_MAIN : size of stack for main function
# STACK_MAX : maximum stack size of any frame
# COMPILE_FLAGS : compile flags
# COMPILE_FLAGS : compile flags
# LINK_FLAGS : link flags
# SRCS : source files
# INCLUDES : include directories
@ -277,7 +198,7 @@ function(px4_add_module)
REQUIRED MODULE
ARGN ${ARGN})
if(EXTERNAL)
if (EXTERNAL)
px4_mangle_name("${EXTERNAL_MODULES_LOCATION}/src/${MODULE}" MODULE)
endif()
@ -352,260 +273,6 @@ function(px4_add_module)
endfunction()
#=============================================================================
#
# px4_generate_messages
#
# This function generates source code from ROS msg definitions.
#
# Usage:
# px4_generate_messages(TARGET <target> MSGS <msg-files>)
#
# Input:
# MSG_FILES : the ROS msgs to generate files from
# OS : the operating system selected
# DEPENDS : dependencies
#
# Output:
# TARGET : the message generation target
#
# Example:
# px4_generate_messages(TARGET <target>
# MSG_FILES <files> OS <operating-system>
# [ DEPENDS <dependencies> ]
# )
#
function(px4_generate_messages)
px4_parse_function_args(
NAME px4_generate_messages
OPTIONS VERBOSE
ONE_VALUE OS TARGET
MULTI_VALUE MSG_FILES DEPENDS INCLUDES
REQUIRED MSG_FILES OS TARGET
ARGN ${ARGN})
if("${config_nuttx_config}" STREQUAL "bootloader")
else()
set(QUIET)
if(NOT VERBOSE)
set(QUIET "-q")
endif()
# headers
set(msg_out_path ${PX4_BINARY_DIR}/src/modules/uORB/topics)
set(msg_list)
foreach(msg_file ${MSG_FILES})
get_filename_component(msg ${msg_file} NAME_WE)
list(APPEND msg_list ${msg})
endforeach()
set(msg_files_out)
foreach(msg ${msg_list})
list(APPEND msg_files_out ${msg_out_path}/${msg}.h)
endforeach()
add_custom_command(OUTPUT ${msg_files_out}
COMMAND ${PYTHON_EXECUTABLE}
Tools/px_generate_uorb_topic_files.py
--headers
${QUIET}
-f ${MSG_FILES}
-i ${INCLUDES}
-o ${msg_out_path}
-e msg/templates/uorb
-t ${PX4_BINARY_DIR}/topics_temporary_header
DEPENDS ${DEPENDS} ${MSG_FILES}
WORKING_DIRECTORY ${PX4_SOURCE_DIR}
COMMENT "Generating uORB topic headers"
VERBATIM
)
# !sources
set(msg_source_out_path ${PX4_BINARY_DIR}/topics_sources)
set(msg_source_files_out ${msg_source_out_path}/uORBTopics.cpp)
foreach(msg ${msg_list})
list(APPEND msg_source_files_out ${msg_source_out_path}/${msg}.cpp)
endforeach()
add_custom_command(OUTPUT ${msg_source_files_out}
COMMAND ${PYTHON_EXECUTABLE}
Tools/px_generate_uorb_topic_files.py
--sources
${QUIET}
-f ${MSG_FILES}
-i ${INCLUDES}
-o ${msg_source_out_path}
-e msg/templates/uorb
-t ${PX4_BINARY_DIR}/topics_temporary_sources
DEPENDS ${DEPENDS} ${MSG_FILES}
WORKING_DIRECTORY ${PX4_SOURCE_DIR}
COMMENT "Generating uORB topic sources"
VERBATIM
)
set_source_files_properties(${msg_source_files_out} PROPERTIES GENERATED TRUE)
# multi messages for target OS
set(msg_multi_out_path
${PX4_BINARY_DIR}/src/platforms/${OS}/px4_messages)
set(msg_multi_files_out)
foreach(msg ${msg_list})
list(APPEND msg_multi_files_out ${msg_multi_out_path}/px4_${msg}.h)
endforeach()
add_custom_command(OUTPUT ${msg_multi_files_out}
COMMAND ${PYTHON_EXECUTABLE}
Tools/px_generate_uorb_topic_files.py
--headers
${QUIET}
-f ${MSG_FILES}
-i ${INCLUDES}
-o ${msg_multi_out_path}
-e msg/templates/px4/uorb
-t ${PX4_BINARY_DIR}/multi_topics_temporary/${OS}
-p "px4_"
DEPENDS ${DEPENDS} ${MSG_FILES}
WORKING_DIRECTORY ${PX4_SOURCE_DIR}
COMMENT "Generating uORB topic multi headers for ${OS}"
VERBATIM
)
px4_add_library(${TARGET}
${msg_source_files_out}
${msg_multi_files_out}
${msg_files_out}
)
endif()
endfunction()
#=============================================================================
#
# px4_add_upload
#
# This function generates source code from ROS msg definitions.
#
# Usage:
# px4_add_upload(OUT <target> BUNDLE <file.px4>)
#
# Input:
# BUNDLE : the firmware.px4 file
# OS : the operating system
# BOARD : the board
#
# Output:
# OUT : the firmware target
#
# Example:
# px4_add_upload(OUT upload
# BUNDLE main.px4
# )
#
function(px4_add_upload)
px4_parse_function_args(
NAME px4_add_upload
ONE_VALUE OS BOARD OUT BUNDLE
REQUIRED OS BOARD OUT BUNDLE
ARGN ${ARGN})
set(serial_ports)
if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Linux")
list(APPEND serial_ports
/dev/serial/by-id/*_PX4_*
/dev/serial/by-id/usb-3D_Robotics*
/dev/serial/by-id/usb-The_Autopilot*
/dev/serial/by-id/usb-Bitcraze*
/dev/serial/by-id/pci-3D_Robotics*
/dev/serial/by-id/pci-Bitcraze*
/dev/serial/by-id/usb-Gumstix*
)
elseif(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Darwin")
list(APPEND serial_ports
/dev/tty.usbmodemPX*,/dev/tty.usbmodem*
)
elseif(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows")
foreach(port RANGE 32 0)
list(APPEND serial_ports
"COM${port}")
endforeach()
endif()
px4_join(OUT serial_ports LIST "${serial_ports}" GLUE ",")
add_custom_target(${OUT}
COMMAND ${PYTHON_EXECUTABLE}
${PX4_SOURCE_DIR}/Tools/px_uploader.py --port ${serial_ports} ${BUNDLE}
DEPENDS ${BUNDLE}
WORKING_DIRECTORY ${PX4_BINARY_DIR}
COMMENT "uploading ${BUNDLE}"
VERBATIM
USES_TERMINAL
)
endfunction()
function(px4_add_adb_push)
px4_parse_function_args(
NAME px4_add_upload
ONE_VALUE OS BOARD OUT DEST
MULTI_VALUE FILES DEPENDS
REQUIRED OS BOARD OUT FILES DEPENDS DEST
ARGN ${ARGN})
add_custom_target(${OUT}
COMMAND ${PX4_SOURCE_DIR}/Tools/adb_upload.sh ${FILES} ${DEST}
DEPENDS ${DEPENDS}
WORKING_DIRECTORY ${PX4_BINARY_DIR}
COMMENT "uploading ${BUNDLE}"
VERBATIM
USES_TERMINAL
)
endfunction()
function(px4_add_adb_push_to_bebop)
px4_parse_function_args(
NAME px4_add_upload_to_bebop
ONE_VALUE OS BOARD OUT DEST
MULTI_VALUE FILES DEPENDS
REQUIRED OS BOARD OUT FILES DEPENDS DEST
ARGN ${ARGN})
add_custom_target(${OUT}
COMMAND ${PX4_SOURCE_DIR}/Tools/adb_upload_to_bebop.sh ${FILES} ${DEST}
DEPENDS ${DEPENDS}
WORKING_DIRECTORY ${PX4_BINARY_DIR}
COMMENT "uploading ${BUNDLE}"
VERBATIM
USES_TERMINAL
)
endfunction()
function(px4_add_scp_push)
px4_parse_function_args(
NAME px4_add_upload
ONE_VALUE OS BOARD OUT DEST
MULTI_VALUE FILES DEPENDS
REQUIRED OS BOARD OUT FILES DEPENDS DEST
ARGN ${ARGN})
add_custom_target(${OUT}
COMMAND ${PX4_SOURCE_DIR}/Tools/scp_upload.sh ${FILES} ${DEST}
DEPENDS ${DEPENDS}
WORKING_DIRECTORY ${PX4_BINARY_DIR}
COMMENT "uploading ${BUNDLE}"
VERBATIM
USES_TERMINAL
)
endfunction()
function(px4_add_upload_aero)
px4_parse_function_args(
NAME px4_add_upload_aero
ONE_VALUE OS BOARD OUT BUNDLE
REQUIRED OS BOARD OUT BUNDLE
ARGN ${ARGN})
add_custom_target(${OUT}
COMMAND ${PX4_SOURCE_DIR}/Tools/aero_upload.sh ${BUNDLE}
DEPENDS ${BUNDLE}
WORKING_DIRECTORY ${PX4_BINARY_DIR}
COMMENT "uploading ${BUNDLE}"
VERBATIM
USES_TERMINAL
)
endfunction()
#=============================================================================
#
# px4_add_common_flags
@ -657,27 +324,21 @@ function(px4_add_common_flags)
set(warnings
-Wall
-Warray-bounds
-Werror
-Wextra
-Wno-sign-compare
-Wshadow
-Wfloat-equal
-Wpointer-arith
-Wmissing-declarations
-Wno-unused-parameter
-Werror=format-security
-Werror=array-bounds
-Wfatal-errors
-Werror=unused-variable
-Werror=reorder
-Werror=uninitialized
-Werror=init-self
#-Wcast-qual - generates spurious noreturn attribute warnings,
# try again later
#-Wconversion - would be nice, but too many "risky-but-safe"
# conversions in the code
#-Wcast-align - would help catch bad casts in some cases,
# but generates too many false positives
-Wfloat-equal
-Wformat-security
-Winit-self
-Wmissing-declarations
-Wpointer-arith
-Wshadow
-Wuninitialized
-Wunused-variable
-Wno-sign-compare
-Wno-unused-parameter
)
if (${CMAKE_C_COMPILER_ID} MATCHES ".*Clang.*")
@ -693,111 +354,25 @@ function(px4_add_common_flags)
endif()
else()
list(APPEND warnings
-Werror=unused-but-set-variable
-Wunused-but-set-variable
-Wformat=1
#-Wlogical-op # very verbose due to eigen
-Wdouble-promotion
-Werror=double-promotion
)
endif()
# optimization flags and santiziers (ASAN, TSAN, UBSAN)
if ($ENV{PX4_ASAN} MATCHES "1")
message(STATUS "address sanitizer enabled")
# environment variables
# ASAN_OPTIONS=detect_stack_use_after_return=1
# ASAN_OPTIONS=check_initialization_order=1
set(max_optimization -O1)
# Do not use optimization_flags (without _) as that is already used.
set(_optimization_flags
-fno-strict-aliasing
-fno-omit-frame-pointer
-funsafe-math-optimizations
-ffunction-sections
-fdata-sections
-g3 -fsanitize=address
#-fsanitize-address-use-after-scope
)
elseif ($ENV{PX4_TSAN} MATCHES "1")
message(STATUS "thread sanitizer enabled")
# needs some optimization for usable performance
set(max_optimization -O1)
# Do not use optimization_flags (without _) as that is already used.
set(_optimization_flags
-fno-strict-aliasing
-fno-omit-frame-pointer
-funsafe-math-optimizations
-ffunction-sections
-fdata-sections
-g3 -fsanitize=thread
)
elseif ($ENV{PX4_UBSAN} MATCHES "1")
message(STATUS "undefined behaviour sanitizer enabled")
set(max_optimization -O2)
# Do not use optimization_flags (without _) as that is already used.
set(_optimization_flags
-fno-strict-aliasing
-fno-omit-frame-pointer
-funsafe-math-optimizations
-ffunction-sections
-fdata-sections
-g3
#-fsanitize=alignment
-fsanitize=bool
-fsanitize=bounds
-fsanitize=enum
#-fsanitize=float-cast-overflow
-fsanitize=float-divide-by-zero
#-fsanitize=function
-fsanitize=integer-divide-by-zero
-fsanitize=nonnull-attribute
-fsanitize=null
-fsanitize=object-size
-fsanitize=return
-fsanitize=returns-nonnull-attribute
-fsanitize=shift
-fsanitize=signed-integer-overflow
-fsanitize=unreachable
#-fsanitize=unsigned-integer-overflow
-fsanitize=vla-bound
-fsanitize=vptr
)
else()
if ("${OS}" STREQUAL "nuttx")
set(max_optimization -Os)
elseif (${BOARD} STREQUAL "bebop")
set(max_optimization -Os)
else()
set(max_optimization -O2)
endif()
if ("${OS}" STREQUAL "qurt")
set(PIC_FLAG -fPIC)
endif()
set(_optimization_flags
-fno-strict-aliasing
-fomit-frame-pointer
-funsafe-math-optimizations
-ffunction-sections
-fdata-sections
${PIC_FLAG}
)
if ("${OS}" STREQUAL "qurt")
set(PIC_FLAG -fPIC)
endif()
# code coverage
if ($ENV{PX4_CODE_COVERAGE} MATCHES "1")
#set(max_optimization -O0)
endif()
set(_optimization_flags
-fno-strict-aliasing
-fomit-frame-pointer
-funsafe-math-optimizations
-ffunction-sections
-fdata-sections
${PIC_FLAG}
)
set(c_warnings
-Wbad-function-cast
@ -814,6 +389,7 @@ function(px4_add_common_flags)
set(cxx_warnings
-Wno-missing-field-initializers
-Wreorder
)
set(cxx_compile_flags
@ -875,7 +451,6 @@ function(px4_add_common_flags)
)
set(added_optimization_flags
${max_optimization}
${_optimization_flags}
)
@ -883,34 +458,26 @@ function(px4_add_common_flags)
${PX4_BINARY_DIR}
${PX4_BINARY_DIR}/src
${PX4_BINARY_DIR}/src/modules
${PX4_BINARY_DIR}/src/modules/px4_messages
${PX4_SOURCE_DIR}/mavlink/include/mavlink
${PX4_SOURCE_DIR}/src
${PX4_SOURCE_DIR}/src/drivers/boards/${BOARD}
${PX4_SOURCE_DIR}/src/include
${PX4_SOURCE_DIR}/src/lib
${PX4_SOURCE_DIR}/src/lib/DriverFramework/framework/include
${PX4_SOURCE_DIR}/src/lib/matrix
${PX4_SOURCE_DIR}/src/modules
${PX4_SOURCE_DIR}/src/platforms
)
list(APPEND added_include_dirs
src/lib/matrix
)
set(added_link_dirs) # none used currently
set(added_exe_linker_flags)
string(TOUPPER ${BOARD} board_upper)
string(REPLACE "-" "_" board_config ${board_upper})
set (added_target_definitions)
if (NOT ${target_definitions})
px4_prepend_string(OUT added_target_definitions STR "-D" LIST ${target_definitions})
endif()
set(added_definitions
-DCONFIG_ARCH_BOARD_${board_config}
-D__STDC_FORMAT_MACROS
${added_target_definitions}
)
if (NOT (APPLE AND (${CMAKE_C_COMPILER_ID} MATCHES ".*Clang.*")))
@ -921,20 +488,6 @@ function(px4_add_common_flags)
)
endif()
# code coverage
if ($ENV{PX4_CODE_COVERAGE} MATCHES "1")
message(STATUS "Code coverage build flags enabled")
list(APPEND added_cxx_flags
-fprofile-arcs -ftest-coverage --coverage -g3 -O0 -fno-elide-constructors -Wno-invalid-offsetof -fno-default-inline -fno-inline
)
list(APPEND added_c_flags
-fprofile-arcs -ftest-coverage --coverage -g3 -O0 -fno-default-inline -fno-inline
)
list(APPEND added_exe_linker_flags
-ftest-coverage --coverage -lgcov
)
endif()
# output
foreach(var ${inout_vars})
string(TOLOWER ${var} lower_var)
@ -969,280 +522,6 @@ function(px4_mangle_name dirname newname)
set(${newname} ${tmp} PARENT_SCOPE)
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()
#=============================================================================
#
# px4_generate_parameters_xml
#
# Generates a parameters.xml file.
#
# Usage:
# px4_generate_parameters_xml(OUT <param-xml_file>)
#
# Input:
# BOARD : the board
# MODULES : a list of px4 modules used to limit scope of the paramaters
# OVERRIDES : A json dict with param names as keys and param default
# overrides as values
#
# Output:
# OUT : the generated xml file
#
# Example:
# px4_generate_parameters_xml(OUT parameters.xml)
#
function(px4_generate_parameters_xml)
px4_parse_function_args(
NAME px4_generate_parameters_xml
ONE_VALUE OUT BOARD OVERRIDES
MULTI_VALUE MODULES
REQUIRED MODULES OUT BOARD
ARGN ${ARGN})
set(path ${PX4_SOURCE_DIR}/src)
file(GLOB_RECURSE param_src_files
${PX4_SOURCE_DIR}/src/*params.c
)
if (NOT OVERRIDES)
set(OVERRIDES "{}")
endif()
# get full path for each module
set(module_list)
if(DISABLE_PARAMS_MODULE_SCOPING)
set(module_list ${path})
else()
foreach(module ${MODULES})
list(APPEND module_list ${PX4_SOURCE_DIR}/src/${module})
endforeach()
endif()
add_custom_command(OUTPUT ${OUT}
COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/px_process_params.py
-s ${module_list} ${EXTERNAL_MODULES_LOCATION}
--board CONFIG_ARCH_${BOARD} --xml --inject-xml
--overrides ${OVERRIDES}
DEPENDS ${param_src_files} ${PX4_SOURCE_DIR}/Tools/px_process_params.py
${PX4_SOURCE_DIR}/Tools/px_generate_params.py
)
set(${OUT} ${${OUT}} PARENT_SCOPE)
endfunction()
#=============================================================================
#
# px4_generate_parameters_source
#
# Generates a source file with all parameters.
#
# Usage:
# px4_generate_parameters_source(OUT <list-source-files> XML <param-xml-file> MODULES px4 module list)
#
# Input:
# XML : the parameters.xml file
# MODULES : a list of px4 modules used to limit scope of the paramaters
# DEPS : target dependencies
#
# Output:
# OUT : the generated source files
#
# Example:
# px4_generate_parameters_source(OUT param_files XML parameters.xml MODULES lib/controllib modules/ekf2)
#
function(px4_generate_parameters_source)
px4_parse_function_args(
NAME px4_generate_parameters_source
ONE_VALUE OUT XML DEPS
MULTI_VALUE MODULES
REQUIRED MODULES OUT XML
ARGN ${ARGN})
set(generated_files
${CMAKE_CURRENT_BINARY_DIR}/px4_parameters.h
${CMAKE_CURRENT_BINARY_DIR}/px4_parameters.c)
set_source_files_properties(${generated_files}
PROPERTIES GENERATED TRUE)
if(DISABLE_PARAMS_MODULE_SCOPING)
add_custom_command(OUTPUT ${generated_files}
COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/px_generate_params.py
--xml ${XML} --dest ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${XML} ${DEPS}
)
else()
px4_join(OUT module_list LIST ${MODULES} GLUE ",")
add_custom_command(OUTPUT ${generated_files}
COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/px_generate_params.py
--xml ${XML} --modules ${module_list} --dest ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${XML} ${DEPS}
)
endif()
set(${OUT} ${generated_files} PARENT_SCOPE)
endfunction()
#=============================================================================
#
# px4_generate_airframes_xml
#
# Generates airframes.xml
#
# Usage:
# px4_generate_airframes_xml(OUT <airframe-xml-file>)
#
# Input:
# XML : the airframes.xml file
# BOARD : the board
#
# Output:
# OUT : the generated source files
#
# Example:
# px4_generate_airframes_xml(OUT airframes.xml)
#
function(px4_generate_airframes_xml)
px4_parse_function_args(
NAME px4_generate_airframes_xml
ONE_VALUE OUT BOARD
REQUIRED OUT BOARD
ARGN ${ARGN})
set(process_airframes ${PX4_SOURCE_DIR}/Tools/px_process_airframes.py)
add_custom_command(OUTPUT ${OUT}
COMMAND ${PYTHON_EXECUTABLE} ${process_airframes}
-a ${PX4_SOURCE_DIR}/ROMFS/${config_romfs_root}/init.d
--board CONFIG_ARCH_BOARD_${BOARD} --xml
)
set(${OUT} ${${OUT}} PARENT_SCOPE)
endfunction()
#=============================================================================
#
# px4_copy_tracked
#
# Copy files to a directory and keep track of dependencies.
#
# Usage:
# px4_copy_tracked(OUT <dest-files> FILES <in-files> DIR <dir-name>)
#
# Input:
# FILES : the source files
# DEST : the directory to copy files to
# RELATIVE : relative directory for source files
#
# Output:
# OUT : the copied files
#
# Example:
# px4_copy_tracked(OUT copied_files FILES src_files DEST path RELATIVE path_rel)
#
function(px4_copy_tracked)
px4_parse_function_args(
NAME px4_copy_tracked
ONE_VALUE DEST OUT RELATIVE
MULTI_VALUE FILES
REQUIRED DEST OUT FILES
ARGN ${ARGN})
set(files)
# before build, make sure dest directory exists
execute_process(
COMMAND cmake -E make_directory ${DEST})
# create rule to copy each file and set dependency as source file
set(_files_out)
foreach(_file ${FILES})
if (RELATIVE)
file(RELATIVE_PATH _file_path ${RELATIVE} ${_file})
else()
set(_file_path ${_file})
endif()
set(_dest_file ${DEST}/${_file_path})
#message(STATUS "copy ${_file} -> ${_dest_file}")
add_custom_command(OUTPUT ${_dest_file}
COMMAND cmake -E copy ${_file} ${_dest_file}
DEPENDS ${_file})
list(APPEND _files_out ${_dest_file})
endforeach()
set(${OUT} ${_files_out} PARENT_SCOPE)
endfunction()
#=============================================================================
#
# px4_share_subdirectory
#
# This function simplifes sharing a sub directory
#
# Usage:
# px4_share_subdirectory(RELDIR <relative path> ARGS <args>)
#
# Input:
# RELDIR : The relitive path to share.
# ARGS : Any optional arguments to pass to add_subdirectory
#
# Output:
# : None
#
# Example:
# px4_share_subdirectory(RELDIR ../uavcan/libuavcan ARGS EXCLUDE_FROM_ALL)
#
function(px4_share_subdirectory)
px4_parse_function_args(
NAME px4_share_subdirectory
ONE_VALUE OUT RELDIR
MULTI_VALUE ARGS
REQUIRED RELDIR
ARGN ${ARGN})
add_subdirectory(${RELDIR} ${RELDIR}/${RELDIR} ${ARGS})
endfunction()
#=============================================================================
#
# px4_strip_optimization

138
cmake/common/px4_git.cmake Normal file
View File

@ -0,0 +1,138 @@
############################################################################
#
# Copyright (c) 2017 PX4 Development Team. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name PX4 nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
include(CMakeParseArguments)
include(common/px4_base)
#=============================================================================
#
# Defined functions in this file
#
# utility functions
#
# * px4_add_git_submodule
# * px4_create_git_hash_header
#
#=============================================================================
#
# px4_add_git_submodule
#
# This function add a git submodule target.
#
# Usage:
# px4_add_git_submodule(TARGET <target> PATH <path>)
#
# Input:
# PATH : git submodule path
#
# Output:
# TARGET : git target
#
# Example:
# px4_add_git_submodule(TARGET git_nuttx PATH "NuttX")
#
function(px4_add_git_submodule)
px4_parse_function_args(
NAME px4_add_git_submodule
ONE_VALUE TARGET PATH
REQUIRED TARGET PATH
ARGN ${ARGN})
string(REPLACE "/" "_" NAME ${PATH})
add_custom_command(OUTPUT ${PX4_BINARY_DIR}/git_init_${NAME}.stamp
WORKING_DIRECTORY ${PX4_SOURCE_DIR}
COMMAND touch ${PX4_BINARY_DIR}/git_init_${NAME}.stamp
DEPENDS ${PX4_SOURCE_DIR}/.gitmodules
)
add_custom_target(${TARGET}
WORKING_DIRECTORY ${PX4_SOURCE_DIR}
# todo:Not have 2 list of submodules one (see the end of Tools/check_submodules.sh and Firmware/CMakeLists.txt)
# using the list of submodules from the CMake file to drive the test
# COMMAND Tools/check_submodules.sh ${PATH}
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()

View File

@ -0,0 +1,312 @@
############################################################################
#
# Copyright (c) 2017 PX4 Development Team. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name PX4 nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
#=============================================================================
#
# Defined functions in this file
#
# utility functions
#
# * px4_generate_messages
# * px4_generate_parameters_xml
# * px4_generate_parameters_source
# * px4_generate_airframes_xml
#
#=============================================================================
#
# px4_generate_messages
#
# This function generates source code from ROS msg definitions.
#
# Usage:
# px4_generate_messages(TARGET <target> MSGS <msg-files>)
#
# Input:
# MSG_FILES : the ROS msgs to generate files from
# OS : the operating system selected
# DEPENDS : dependencies
#
# Output:
# TARGET : the message generation target
#
# Example:
# px4_generate_messages(TARGET <target>
# MSG_FILES <files> OS <operating-system>
# [ DEPENDS <dependencies> ]
# )
#
function(px4_generate_messages)
px4_parse_function_args(
NAME px4_generate_messages
OPTIONS VERBOSE
ONE_VALUE OS TARGET
MULTI_VALUE MSG_FILES DEPENDS INCLUDES
REQUIRED MSG_FILES OS TARGET
ARGN ${ARGN})
if("${config_nuttx_config}" STREQUAL "bootloader")
# do nothing for bootloaders
else()
set(QUIET)
if (NOT VERBOSE)
set(QUIET "-q")
endif()
# headers
set(msg_out_path ${PX4_BINARY_DIR}/src/modules/uORB/topics)
set(msg_list)
foreach(msg_file ${MSG_FILES})
get_filename_component(msg ${msg_file} NAME_WE)
list(APPEND msg_list ${msg})
endforeach()
set(msg_files_out)
foreach(msg ${msg_list})
list(APPEND msg_files_out ${msg_out_path}/${msg}.h)
endforeach()
add_custom_command(OUTPUT ${msg_files_out}
COMMAND ${PYTHON_EXECUTABLE}
Tools/px_generate_uorb_topic_files.py
--headers
${QUIET}
-f ${MSG_FILES}
-i ${INCLUDES}
-o ${msg_out_path}
-e msg/templates/uorb
-t ${PX4_BINARY_DIR}/topics_temporary_header
DEPENDS ${DEPENDS} ${MSG_FILES}
WORKING_DIRECTORY ${PX4_SOURCE_DIR}
COMMENT "Generating uORB topic headers"
VERBATIM
)
# !sources
set(msg_source_out_path ${PX4_BINARY_DIR}/topics_sources)
set(msg_source_files_out ${msg_source_out_path}/uORBTopics.cpp)
foreach(msg ${msg_list})
list(APPEND msg_source_files_out ${msg_source_out_path}/${msg}.cpp)
endforeach()
add_custom_command(OUTPUT ${msg_source_files_out}
COMMAND ${PYTHON_EXECUTABLE}
Tools/px_generate_uorb_topic_files.py
--sources
${QUIET}
-f ${MSG_FILES}
-i ${INCLUDES}
-o ${msg_source_out_path}
-e msg/templates/uorb
-t ${PX4_BINARY_DIR}/topics_temporary_sources
DEPENDS ${DEPENDS} ${MSG_FILES}
WORKING_DIRECTORY ${PX4_SOURCE_DIR}
COMMENT "Generating uORB topic sources"
VERBATIM
)
set_source_files_properties(${msg_source_files_out} PROPERTIES GENERATED TRUE)
# multi messages for target OS
set(msg_multi_out_path ${PX4_BINARY_DIR}/src/platforms/${OS}/px4_messages)
set(msg_multi_files_out)
foreach(msg ${msg_list})
list(APPEND msg_multi_files_out ${msg_multi_out_path}/px4_${msg}.h)
endforeach()
add_custom_command(OUTPUT ${msg_multi_files_out}
COMMAND ${PYTHON_EXECUTABLE}
Tools/px_generate_uorb_topic_files.py
--headers
${QUIET}
-f ${MSG_FILES}
-i ${INCLUDES}
-o ${msg_multi_out_path}
-e msg/templates/px4/uorb
-t ${PX4_BINARY_DIR}/multi_topics_temporary/${OS}
-p "px4_"
DEPENDS ${DEPENDS} ${MSG_FILES}
WORKING_DIRECTORY ${PX4_SOURCE_DIR}
COMMENT "Generating uORB topic multi headers for ${OS}"
VERBATIM
)
px4_add_library(${TARGET}
${msg_source_files_out}
${msg_multi_files_out}
${msg_files_out}
)
endif()
endfunction()
#=============================================================================
#
# px4_generate_parameters_xml
#
# Generates a parameters.xml file.
#
# Usage:
# px4_generate_parameters_xml(OUT <param-xml_file>)
#
# Input:
# BOARD : the board
# MODULES : a list of px4 modules used to limit scope of the paramaters
# OVERRIDES : A json dict with param names as keys and param default
# overrides as values
#
# Output:
# OUT : the generated xml file
#
# Example:
# px4_generate_parameters_xml(OUT parameters.xml)
#
function(px4_generate_parameters_xml)
px4_parse_function_args(
NAME px4_generate_parameters_xml
ONE_VALUE OUT BOARD OVERRIDES
MULTI_VALUE MODULES
REQUIRED MODULES OUT BOARD
ARGN ${ARGN})
set(path ${PX4_SOURCE_DIR}/src)
file(GLOB_RECURSE param_src_files
${PX4_SOURCE_DIR}/src/*params.c
)
if (NOT OVERRIDES)
set(OVERRIDES "{}")
endif()
# get full path for each module
set(module_list)
if(DISABLE_PARAMS_MODULE_SCOPING)
set(module_list ${path})
else()
foreach(module ${MODULES})
list(APPEND module_list ${PX4_SOURCE_DIR}/src/${module})
endforeach()
endif()
add_custom_command(OUTPUT ${OUT}
COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/px_process_params.py
-s ${module_list} ${EXTERNAL_MODULES_LOCATION}
--board CONFIG_ARCH_${BOARD} --xml --inject-xml
--overrides ${OVERRIDES}
DEPENDS ${param_src_files} ${PX4_SOURCE_DIR}/Tools/px_process_params.py
${PX4_SOURCE_DIR}/Tools/px_generate_params.py
)
set(${OUT} ${${OUT}} PARENT_SCOPE)
endfunction()
#=============================================================================
#
# px4_generate_parameters_source
#
# Generates a source file with all parameters.
#
# Usage:
# px4_generate_parameters_source(OUT <list-source-files> XML <param-xml-file> MODULES px4 module list)
#
# Input:
# XML : the parameters.xml file
# MODULES : a list of px4 modules used to limit scope of the paramaters
# DEPS : target dependencies
#
# Output:
# OUT : the generated source files
#
# Example:
# px4_generate_parameters_source(OUT param_files XML parameters.xml MODULES lib/controllib modules/ekf2)
#
function(px4_generate_parameters_source)
px4_parse_function_args(
NAME px4_generate_parameters_source
ONE_VALUE OUT XML DEPS
MULTI_VALUE MODULES
REQUIRED MODULES OUT XML
ARGN ${ARGN})
set(generated_files
${CMAKE_CURRENT_BINARY_DIR}/px4_parameters.h
${CMAKE_CURRENT_BINARY_DIR}/px4_parameters.c)
set_source_files_properties(${generated_files} PROPERTIES GENERATED TRUE)
if(DISABLE_PARAMS_MODULE_SCOPING)
add_custom_command(OUTPUT ${generated_files}
COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/px_generate_params.py
--xml ${XML} --dest ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${XML} ${DEPS}
)
else()
px4_join(OUT module_list LIST ${MODULES} GLUE ",")
add_custom_command(OUTPUT ${generated_files}
COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/px_generate_params.py
--xml ${XML} --modules ${module_list} --dest ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${XML} ${DEPS}
)
endif()
set(${OUT} ${generated_files} PARENT_SCOPE)
endfunction()
#=============================================================================
#
# px4_generate_airframes_xml
#
# Generates airframes.xml
#
# Usage:
# px4_generate_airframes_xml(OUT <airframe-xml-file>)
#
# Input:
# XML : the airframes.xml file
# BOARD : the board
#
# Output:
# OUT : the generated source files
#
# Example:
# px4_generate_airframes_xml(OUT airframes.xml)
#
function(px4_generate_airframes_xml)
px4_parse_function_args(
NAME px4_generate_airframes_xml
ONE_VALUE OUT BOARD
REQUIRED OUT BOARD
ARGN ${ARGN})
set(process_airframes ${PX4_SOURCE_DIR}/Tools/px_process_airframes.py)
add_custom_command(OUTPUT ${OUT}
COMMAND ${PYTHON_EXECUTABLE} ${process_airframes}
-a ${PX4_SOURCE_DIR}/ROMFS/${config_romfs_root}/init.d
--board CONFIG_ARCH_BOARD_${BOARD} --xml
)
set(${OUT} ${${OUT}} PARENT_SCOPE)
endfunction()

View File

@ -0,0 +1,182 @@
############################################################################
#
# Copyright (c) 2017 PX4 Development Team. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name PX4 nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
#=============================================================================
#
# Defined functions in this file
#
# utility functions
#
# * px4_add_upload
# * px4_add_adb_push
# * px4_add_adb_push_to_bebop
# * px4_add_scp_push
# * px4_add_upload_aero
#
#=============================================================================
#
# px4_add_upload
#
# This function generates source code from ROS msg definitions.
#
# Usage:
# px4_add_upload(OUT <target> BUNDLE <file.px4>)
#
# Input:
# BUNDLE : the firmware.px4 file
# OS : the operating system
# BOARD : the board
#
# Output:
# OUT : the firmware target
#
# Example:
# px4_add_upload(OUT upload
# BUNDLE main.px4
# )
#
function(px4_add_upload)
px4_parse_function_args(
NAME px4_add_upload
ONE_VALUE OS BOARD OUT BUNDLE
REQUIRED OS BOARD OUT BUNDLE
ARGN ${ARGN})
set(serial_ports)
if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Linux")
list(APPEND serial_ports
/dev/serial/by-id/*_PX4_*
/dev/serial/by-id/usb-3D_Robotics*
/dev/serial/by-id/usb-The_Autopilot*
/dev/serial/by-id/usb-Bitcraze*
/dev/serial/by-id/pci-3D_Robotics*
/dev/serial/by-id/pci-Bitcraze*
/dev/serial/by-id/usb-Gumstix*
)
elseif(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Darwin")
list(APPEND serial_ports
/dev/tty.usbmodemPX*,/dev/tty.usbmodem*
)
elseif(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows")
foreach(port RANGE 32 0)
list(APPEND serial_ports
"COM${port}")
endforeach()
endif()
px4_join(OUT serial_ports LIST "${serial_ports}" GLUE ",")
add_custom_target(${OUT}
COMMAND ${PYTHON_EXECUTABLE}
${PX4_SOURCE_DIR}/Tools/px_uploader.py --port ${serial_ports} ${BUNDLE}
DEPENDS ${BUNDLE}
WORKING_DIRECTORY ${PX4_BINARY_DIR}
COMMENT "uploading ${BUNDLE}"
VERBATIM
USES_TERMINAL
)
endfunction()
function(px4_add_adb_push)
px4_parse_function_args(
NAME px4_add_upload
ONE_VALUE OS BOARD OUT DEST
MULTI_VALUE FILES DEPENDS
REQUIRED OS BOARD OUT FILES DEPENDS DEST
ARGN ${ARGN})
add_custom_target(${OUT}
COMMAND ${PX4_SOURCE_DIR}/Tools/adb_upload.sh ${FILES} ${DEST}
DEPENDS ${DEPENDS}
WORKING_DIRECTORY ${PX4_BINARY_DIR}
COMMENT "uploading ${BUNDLE}"
VERBATIM
USES_TERMINAL
)
endfunction()
function(px4_add_adb_push_to_bebop)
px4_parse_function_args(
NAME px4_add_upload_to_bebop
ONE_VALUE OS BOARD OUT DEST
MULTI_VALUE FILES DEPENDS
REQUIRED OS BOARD OUT FILES DEPENDS DEST
ARGN ${ARGN})
add_custom_target(${OUT}
COMMAND ${PX4_SOURCE_DIR}/Tools/adb_upload_to_bebop.sh ${FILES} ${DEST}
DEPENDS ${DEPENDS}
WORKING_DIRECTORY ${PX4_BINARY_DIR}
COMMENT "uploading ${BUNDLE}"
VERBATIM
USES_TERMINAL
)
endfunction()
function(px4_add_scp_push)
px4_parse_function_args(
NAME px4_add_upload
ONE_VALUE OS BOARD OUT DEST
MULTI_VALUE FILES DEPENDS
REQUIRED OS BOARD OUT FILES DEPENDS DEST
ARGN ${ARGN})
add_custom_target(${OUT}
COMMAND ${PX4_SOURCE_DIR}/Tools/scp_upload.sh ${FILES} ${DEST}
DEPENDS ${DEPENDS}
WORKING_DIRECTORY ${PX4_BINARY_DIR}
COMMENT "uploading ${BUNDLE}"
VERBATIM
USES_TERMINAL
)
endfunction()
function(px4_add_upload_aero)
px4_parse_function_args(
NAME px4_add_upload_aero
ONE_VALUE OS BOARD OUT BUNDLE
REQUIRED OS BOARD OUT BUNDLE
ARGN ${ARGN})
add_custom_target(${OUT}
COMMAND ${PX4_SOURCE_DIR}/Tools/aero_upload.sh ${BUNDLE}
DEPENDS ${BUNDLE}
WORKING_DIRECTORY ${PX4_BINARY_DIR}
COMMENT "uploading ${BUNDLE}"
VERBATIM
USES_TERMINAL
)
endfunction()

View File

@ -0,0 +1,94 @@
############################################################################
#
# Copyright (c) 2017 PX4 Development Team. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name PX4 nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
option(SANITIZE_ADDRESS "Enable AddressSanitizer" Off)
option(SANITIZE_MEMORY "Enable MemorySanitizer" Off)
option(SANITIZE_THREAD "Enable ThreadSanitizer" Off)
option(SANITIZE_UNDEFINED "Enable UndefinedBehaviorSanitizer" Off)
if (SANITIZE_ADDRESS)
message(STATUS "address sanitizer enabled")
# environment variables
# ASAN_OPTIONS=detect_stack_use_after_return=1
# ASAN_OPTIONS=check_initialization_order=1
add_compile_options(
-g3
-fno-omit-frame-pointer
-fsanitize=address
#-fsanitize-address-use-after-scope
)
elseif(SANITIZE_MEMORY)
message(STATUS "thread sanitizer enabled")
add_compile_options(
-g3
-fsanitize=memory
)
elseif(SANITIZE_THREAD)
message(STATUS "thread sanitizer enabled")
add_compile_options(
-g3
-fsanitize=thread
)
elseif(SANITIZE_UNDEFINED)
message(STATUS "undefined behaviour sanitizer enabled")
add_compile_options(
-g3
#-fsanitize=alignment
-fsanitize=bool
-fsanitize=bounds
-fsanitize=enum
#-fsanitize=float-cast-overflow
-fsanitize=float-divide-by-zero
#-fsanitize=function
-fsanitize=integer-divide-by-zero
-fsanitize=nonnull-attribute
-fsanitize=null
-fsanitize=object-size
-fsanitize=return
-fsanitize=returns-nonnull-attribute
-fsanitize=shift
-fsanitize=signed-integer-overflow
-fsanitize=unreachable
#-fsanitize=unsigned-integer-overflow
-fsanitize=vla-bound
-fsanitize=vptr
)
endif()

View File

@ -15,6 +15,8 @@ gpssim start
measairspeedsim start
pwm_out_sim mode_pwm
help
ver all
list_tasks
@ -30,4 +32,6 @@ tests @test_name@
dataman status
dataman stop
perf
shutdown

View File

@ -1,3 +1,6 @@
include(common/px4_upload)
px4_nuttx_generate_builtin_commands(
OUT builtin_commands.c
MODULE_LIST

View File

@ -1,3 +1,5 @@
include (common/px4_upload)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
px4_posix_generate_builtin_commands(

View File

@ -39,7 +39,7 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
endif()
foreach(test_name ${tests})
configure_file(${PX4_SOURCE_DIR}/posix-configs/SITL/init/test/test_template.in ${PX4_SOURCE_DIR}/posix-configs/SITL/init/test/${test_name}_generated)
configure_file(${PX4_SOURCE_DIR}/posix-configs/SITL/init/test/test_template.in ${PX4_SOURCE_DIR}/posix-configs/SITL/init/test/test_${test_name}_generated)
add_test(NAME ${test_name}
COMMAND ${PX4_SOURCE_DIR}/Tools/sitl_run.sh
@ -47,7 +47,7 @@ foreach(test_name ${tests})
posix-configs/SITL/init/test
none
none
${test_name}_generated
test_${test_name}_generated
${PX4_SOURCE_DIR}
${PX4_BINARY_DIR}
WORKING_DIRECTORY ${SITL_WORKING_DIR})
@ -64,6 +64,10 @@ add_custom_target(test_results
WORKING_DIRECTORY ${PX4_BINARY_DIR})
set_target_properties(test_results PROPERTIES EXCLUDE_FROM_ALL TRUE)
if (CMAKE_BUILD_TYPE STREQUAL Coverage)
setup_target_for_coverage(test_coverage ${CMAKE_CTEST_COMMAND} coverage.info "--output-on-failure -T Test")
endif()
add_custom_target(test_results_junit
COMMAND xsltproc ${PX4_SOURCE_DIR}/Tools/CTest2JUnit.xsl Testing/`head -n 1 < Testing/TAG`/Test.xml > JUnitTestResults.xml
COMMENT "Converting ctest output to junit xml"

View File

@ -1,4 +1,5 @@
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PX4_SOURCE_DIR}/cmake/cmake_hexagon")
include(common/px4_upload)
include(toolchain/Toolchain-qurt)
include(fastrpc)
include(qurt_lib)

View File

@ -50,8 +50,6 @@
#include <unistd.h>
#include <math.h>
#include <px4iofirmware/protocol.h>
#include "mixer.h"
#define debug(fmt, args...) do { } while(0)

View File

@ -52,7 +52,6 @@
#include <math.h>
#include <mathlib/math/Limits.hpp>
#include <px4iofirmware/protocol.h>
#include <drivers/drv_pwm_output.h>
#include "mixer.h"

View File

@ -53,7 +53,7 @@ add_definitions(
-DHW_VERSION_MINOR=${uavcanblid_hw_version_minor}
)
px4_share_subdirectory(RELDIR ../uavcan/libuavcan ARGS EXCLUDE_FROM_ALL)
add_subdirectory(../uavcan/libuavcan uavcanesc_libuavcan)
add_dependencies(uavcan platforms__nuttx)
include_directories(../../drivers/bootloaders/include)
@ -71,12 +71,12 @@ px4_add_module(
-Wno-deprecated-declarations
-O3
SRCS
uavcanesc_main.cpp
indication_controller.cpp
led.cpp
uavcanesc_params.c
../systemlib/flashparams/flashparams.c
../systemlib/flashparams/flashfs.c
uavcanesc_main.cpp
indication_controller.cpp
led.cpp
uavcanesc_params.c
../systemlib/flashparams/flashparams.c
../systemlib/flashparams/flashfs.c
DEPENDS
platforms__common

View File

@ -53,7 +53,7 @@ add_definitions(
-DHW_VERSION_MINOR=${uavcanblid_hw_version_minor}
)
px4_share_subdirectory(RELDIR ../uavcan/libuavcan ARGS EXCLUDE_FROM_ALL)
add_subdirectory(../uavcan/libuavcan uavcannode_libuavcan)
add_dependencies(uavcan platforms__nuttx)
include_directories(../../drivers/bootloaders/include)
@ -72,11 +72,11 @@ px4_add_module(
-O3
SRCS
uavcannode_main.cpp
indication_controller.cpp
sim_controller.cpp
led.cpp
resources.cpp
uavcannode_params.c
indication_controller.cpp
sim_controller.cpp
led.cpp
resources.cpp
uavcannode_params.c
DEPENDS
platforms__common