2015-09-07 21:37:45 -03:00
|
|
|
############################################################################
|
|
|
|
#
|
|
|
|
# Copyright (c) 2015 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.
|
|
|
|
#
|
|
|
|
############################################################################
|
|
|
|
|
|
|
|
#=============================================================================
|
|
|
|
# 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
|
2015-09-08 01:30:35 -03:00
|
|
|
# px_impl_${OS}.cmake or px4_impl_${OS}_${BOARD}.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.
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# * Avoid use of global variables in functions. Functions in a nested
|
|
|
|
# scope may use global variables, but this makes it difficult to
|
|
|
|
# resuse functions.
|
|
|
|
#
|
|
|
|
# Included CMake Files
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# * 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
|
|
|
|
# subdirecties, so it is not truly global.
|
|
|
|
#
|
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.
|
|
|
|
# Don't do "${OS}" STREQUAL "posix",
|
|
|
|
# instead type ${OS} STREQUAL "posix". This will throw an
|
|
|
|
# error when ${OS} is not defined instead of silently
|
|
|
|
# evaluating to false.
|
|
|
|
#
|
|
|
|
#=============================================================================
|
|
|
|
|
|
|
|
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
|
2015-09-10 23:15:11 -03:00
|
|
|
|
|
|
|
#=============================================================================
|
2015-09-11 00:43:59 -03:00
|
|
|
# parameters
|
2015-09-10 23:15:11 -03:00
|
|
|
#
|
|
|
|
|
2015-09-11 00:43:59 -03:00
|
|
|
set(CONFIG "nuttx_px4fmu-v2_default" CACHE STRING "desired configuration")
|
|
|
|
file(GLOB_RECURSE configs RELATIVE cmake/configs "cmake/configs/*.cmake")
|
|
|
|
set_property(CACHE CONFIG PROPERTY STRINGS ${configs})
|
|
|
|
set(THREADS "4" CACHE STRING
|
|
|
|
"number of threads to use for external build processes")
|
2015-09-10 23:15:11 -03:00
|
|
|
|
2015-09-07 21:37:45 -03:00
|
|
|
#=============================================================================
|
2015-09-11 00:43:59 -03:00
|
|
|
# configuration
|
2015-09-07 21:37:45 -03:00
|
|
|
#
|
2015-09-11 00:43:59 -03:00
|
|
|
# must come before project to set toolchain
|
2015-09-07 21:37:45 -03:00
|
|
|
|
2015-09-11 00:43:59 -03:00
|
|
|
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
|
|
|
|
set(config_module "configs/${CONFIG}")
|
|
|
|
include(${config_module})
|
2015-09-08 05:17:54 -03:00
|
|
|
|
|
|
|
# require px4 module interface
|
2015-09-11 00:43:59 -03:00
|
|
|
set(px4_required_interface
|
2015-09-08 00:58:31 -03:00
|
|
|
px4_os_prebuild_targets
|
|
|
|
px4_os_add_flags
|
|
|
|
)
|
2015-09-11 00:43:59 -03:00
|
|
|
foreach(cmd ${px4_required_interface})
|
2015-09-08 00:58:31 -03:00
|
|
|
if(NOT COMMAND ${cmd})
|
2015-09-11 00:43:59 -03:00
|
|
|
message(FATAL_ERROR "${config_module} must implement ${cmd}")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
set(px4_required_config
|
|
|
|
config_module_list
|
|
|
|
)
|
|
|
|
foreach(conf ${px4_required_config})
|
2015-09-11 01:28:13 -03:00
|
|
|
if(NOT DEFINED ${conf})
|
2015-09-11 00:53:25 -03:00
|
|
|
message(FATAL_ERROR "cmake/${config_module} must define ${conf}")
|
2015-09-08 00:58:31 -03:00
|
|
|
endif()
|
|
|
|
endforeach()
|
2015-09-08 06:32:55 -03:00
|
|
|
|
2015-09-07 21:37:45 -03:00
|
|
|
#=============================================================================
|
2015-09-11 00:43:59 -03:00
|
|
|
# project definition
|
2015-09-07 21:37:45 -03:00
|
|
|
#
|
2015-09-11 00:43:59 -03:00
|
|
|
project(px4 CXX C ASM)
|
|
|
|
if (NOT ${CMAKE_VERSION} VERSION_LESS 3.0.0)
|
|
|
|
cmake_policy(SET CMP0045 NEW) # error on non-existent target in get prop
|
|
|
|
cmake_policy(SET CMP0046 NEW) # no non-existent targets as dependencies
|
|
|
|
endif()
|
2015-09-07 21:37:45 -03:00
|
|
|
|
2015-09-11 01:31:36 -03:00
|
|
|
set(version_major 1)
|
|
|
|
set(version_minor 0)
|
|
|
|
set(version_patch 1)
|
2015-09-11 00:43:59 -03:00
|
|
|
set(version "${version_major}.${version_minor}.${version_patch}")
|
|
|
|
set(package-contact "px4users@googlegroups.com")
|
2015-09-07 21:37:45 -03:00
|
|
|
|
2015-09-11 00:43:59 -03:00
|
|
|
string(REPLACE "_" ";" config_args ${CONFIG})
|
|
|
|
list(GET config_args 0 OS)
|
|
|
|
list(GET config_args 1 BOARD)
|
|
|
|
list(GET config_args 2 LABEL)
|
2015-09-07 21:37:45 -03:00
|
|
|
|
2015-09-11 00:43:59 -03:00
|
|
|
message(STATUS "TARGET: OS(${OS})-BOARD(${BOARD})-LABEL(${LABEL})")
|
2015-09-07 21:37:45 -03:00
|
|
|
|
2015-09-11 00:43:59 -03:00
|
|
|
#=============================================================================
|
2015-09-11 01:15:33 -03:00
|
|
|
# programs
|
2015-09-11 00:43:59 -03:00
|
|
|
#
|
2015-09-11 01:15:33 -03:00
|
|
|
find_package(PythonInterp REQUIRED)
|
2015-09-07 21:37:45 -03:00
|
|
|
|
2015-09-11 00:43:59 -03:00
|
|
|
#=============================================================================
|
2015-09-11 01:15:33 -03:00
|
|
|
# cmake modules
|
2015-09-11 00:43:59 -03:00
|
|
|
#
|
2015-09-11 01:15:33 -03:00
|
|
|
enable_testing()
|
2015-09-07 21:37:45 -03:00
|
|
|
|
|
|
|
#=============================================================================
|
|
|
|
# check required toolchain variables
|
|
|
|
#
|
2015-09-11 00:43:59 -03:00
|
|
|
set(required_variables
|
|
|
|
CMAKE_C_COMPILER_ID
|
|
|
|
)
|
|
|
|
foreach(var ${required_variables})
|
2015-09-07 21:37:45 -03:00
|
|
|
if (NOT ${var})
|
2015-09-11 00:43:59 -03:00
|
|
|
message(FATAL_ERROR "Toolchain/config must define ${var}")
|
2015-09-07 21:37:45 -03:00
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
#=============================================================================
|
|
|
|
# git
|
|
|
|
#
|
|
|
|
px4_add_git_submodule(TARGET git_genmsg PATH "Tools/genmsg")
|
|
|
|
px4_add_git_submodule(TARGET git_gencpp PATH "Tools/gencpp")
|
|
|
|
px4_add_git_submodule(TARGET git_mavlink PATH "mavlink/include/mavlink/v1.0")
|
|
|
|
px4_add_git_submodule(TARGET git_gtest PATH "unittets/gtest")
|
2015-09-10 14:57:54 -03:00
|
|
|
px4_add_git_submodule(TARGET git_uavcan PATH "src/lib/uavcan")
|
2015-09-10 15:18:30 -03:00
|
|
|
px4_add_git_submodule(TARGET git_eigen PATH "src/lib/eigen")
|
|
|
|
px4_add_git_submodule(TARGET git_nuttx PATH "NuttX")
|
|
|
|
px4_add_git_submodule(TARGET git_eigen32 PATH "src/lib/eigen-3.2")
|
|
|
|
px4_add_git_submodule(TARGET git_dspal PATH "src/lib/dspal")
|
|
|
|
|
2015-09-07 21:37:45 -03:00
|
|
|
add_custom_target(submodule_clean
|
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
|
|
COMMAND git submodule deinit -f .
|
|
|
|
COMMAND rm -rf .git/modules/*
|
|
|
|
)
|
|
|
|
|
|
|
|
#=============================================================================
|
|
|
|
# external libraries
|
|
|
|
#
|
2015-09-08 00:58:31 -03:00
|
|
|
px4_os_prebuild_targets(OUT prebuild_targets
|
|
|
|
BOARD ${BOARD}
|
|
|
|
THREADS ${THREADS})
|
2014-11-03 02:41:05 -04:00
|
|
|
|
2015-09-07 21:37:45 -03:00
|
|
|
#=============================================================================
|
|
|
|
# build flags
|
|
|
|
#
|
2015-09-08 00:58:31 -03:00
|
|
|
px4_os_add_flags(
|
|
|
|
BOARD ${BOARD}
|
2015-09-07 21:37:45 -03:00
|
|
|
C_FLAGS c_flags
|
|
|
|
CXX_FLAGS cxx_flags
|
|
|
|
EXE_LINKER_FLAGS exe_linker_flags
|
|
|
|
INCLUDE_DIRS include_dirs
|
|
|
|
LINK_DIRS link_dirs
|
|
|
|
DEFINITIONS definitions)
|
2015-09-08 05:20:48 -03:00
|
|
|
|
2015-09-07 21:37:45 -03:00
|
|
|
px4_join(OUT CMAKE_EXE_LINKER_FLAGS LIST "${exe_linker_flags}" GLUE " ")
|
|
|
|
px4_join(OUT CMAKE_C_FLAGS LIST "${c_flags}" GLUE " ")
|
|
|
|
px4_join(OUT CMAKE_CXX_FLAGS LIST "${cxx_flags}" GLUE " ")
|
2015-09-08 00:58:31 -03:00
|
|
|
|
2015-09-07 21:37:45 -03:00
|
|
|
include_directories(${include_dirs})
|
|
|
|
link_directories(${link_dirs})
|
|
|
|
add_definitions(${definitions})
|
|
|
|
|
|
|
|
#=============================================================================
|
2015-09-11 06:33:42 -03:00
|
|
|
# source code generation
|
2015-09-07 21:37:45 -03:00
|
|
|
#
|
|
|
|
file(GLOB_RECURSE msg_files msg/*.msg)
|
|
|
|
px4_generate_messages(TARGET msg_gen
|
|
|
|
MSG_FILES ${msg_files}
|
|
|
|
OS ${OS}
|
|
|
|
DEPENDS git_genmsg git_gencpp
|
|
|
|
)
|
|
|
|
|
|
|
|
#=============================================================================
|
|
|
|
# subdirectories
|
|
|
|
#
|
2015-09-10 00:00:58 -03:00
|
|
|
set(module_libraries)
|
2015-09-11 00:43:59 -03:00
|
|
|
foreach(module ${config_module_list})
|
2015-09-10 00:00:58 -03:00
|
|
|
add_subdirectory(src/${module})
|
|
|
|
px4_mangle_name(${module} mangled_name)
|
|
|
|
list(APPEND module_libraries ${mangled_name})
|
2015-09-10 22:15:55 -03:00
|
|
|
#message(STATUS "adding module: ${module}")
|
2015-09-10 00:00:58 -03:00
|
|
|
endforeach()
|
2015-09-07 21:37:45 -03:00
|
|
|
|
2015-09-10 00:00:58 -03:00
|
|
|
add_subdirectory(src/firmware/${OS})
|
2015-09-08 16:18:59 -03:00
|
|
|
|
2015-09-08 22:39:51 -03:00
|
|
|
#=============================================================================
|
|
|
|
# generate git version
|
|
|
|
#
|
|
|
|
px4_create_git_hash_header(HEADER ${CMAKE_BINARY_DIR}/build_git_version.h)
|
|
|
|
|
2015-09-07 21:37:45 -03:00
|
|
|
#=============================================================================
|
|
|
|
# packaging
|
|
|
|
#
|
|
|
|
# Important to having packaging at end of cmake file.
|
|
|
|
#
|
|
|
|
set(CPACK_PACKAGE_VERSION ${version})
|
|
|
|
set(CPACK_PACKAGE_CONTACT ${package_contact})
|
2015-09-10 22:54:58 -03:00
|
|
|
set(CPACK_GENERATOR "ZIP")
|
|
|
|
set(CPACK_SOURCE_GENERATOR "ZIP")
|
2015-09-07 21:37:45 -03:00
|
|
|
include(CPack)
|
|
|
|
|
|
|
|
# vim: set noet fenc=utf-8 ff=unix ft=cmake :
|