############################################################################
#
# Copyright (c) 2019 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.
#
############################################################################
if ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" )
if ( CMAKE_CXX_COMPILER_VERSION VERSION_LESS_EQUAL 7 )
message ( FATAL_ERROR "GCC 7 or older no longer supported. https://docs.px4.io/master/en/dev_setup/dev_env.html" )
endif ( )
endif ( )
if ( NOT PX4_BOARD )
message ( FATAL_ERROR "PX4_BOARD must be set (eg px4_fmu-v2)" )
endif ( )
if ( NOT PX4_BINARY_DIR )
message ( FATAL_ERROR "PX4_BINARY_DIR must be set" )
endif ( )
if ( NOT PX4_BOARD_DIR )
message ( FATAL_ERROR "PX4_BOARD_DIR must be set" )
endif ( )
set ( NUTTX_CONFIG_DIR ${ PX4_BOARD_DIR } /nuttx-config CACHE FILEPATH "PX4 NuttX config" FORCE )
# NuttX defconfig
# cmake should trigger reconfigure if defconfig changes
set ( NUTTX_DEFCONFIG ${ NUTTX_CONFIG_DIR } / ${ NUTTX_CONFIG } /defconfig CACHE FILEPATH "path to defconfig" FORCE )
set_property ( DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${ NUTTX_DEFCONFIG } )
set ( NUTTX_SRC_DIR ${ PX4_SOURCE_DIR } /platforms/nuttx/NuttX )
set ( NUTTX_DIR ${ PX4_SOURCE_DIR } /platforms/nuttx/NuttX/nuttx CACHE FILEPATH "NuttX directory" FORCE )
set ( NUTTX_APPS_DIR ${ PX4_SOURCE_DIR } /platforms/nuttx/NuttX/apps CACHE FILEPATH "NuttX apps directory" FORCE )
px4_add_git_submodule ( TARGET git_nuttx PATH "${NUTTX_SRC_DIR}/nuttx" )
px4_add_git_submodule ( TARGET git_nuttx_apps PATH "${NUTTX_SRC_DIR}/apps" )
# make olddefconfig (inflate defconfig to full .config)
execute_process ( COMMAND ${ CMAKE_COMMAND } -E make_directory ${ NUTTX_CONFIG_DIR } /src ) # needed for NuttX build
execute_process ( COMMAND ${ CMAKE_COMMAND } -E copy_if_different ${ NUTTX_SRC_DIR } /Make.defs.in ${ NUTTX_DIR } /Make.defs ) # Create a temporary Toplevel Make.defs for the oldconfig step
execute_process ( COMMAND ${ CMAKE_COMMAND } -E copy_if_different ${ NUTTX_DEFCONFIG } ${ NUTTX_DIR } /.config )
execute_process ( COMMAND ${ CMAKE_COMMAND } -E copy_if_different ${ NUTTX_DEFCONFIG } ${ NUTTX_DIR } /defconfig )
set_property ( DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${ NUTTX_DIR } /defconfig )
execute_process (
C O M M A N D $ { N U T T X _ S R C _ D I R } / t o o l s / p x 4 _ n u t t x _ m a k e _ o l d d e f c o n f i g . s h
W O R K I N G _ D I R E C T O R Y $ { N U T T X _ D I R }
O U T P U T _ F I L E $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / n u t t x _ o l d d e f c o n f i g . l o g
R E S U L T _ V A R I A B L E r e t
)
execute_process ( COMMAND ${ CMAKE_COMMAND } -E copy_if_different ${ NUTTX_DIR } /.config ${ PX4_BINARY_DIR } /NuttX/nuttx/.config )
###############################################################################
# NuttX cmake defconfig
###############################################################################
# parse nuttx config options for cmake
file ( STRINGS ${ PX4_BINARY_DIR } /NuttX/nuttx/.config ConfigContents )
foreach ( NameAndValue ${ ConfigContents } )
# Strip leading spaces
string ( REGEX REPLACE "^[ ]+" "" NameAndValue ${ NameAndValue } )
# Find variable name
string ( REGEX MATCH "^CONFIG[^=]+" Name ${ NameAndValue } )
if ( Name )
# Find the value
string ( REPLACE "${Name}=" "" Value ${ NameAndValue } )
# remove extra quotes
string ( REPLACE "\" " " " Value ${ Value } )
# Set the variable
#message(STATUS "${Name} ${Value}")
set ( ${ Name } ${ Value } CACHE INTERNAL "NUTTX DEFCONFIG: ${Name}" FORCE )
endif ( )
endforeach ( )