############################################################################ # # 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. # ############################################################################ #============================================================================= # CMAKE CODING STANDARD FOR PX4 # # Structure # --------------------------------------------------------------------------- # # * Common functions should be included in px_base.cmake. # # * OS/ board specific fucntions should be include in # px_impl_${PX4_PLATFORM}.cmake or px4_impl_${PX4_PLATFORM}_${PX4_BOARD}.cmake. # # 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. # # * For else, endif, endfunction, etc, never put the name of the statement # # Functions/Macros # --------------------------------------------------------------------------- # # * Use px4_parse_function_args to parse functions and check for required # arguments. Unless there is only one argument in the function and it is clear. # # * 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 # reuse functions. # # Included CMake Files # --------------------------------------------------------------------------- # # * All variables in config files must have the prefix "config_". # # * Never set global variables in an included cmake file, # 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 # are being created. # # * Setting a global variable in a CMakeLists.txt file is ok, because # each CMakeLists.txt file has scope in the current directory and all # subdirectories, so it is not truly global. # # * 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 "${PX4_PLATFORM}" STREQUAL "posix", # instead type ${PX4_PLATFORM} STREQUAL "posix". This will throw an # error when ${PX4_PLATFORM} is not defined instead of silently # evaluating to false. # #============================================================================= cmake_minimum_required(VERSION 3.2 FATAL_ERROR) set(PX4_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") set(PX4_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}") list(APPEND CMAKE_MODULE_PATH ${PX4_SOURCE_DIR}/cmake) #============================================================================= # git # include(px4_git) execute_process( COMMAND git describe --always --tags OUTPUT_VARIABLE PX4_GIT_TAG OUTPUT_STRIP_TRAILING_WHITESPACE WORKING_DIRECTORY ${PX4_SOURCE_DIR} ) define_property(GLOBAL PROPERTY PX4_MODULE_LIBRARIES BRIEF_DOCS "PX4 module libs" FULL_DOCS "List of all PX4 module libraries" ) define_property(GLOBAL PROPERTY PX4_MODULE_PATHS BRIEF_DOCS "PX4 module paths" FULL_DOCS "List of paths to all PX4 modules" ) #============================================================================= # configuration # set(CONFIG "px4_sitl_default" CACHE STRING "desired configuration") include(px4_add_module) set(config_module_list) set(config_df_driver_list) # find PX4 config # look for in tree board config that matches CONFIG input if(NOT PX4_CONFIG_FILE) file(GLOB_RECURSE board_configs RELATIVE "${PX4_SOURCE_DIR}/boards" "boards/*.cmake" ) set(PX4_CONFIGS ${board_configs} CACHE STRING "PX4 board configs" FORCE) foreach(filename ${board_configs}) # parse input CONFIG into components to match with existing in tree configs # the platform prefix (eg nuttx_) is historical, and removed if present string(REPLACE ".cmake" "" filename_stripped ${filename}) string(REPLACE "/" ";" config ${filename_stripped}) list(LENGTH config config_len) if(${config_len} EQUAL 3) list(GET config 0 vendor) list(GET config 1 model) list(GET config 2 label) set(board "${vendor}${model}") # __