2015-09-07 21:37:45 -03:00
|
|
|
############################################################################
|
|
|
|
#
|
2022-12-09 00:03:44 -04:00
|
|
|
# Copyright (c) 2017 - 2022 PX4 Development Team. All rights reserved.
|
2015-09-07 21:37:45 -03:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
############################################################################
|
|
|
|
|
|
|
|
#=============================================================================
|
|
|
|
# CMAKE CODING STANDARD FOR PX4
|
|
|
|
#
|
|
|
|
# Structure
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
#
|
2015-09-08 01:30:35 -03:00
|
|
|
# * Common functions should be included in px_base.cmake.
|
2015-09-07 21:37:45 -03:00
|
|
|
#
|
|
|
|
# * OS/ board specific fucntions should be include in
|
2021-11-15 19:47:38 -04:00
|
|
|
# px_impl_${PX4_PLATFORM}.cmake
|
2015-09-07 21:37:45 -03:00
|
|
|
#
|
|
|
|
# Formatting
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# * Use hard indents to match the px4 source code.
|
|
|
|
#
|
|
|
|
# * All function and script arguments are upper case.
|
|
|
|
#
|
|
|
|
# * All local variables are lower case.
|
|
|
|
#
|
|
|
|
# * All cmake functions are lowercase.
|
|
|
|
#
|
2015-09-12 16:47:23 -03:00
|
|
|
# * For else, endif, endfunction, etc, never put the name of the statement
|
|
|
|
#
|
2015-09-07 21:37:45 -03:00
|
|
|
# Functions/Macros
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
#
|
2015-09-08 00:58:31 -03:00
|
|
|
# * Use px4_parse_function_args to parse functions and check for required
|
2015-09-10 00:00:58 -03:00
|
|
|
# arguments. Unless there is only one argument in the function and it is clear.
|
2015-09-08 00:58:31 -03:00
|
|
|
#
|
2015-09-07 21:37:45 -03:00
|
|
|
# * Never use macros. They allow overwriting global variables and this
|
|
|
|
# makes variable declarations hard to locate.
|
|
|
|
#
|
|
|
|
# * If a target from add_custom_* is set in a function, explicitly pass it
|
|
|
|
# as an output argument so that the target name is clear to the user.
|
|
|
|
#
|
2016-01-19 03:16:31 -04:00
|
|
|
# * Avoid use of global variables in functions. Functions in a nested
|
2015-09-07 21:37:45 -03:00
|
|
|
# scope may use global variables, but this makes it difficult to
|
2018-04-11 16:10:51 -03:00
|
|
|
# reuse functions.
|
2015-09-07 21:37:45 -03:00
|
|
|
#
|
|
|
|
# Included CMake Files
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
#
|
2015-09-12 06:26:31 -03:00
|
|
|
# * All variables in config files must have the prefix "config_".
|
|
|
|
#
|
2015-09-07 21:37:45 -03:00
|
|
|
# * Never set global variables in an included cmake file,
|
2015-09-11 00:53:25 -03:00
|
|
|
# you may only define functions. This excludes config and Toolchain files.
|
|
|
|
# This makes it clear to the user when variables are being set or targets
|
2015-09-07 21:37:45 -03:00
|
|
|
# are being created.
|
|
|
|
#
|
2015-09-10 00:18:53 -03:00
|
|
|
# * Setting a global variable in a CMakeLists.txt file is ok, because
|
|
|
|
# each CMakeLists.txt file has scope in the current directory and all
|
2017-06-01 09:47:33 -03:00
|
|
|
# subdirectories, so it is not truly global.
|
2015-09-10 00:18:53 -03:00
|
|
|
#
|
2015-09-07 21:37:45 -03:00
|
|
|
# * All toolchain files should be included in the cmake
|
|
|
|
# directory and named Toolchain-"name".cmake.
|
|
|
|
#
|
|
|
|
# Misc
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# * If referencing a string variable, don't put it in quotes.
|
2018-11-16 13:52:37 -04:00
|
|
|
# Don't do "${PX4_PLATFORM}" STREQUAL "posix",
|
|
|
|
# instead type ${PX4_PLATFORM} STREQUAL "posix". This will throw an
|
|
|
|
# error when ${PX4_PLATFORM} is not defined instead of silently
|
2015-09-07 21:37:45 -03:00
|
|
|
# evaluating to false.
|
|
|
|
#
|
|
|
|
#=============================================================================
|
|
|
|
|
2022-02-24 13:41:42 -04:00
|
|
|
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
|
2015-09-10 23:15:11 -03:00
|
|
|
|
2021-11-15 19:47:38 -04:00
|
|
|
set(PX4_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CACHE FILEPATH "PX4 source directory" FORCE)
|
|
|
|
set(PX4_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}" CACHE FILEPATH "PX4 binary directory" FORCE)
|
2016-08-18 16:37:23 -03:00
|
|
|
|
2018-11-16 13:52:37 -04:00
|
|
|
list(APPEND CMAKE_MODULE_PATH ${PX4_SOURCE_DIR}/cmake)
|
2019-09-15 14:49:51 -03:00
|
|
|
include(px4_parse_function_args)
|
2017-12-06 21:40:48 -04:00
|
|
|
|
|
|
|
#=============================================================================
|
|
|
|
# git
|
|
|
|
#
|
2018-11-16 13:52:37 -04:00
|
|
|
include(px4_git)
|
2017-12-06 21:40:48 -04:00
|
|
|
|
|
|
|
execute_process(
|
2021-02-18 08:22:36 -04:00
|
|
|
COMMAND git describe --exclude ext/* --always --tags
|
2018-06-21 12:41:03 -03:00
|
|
|
OUTPUT_VARIABLE PX4_GIT_TAG
|
2017-12-06 21:40:48 -04:00
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
WORKING_DIRECTORY ${PX4_SOURCE_DIR}
|
|
|
|
)
|
2023-01-17 12:20:51 -04:00
|
|
|
|
|
|
|
# git describe to X.Y.Z version
|
|
|
|
string(REPLACE "." ";" VERSION_LIST ${PX4_GIT_TAG})
|
|
|
|
|
|
|
|
# major version
|
|
|
|
list(GET VERSION_LIST 0 PX4_VERSION_MAJOR)
|
|
|
|
string(REPLACE "v" "" PX4_VERSION_MAJOR ${PX4_VERSION_MAJOR})
|
|
|
|
# minor version
|
|
|
|
list(GET VERSION_LIST 1 PX4_VERSION_MINOR)
|
|
|
|
# patch version
|
|
|
|
list(GET VERSION_LIST 2 PX4_VERSION_PATCH)
|
|
|
|
string(REPLACE "-" ";" PX4_VERSION_PATCH ${PX4_VERSION_PATCH})
|
|
|
|
list(GET PX4_VERSION_PATCH 0 PX4_VERSION_PATCH)
|
|
|
|
|
|
|
|
message(STATUS "PX4 version: ${PX4_GIT_TAG} (${PX4_VERSION_MAJOR}.${PX4_VERSION_MINOR}.${PX4_VERSION_PATCH})")
|
2017-12-06 21:40:48 -04:00
|
|
|
|
2018-04-11 16:10:51 -03:00
|
|
|
define_property(GLOBAL PROPERTY PX4_MODULE_LIBRARIES
|
|
|
|
BRIEF_DOCS "PX4 module libs"
|
2017-08-29 18:22:05 -03:00
|
|
|
FULL_DOCS "List of all PX4 module libraries"
|
|
|
|
)
|
2016-08-25 16:47:45 -03:00
|
|
|
|
2020-12-30 09:57:55 -04:00
|
|
|
define_property(GLOBAL PROPERTY PX4_KERNEL_MODULE_LIBRARIES
|
|
|
|
BRIEF_DOCS "PX4 kernel side module libs"
|
|
|
|
FULL_DOCS "List of all PX4 kernel module libraries"
|
|
|
|
)
|
|
|
|
|
2018-04-11 16:10:51 -03:00
|
|
|
define_property(GLOBAL PROPERTY PX4_MODULE_PATHS
|
|
|
|
BRIEF_DOCS "PX4 module paths"
|
|
|
|
FULL_DOCS "List of paths to all PX4 modules"
|
|
|
|
)
|
2020-11-09 06:51:27 -04:00
|
|
|
define_property(GLOBAL PROPERTY PX4_SRC_FILES
|
|
|
|
BRIEF_DOCS "src files from all PX4 modules & libs"
|
|
|
|
FULL_DOCS "SRC files from px4_add_{module,library}"
|
|
|
|
)
|
2018-04-11 16:10:51 -03:00
|
|
|
|
2015-09-10 23:15:11 -03:00
|
|
|
#=============================================================================
|
2017-06-01 09:47:33 -03:00
|
|
|
# configuration
|
2015-09-10 23:15:11 -03:00
|
|
|
#
|
|
|
|
|
2018-11-23 12:26:41 -04:00
|
|
|
include(px4_add_module)
|
2018-11-16 13:52:37 -04:00
|
|
|
set(config_module_list)
|
2020-12-30 09:57:55 -04:00
|
|
|
set(config_kernel_list)
|
2017-01-29 16:32:18 -04:00
|
|
|
|
2021-08-21 12:29:58 -03:00
|
|
|
# Find Python
|
2022-12-09 00:03:44 -04:00
|
|
|
find_package(PythonInterp 3)
|
|
|
|
# We have a custom error message to tell users how to install python3.
|
|
|
|
if(NOT PYTHONINTERP_FOUND)
|
|
|
|
message(FATAL_ERROR "Python 3 not found. Please install Python 3:\n"
|
|
|
|
" Ubuntu: sudo apt install python3 python3-dev python3-pip\n"
|
|
|
|
" macOS: brew install python")
|
2021-08-21 12:29:58 -03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
option(PYTHON_COVERAGE "Python code coverage" OFF)
|
|
|
|
if(PYTHON_COVERAGE)
|
|
|
|
message(STATUS "python coverage enabled")
|
|
|
|
set(PYTHON_EXECUTABLE coverage run -p)
|
|
|
|
endif()
|
|
|
|
|
2019-09-15 14:37:55 -03:00
|
|
|
include(px4_config)
|
2021-08-04 12:09:21 -03:00
|
|
|
include(kconfig)
|
2018-11-23 13:39:44 -04:00
|
|
|
message(STATUS "PX4 config: ${PX4_CONFIG}")
|
2018-11-16 13:52:37 -04:00
|
|
|
message(STATUS "PX4 platform: ${PX4_PLATFORM}")
|
|
|
|
|
2022-07-19 10:28:16 -03:00
|
|
|
if($ENV{CLION_IDE})
|
|
|
|
# CLion automatically executes some compiler commands after configuring the
|
|
|
|
# project. This would fail on NuttX, as visibility.h tries to (indirectly)
|
|
|
|
# include nuttx/config.h, which at that point does not exist yet
|
|
|
|
add_definitions(-DPX4_DISABLE_GCC_POISON)
|
|
|
|
endif()
|
2021-03-11 14:39:01 -04:00
|
|
|
|
2019-11-16 19:30:52 -04:00
|
|
|
if(${PX4_PLATFORM} STREQUAL "posix")
|
|
|
|
if(ENABLE_LOCKSTEP_SCHEDULER)
|
|
|
|
add_definitions(-DENABLE_LOCKSTEP_SCHEDULER)
|
|
|
|
message(STATUS "PX4 lockstep: enabled")
|
|
|
|
else()
|
|
|
|
message(STATUS "PX4 lockstep: disabled")
|
|
|
|
endif()
|
2018-12-09 07:22:49 -04:00
|
|
|
endif()
|
|
|
|
|
2018-11-16 13:52:37 -04:00
|
|
|
# external modules
|
2016-09-07 09:05:22 -03:00
|
|
|
set(EXTERNAL_MODULES_LOCATION "" CACHE STRING "External modules source location")
|
2015-09-10 23:15:11 -03:00
|
|
|
|
2019-11-16 11:08:04 -04:00
|
|
|
if(NOT EXTERNAL_MODULES_LOCATION STREQUAL "")
|
2017-02-24 10:06:38 -04:00
|
|
|
get_filename_component(EXTERNAL_MODULES_LOCATION "${EXTERNAL_MODULES_LOCATION}" ABSOLUTE)
|
|
|
|
endif()
|
|
|
|
|
2018-08-27 06:35:11 -03:00
|
|
|
set_property(GLOBAL PROPERTY PX4_MODULE_CONFIG_FILES)
|
|
|
|
|
2018-11-16 13:52:37 -04:00
|
|
|
include(platforms/${PX4_PLATFORM}/cmake/px4_impl_os.cmake)
|
|
|
|
list(APPEND CMAKE_MODULE_PATH ${PX4_SOURCE_DIR}/platforms/${PX4_PLATFORM}/cmake)
|
2017-06-01 09:47:33 -03:00
|
|
|
|
2019-01-30 11:54:53 -04:00
|
|
|
if(EXISTS "${PX4_SOURCE_DIR}/platforms/${PX4_PLATFORM}/cmake/init.cmake")
|
|
|
|
include(init)
|
|
|
|
endif()
|
|
|
|
|
2022-12-09 00:03:44 -04:00
|
|
|
#=============================================================================
|
|
|
|
# project definition
|
|
|
|
#
|
|
|
|
project(px4 CXX C ASM)
|
|
|
|
|
2018-04-11 16:10:51 -03:00
|
|
|
# CMake build type (Debug Release RelWithDebInfo MinSizeRel Coverage)
|
2019-11-16 11:08:04 -04:00
|
|
|
if(NOT CMAKE_BUILD_TYPE)
|
|
|
|
if(${PX4_PLATFORM} STREQUAL "nuttx")
|
2017-06-01 09:47:33 -03:00
|
|
|
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()
|
|
|
|
|
2020-06-03 19:11:32 -03:00
|
|
|
if((CMAKE_BUILD_TYPE STREQUAL "Debug") OR (CMAKE_BUILD_TYPE STREQUAL "Coverage"))
|
|
|
|
set(MAX_CUSTOM_OPT_LEVEL -O0)
|
|
|
|
elseif(CMAKE_BUILD_TYPE MATCHES "Sanitizer")
|
|
|
|
set(MAX_CUSTOM_OPT_LEVEL -O1)
|
2021-05-04 17:57:16 -03:00
|
|
|
elseif(CMAKE_BUILD_TYPE MATCHES "Release")
|
|
|
|
set(MAX_CUSTOM_OPT_LEVEL -O3)
|
2020-06-03 19:11:32 -03:00
|
|
|
else()
|
|
|
|
if(px4_constrained_flash_build)
|
|
|
|
set(MAX_CUSTOM_OPT_LEVEL -Os)
|
|
|
|
else()
|
|
|
|
set(MAX_CUSTOM_OPT_LEVEL -O2)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2018-09-23 17:52:09 -03:00
|
|
|
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug;Release;RelWithDebInfo;MinSizeRel;Coverage;AddressSanitizer;UndefinedBehaviorSanitizer")
|
2018-11-16 13:52:37 -04:00
|
|
|
message(STATUS "cmake build type: ${CMAKE_BUILD_TYPE}")
|
2017-11-21 21:22:48 -04:00
|
|
|
|
2022-02-24 13:41:42 -04:00
|
|
|
# Check if LTO option and check if toolchain supports it
|
|
|
|
if(LTO)
|
|
|
|
include(CheckIPOSupported)
|
|
|
|
check_ipo_supported()
|
|
|
|
message(AUTHOR_WARNING "LTO enabled: LTO is highly experimental and should not be used in production")
|
|
|
|
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
|
|
|
|
endif()
|
|
|
|
|
2017-11-21 21:22:48 -04:00
|
|
|
set(package-contact "px4users@googlegroups.com")
|
|
|
|
|
2020-01-21 22:49:10 -04:00
|
|
|
set(CMAKE_CXX_STANDARD 14)
|
2018-04-11 16:10:51 -03:00
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
2019-06-26 23:25:39 -03:00
|
|
|
set(CMAKE_C_STANDARD 11)
|
2018-04-11 16:10:51 -03:00
|
|
|
set(CMAKE_C_STANDARD_REQUIRED ON)
|
|
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
2016-12-12 18:53:12 -04:00
|
|
|
|
2022-12-09 00:03:44 -04:00
|
|
|
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})
|
2018-09-27 20:08:08 -03:00
|
|
|
|
2018-04-11 16:10:51 -03:00
|
|
|
#=============================================================================
|
2016-12-12 18:53:12 -04:00
|
|
|
|
2020-07-22 11:23:37 -03:00
|
|
|
# gold linker - use if available (posix only for now)
|
|
|
|
if(${PX4_PLATFORM} STREQUAL "posix")
|
|
|
|
include(CMakeDependentOption)
|
|
|
|
CMAKE_DEPENDENT_OPTION(USE_LD_GOLD
|
|
|
|
"Use GNU gold linker" ON
|
|
|
|
"NOT WIN32;NOT APPLE" OFF
|
|
|
|
)
|
|
|
|
|
|
|
|
if(USE_LD_GOLD)
|
|
|
|
execute_process(COMMAND ${CMAKE_C_COMPILER} -fuse-ld=gold -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION)
|
|
|
|
if("${LD_VERSION}" MATCHES "GNU gold")
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold")
|
|
|
|
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=gold")
|
|
|
|
else()
|
|
|
|
set(USE_LD_GOLD OFF)
|
|
|
|
endif()
|
2019-10-01 15:31:39 -03:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
#=============================================================================
|
|
|
|
|
2016-07-24 14:07:14 -03:00
|
|
|
# Setup install paths
|
2019-11-16 11:08:04 -04:00
|
|
|
if(${PX4_PLATFORM} STREQUAL "posix")
|
2018-11-23 13:39:44 -04:00
|
|
|
# This makes it possible to dynamically load code which depends on symbols
|
|
|
|
# inside the px4 executable.
|
|
|
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
|
|
set(CMAKE_ENABLE_EXPORTS ON)
|
|
|
|
|
2023-01-04 22:12:08 -04:00
|
|
|
if(CMAKE_BUILD_TYPE MATCHES "Coverage")
|
|
|
|
include(coverage)
|
|
|
|
endif()
|
|
|
|
|
2018-11-16 13:52:37 -04:00
|
|
|
include(sanitizers)
|
2018-04-11 16:10:51 -03:00
|
|
|
|
2017-11-21 21:22:48 -04:00
|
|
|
# Define GNU standard installation directories
|
|
|
|
include(GNUInstallDirs)
|
|
|
|
|
2017-08-29 18:22:05 -03:00
|
|
|
if (NOT CMAKE_INSTALL_PREFIX)
|
2016-07-24 14:07:14 -03:00
|
|
|
set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Install path prefix" FORCE)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2019-09-15 14:37:55 -03:00
|
|
|
include(ccache)
|
2017-01-14 22:59:45 -04:00
|
|
|
|
2019-08-23 11:04:22 -03:00
|
|
|
#=============================================================================
|
|
|
|
# get chip and chip manufacturer
|
|
|
|
#
|
|
|
|
px4_os_determine_build_chip()
|
|
|
|
if(NOT PX4_CHIP_MANUFACTURER)
|
|
|
|
message(FATAL_ERROR "px4_os_determine_build_chip() needs to set PX4_CHIP_MANUFACTURER")
|
|
|
|
endif()
|
|
|
|
if(NOT PX4_CHIP)
|
|
|
|
message(FATAL_ERROR "px4_os_determine_build_chip() needs to set PX4_CHIP")
|
|
|
|
endif()
|
|
|
|
|
2015-09-07 21:37:45 -03:00
|
|
|
#=============================================================================
|
|
|
|
# build flags
|
|
|
|
#
|
2018-11-23 13:39:44 -04:00
|
|
|
include(px4_add_common_flags)
|
|
|
|
px4_add_common_flags()
|
|
|
|
px4_os_add_flags()
|
2015-09-08 00:58:31 -03:00
|
|
|
|
2019-12-29 17:59:42 -04:00
|
|
|
#=============================================================================
|
|
|
|
# board cmake init (optional)
|
|
|
|
#
|
2020-01-05 15:03:57 -04:00
|
|
|
if(EXISTS ${PX4_BOARD_DIR}/cmake/init.cmake)
|
|
|
|
include(${PX4_BOARD_DIR}/cmake/init.cmake)
|
2019-12-29 17:59:42 -04:00
|
|
|
endif()
|
|
|
|
|
2015-09-07 21:37:45 -03:00
|
|
|
#=============================================================================
|
2017-06-05 16:24:10 -03:00
|
|
|
# message, and airframe generation
|
2015-09-07 21:37:45 -03:00
|
|
|
#
|
2018-11-16 13:52:37 -04:00
|
|
|
include(px4_metadata)
|
2017-06-01 09:47:33 -03:00
|
|
|
|
2018-04-11 16:10:51 -03:00
|
|
|
add_subdirectory(msg EXCLUDE_FROM_ALL)
|
2017-06-01 09:47:33 -03:00
|
|
|
|
2018-11-16 13:52:37 -04:00
|
|
|
px4_generate_airframes_xml(BOARD ${PX4_BOARD})
|
2017-06-01 09:47:33 -03:00
|
|
|
|
|
|
|
#=============================================================================
|
2015-10-03 15:51:12 -03:00
|
|
|
# external projects
|
|
|
|
#
|
2016-08-18 16:37:23 -03:00
|
|
|
set(ep_base ${PX4_BINARY_DIR}/external)
|
2015-10-03 15:51:12 -03:00
|
|
|
set_property(DIRECTORY PROPERTY EP_BASE ${ep_base})
|
|
|
|
|
|
|
|
# add external project install folders to build
|
2019-11-16 19:30:52 -04:00
|
|
|
# add the directories so cmake won't warn
|
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${ep_base})
|
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${ep_base}/Install)
|
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${ep_base}/Install/lib)
|
2015-10-03 15:51:12 -03:00
|
|
|
link_directories(${ep_base}/Install/lib)
|
2019-11-16 19:30:52 -04:00
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${ep_base}/Install/include)
|
2015-10-03 15:51:12 -03:00
|
|
|
include_directories(${ep_base}/Install/include)
|
|
|
|
|
2016-09-07 09:05:22 -03:00
|
|
|
#=============================================================================
|
|
|
|
# external modules
|
|
|
|
#
|
2017-11-21 01:44:23 -04:00
|
|
|
set(external_module_paths)
|
2017-06-01 09:47:33 -03:00
|
|
|
if (NOT EXTERNAL_MODULES_LOCATION STREQUAL "")
|
2016-09-07 09:05:22 -03:00
|
|
|
message(STATUS "External modules: ${EXTERNAL_MODULES_LOCATION}")
|
2017-11-21 01:44:23 -04:00
|
|
|
add_subdirectory("${EXTERNAL_MODULES_LOCATION}/src" external_modules)
|
2016-09-07 09:05:22 -03:00
|
|
|
|
|
|
|
foreach(external_module ${config_module_list_external})
|
2017-11-21 01:44:23 -04:00
|
|
|
add_subdirectory(${EXTERNAL_MODULES_LOCATION}/src/${external_module} external_modules/${external_module})
|
|
|
|
list(APPEND external_module_paths ${EXTERNAL_MODULES_LOCATION}/src/${external_module})
|
2016-09-07 09:05:22 -03:00
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
|
2019-03-02 13:18:00 -04:00
|
|
|
#=============================================================================
|
|
|
|
# Testing - Automatic unit and integration testing with CTest
|
|
|
|
#
|
|
|
|
|
2019-04-14 15:55:35 -03:00
|
|
|
# optionally enable cmake testing (supported only on posix)
|
|
|
|
option(CMAKE_TESTING "Configure test targets" OFF)
|
2019-12-26 13:36:24 -04:00
|
|
|
if(${PX4_CONFIG} STREQUAL "px4_sitl_test")
|
2019-05-09 17:31:24 -03:00
|
|
|
set(CMAKE_TESTING ON)
|
|
|
|
endif()
|
2019-04-14 15:55:35 -03:00
|
|
|
if(CMAKE_TESTING)
|
2019-04-23 06:22:14 -03:00
|
|
|
include(CTest) # sets BUILD_TESTING variable
|
2019-04-14 15:55:35 -03:00
|
|
|
endif()
|
2019-04-23 06:22:14 -03:00
|
|
|
|
|
|
|
# enable test filtering to run only specific tests with the ctest -R regex functionality
|
2019-04-23 04:36:03 -03:00
|
|
|
set(TESTFILTER "" CACHE STRING "Filter string for ctest to selectively only run specific tests (ctest -R)")
|
2019-03-02 13:18:00 -04:00
|
|
|
|
2019-04-23 06:22:14 -03:00
|
|
|
# if testing is enabled download and configure gtest
|
2019-03-02 13:18:00 -04:00
|
|
|
list(APPEND CMAKE_MODULE_PATH ${PX4_SOURCE_DIR}/cmake/gtest/)
|
|
|
|
include(px4_add_gtest)
|
2019-04-14 15:55:35 -03:00
|
|
|
if(BUILD_TESTING)
|
|
|
|
include(gtest)
|
2020-03-26 09:40:59 -03:00
|
|
|
|
|
|
|
add_custom_target(test_results
|
|
|
|
COMMAND GTEST_COLOR=1 ${CMAKE_CTEST_COMMAND} --output-on-failure -T Test -R ${TESTFILTER} USES_TERMINAL
|
|
|
|
DEPENDS
|
|
|
|
px4
|
|
|
|
examples__dyn_hello
|
|
|
|
USES_TERMINAL
|
|
|
|
COMMENT "Running tests"
|
|
|
|
WORKING_DIRECTORY ${PX4_BINARY_DIR})
|
|
|
|
set_target_properties(test_results PROPERTIES EXCLUDE_FROM_ALL TRUE)
|
2019-03-02 13:18:00 -04:00
|
|
|
endif()
|
|
|
|
|
2019-04-23 06:22:14 -03:00
|
|
|
|
2015-09-07 21:37:45 -03:00
|
|
|
#=============================================================================
|
|
|
|
# subdirectories
|
|
|
|
#
|
2018-04-11 16:10:51 -03:00
|
|
|
add_library(parameters_interface INTERFACE)
|
2021-11-09 02:54:10 -04:00
|
|
|
add_library(kernel_parameters_interface INTERFACE)
|
events: Move implementation of events::send() to lib/events
Events have a global, system-wide sequence number, which must be handled
atomically, (fetching and incrementing the sequence AND sending the event
to uORB must be atomic). Currently in FLAT mode, only one instance of this
sequence number exists, so it is OK to have it in px4_platform.
However, in PROTECTED mode px4_platform is instantiated both in kernel-
and user spaces, which makes two instances of this sequence number, which
causes problems in the mavlink event handling logic.
When mavlink receives and handles events, it expects that:
- The sequence numbers arrive in order (seq n is followed by n+1 etc)
- It increments by 1
- There is only one instance of the sequence number
In PROTECTED mode this is violated, as the kernel and user sequence
numbers run freely on their own. This patch fixes the issue by moving
the event backend to the kernel and by providing user access to it via
ioctl.
2023-09-21 04:33:05 -03:00
|
|
|
add_library(events_interface INTERFACE)
|
|
|
|
add_library(kernel_events_interface INTERFACE)
|
2018-11-23 12:26:41 -04:00
|
|
|
|
|
|
|
include(px4_add_library)
|
2018-04-11 16:10:51 -03:00
|
|
|
add_subdirectory(src/lib EXCLUDE_FROM_ALL)
|
2018-11-23 12:26:41 -04:00
|
|
|
|
2019-08-23 11:04:22 -03:00
|
|
|
add_subdirectory(platforms/${PX4_PLATFORM}/src/px4)
|
2019-08-27 05:57:38 -03:00
|
|
|
add_subdirectory(platforms EXCLUDE_FROM_ALL)
|
2018-01-15 16:34:18 -04:00
|
|
|
|
2018-12-01 13:42:48 -04:00
|
|
|
if(EXISTS "${PX4_BOARD_DIR}/CMakeLists.txt")
|
|
|
|
add_subdirectory(${PX4_BOARD_DIR})
|
|
|
|
endif()
|
|
|
|
|
2015-09-11 00:43:59 -03:00
|
|
|
foreach(module ${config_module_list})
|
2017-11-21 01:44:23 -04:00
|
|
|
add_subdirectory(src/${module})
|
2015-09-10 00:00:58 -03:00
|
|
|
endforeach()
|
2015-09-07 21:37:45 -03:00
|
|
|
|
2020-11-09 06:51:27 -04:00
|
|
|
# add events lib after modules and libs as it needs to know all source files (PX4_SRC_FILES)
|
|
|
|
add_subdirectory(src/lib/events EXCLUDE_FROM_ALL)
|
2021-11-05 07:53:35 -03:00
|
|
|
# metadata needs PX4_MODULE_CONFIG_FILES
|
|
|
|
add_subdirectory(src/lib/metadata EXCLUDE_FROM_ALL)
|
2020-11-09 06:51:27 -04:00
|
|
|
|
2018-04-11 16:10:51 -03:00
|
|
|
# must be the last module before firmware
|
|
|
|
add_subdirectory(src/lib/parameters EXCLUDE_FROM_ALL)
|
2021-11-09 02:54:10 -04:00
|
|
|
|
|
|
|
if(${PX4_PLATFORM} STREQUAL "nuttx" AND NOT CONFIG_BUILD_FLAT)
|
2022-12-09 00:03:44 -04:00
|
|
|
target_link_libraries(parameters_interface INTERFACE usr_parameters)
|
|
|
|
target_link_libraries(kernel_parameters_interface INTERFACE parameters)
|
events: Move implementation of events::send() to lib/events
Events have a global, system-wide sequence number, which must be handled
atomically, (fetching and incrementing the sequence AND sending the event
to uORB must be atomic). Currently in FLAT mode, only one instance of this
sequence number exists, so it is OK to have it in px4_platform.
However, in PROTECTED mode px4_platform is instantiated both in kernel-
and user spaces, which makes two instances of this sequence number, which
causes problems in the mavlink event handling logic.
When mavlink receives and handles events, it expects that:
- The sequence numbers arrive in order (seq n is followed by n+1 etc)
- It increments by 1
- There is only one instance of the sequence number
In PROTECTED mode this is violated, as the kernel and user sequence
numbers run freely on their own. This patch fixes the issue by moving
the event backend to the kernel and by providing user access to it via
ioctl.
2023-09-21 04:33:05 -03:00
|
|
|
target_link_libraries(events_interface INTERFACE usr_events)
|
|
|
|
target_link_libraries(kernel_events_interface INTERFACE events)
|
2021-11-09 02:54:10 -04:00
|
|
|
else()
|
2022-12-09 00:03:44 -04:00
|
|
|
target_link_libraries(parameters_interface INTERFACE parameters)
|
events: Move implementation of events::send() to lib/events
Events have a global, system-wide sequence number, which must be handled
atomically, (fetching and incrementing the sequence AND sending the event
to uORB must be atomic). Currently in FLAT mode, only one instance of this
sequence number exists, so it is OK to have it in px4_platform.
However, in PROTECTED mode px4_platform is instantiated both in kernel-
and user spaces, which makes two instances of this sequence number, which
causes problems in the mavlink event handling logic.
When mavlink receives and handles events, it expects that:
- The sequence numbers arrive in order (seq n is followed by n+1 etc)
- It increments by 1
- There is only one instance of the sequence number
In PROTECTED mode this is violated, as the kernel and user sequence
numbers run freely on their own. This patch fixes the issue by moving
the event backend to the kernel and by providing user access to it via
ioctl.
2023-09-21 04:33:05 -03:00
|
|
|
target_link_libraries(events_interface INTERFACE events)
|
2021-11-09 02:54:10 -04:00
|
|
|
endif()
|
2018-04-11 16:10:51 -03:00
|
|
|
|
|
|
|
# firmware added last to generate the builtin for included modules
|
2018-11-16 13:52:37 -04:00
|
|
|
add_subdirectory(platforms/${PX4_PLATFORM})
|
2017-12-11 07:01:09 -04:00
|
|
|
|
|
|
|
#=============================================================================
|
|
|
|
# uORB graph generation: add a custom target 'uorb_graph'
|
|
|
|
#
|
2018-11-16 13:52:37 -04:00
|
|
|
set(uorb_graph_config ${PX4_BOARD})
|
2017-12-11 07:01:09 -04:00
|
|
|
|
|
|
|
set(graph_module_list "")
|
|
|
|
foreach(module ${config_module_list})
|
|
|
|
set(graph_module_list "${graph_module_list}" "--src-path" "src/${module}")
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
add_custom_command(OUTPUT ${uorb_graph_config}
|
|
|
|
COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/uorb_graph/create.py
|
2021-07-28 17:07:12 -03:00
|
|
|
${graph_module_list} --src-path src/lib
|
|
|
|
--merge-depends
|
2017-12-11 07:01:09 -04:00
|
|
|
--exclude-path src/examples
|
2021-07-28 17:07:12 -03:00
|
|
|
--exclude-path src/lib/parameters # FIXME: enable & fix
|
2017-12-11 07:01:09 -04:00
|
|
|
--file ${PX4_SOURCE_DIR}/Tools/uorb_graph/graph_${uorb_graph_config}
|
|
|
|
WORKING_DIRECTORY ${PX4_SOURCE_DIR}
|
|
|
|
COMMENT "Generating uORB graph"
|
|
|
|
)
|
|
|
|
add_custom_target(uorb_graph DEPENDS ${uorb_graph_config})
|
|
|
|
|
2018-05-03 23:07:24 -03:00
|
|
|
|
2023-01-17 12:20:51 -04:00
|
|
|
include(bloaty)
|
|
|
|
|
|
|
|
|
2019-09-15 14:37:55 -03:00
|
|
|
include(doxygen)
|
|
|
|
include(metadata)
|
|
|
|
include(package)
|
2018-08-04 19:22:08 -03:00
|
|
|
|
2021-03-19 20:39:24 -03:00
|
|
|
# install python requirements using configured python
|
|
|
|
add_custom_target(install_python_requirements
|
|
|
|
COMMAND ${PYTHON_EXECUTABLE} -m pip install --requirement ${PX4_SOURCE_DIR}/Tools/setup/requirements.txt
|
|
|
|
DEPENDS ${PX4_SOURCE_DIR}/Tools/setup/requirements.txt
|
|
|
|
USES_TERMINAL
|
|
|
|
)
|
2022-12-09 00:03:44 -04:00
|
|
|
|
|
|
|
if(EXISTS "${PX4_SOURCE_DIR}/platforms/${PX4_PLATFORM}/cmake/finalize.cmake")
|
|
|
|
include(finalize)
|
|
|
|
endif()
|