[buildout]
extends =
  ../cmake/buildout.cfg
  ../curl/buildout.cfg
  ../git/buildout.cfg
  ../jsoncpp/buildout.cfg
  ../tinyxml2/buildout.cfg

parts =
  mavsdk

[c-astral-headers]
recipe = slapos.recipe.build:gitclone
repository = https://lab.nexedi.com/nexedi/c-astral-c-library
revision = v1.0
git-executable = ${git:location}/bin/git

[gcc]
min_version = 7.1

[mavsdk-source]
recipe = slapos.recipe.build:gitclone
repository = https://github.com/mavlink/MAVSDK.git
revision = v0.39.0

git-executable = ${git:location}/bin/git
ignore-cloning-submodules = true

[mavsdk]
recipe = slapos.recipe.cmmi
path = ${mavsdk-source:location}
cmake = ${cmake:location}/bin/cmake
pre-configure =
  ${git:location}/bin/git submodule update --init --recursive
  cp -r ${c-astral-headers:location}/* ${mavsdk-source:location}/src/third_party/mavlink/include/mavlink/v2.0/
  sed -i 's#common/mavlink.h#CAstral/mavlink.h#' ${mavsdk-source:location}/src/core/mavlink_include.h
configure-command =
  ${:cmake}
configure-options =
  -DCMAKE_BUILD_TYPE=Release
  -DCMAKE_C_FLAGS="${:CMAKE_CFLAGS}"
  -DCMAKE_CXX_FLAGS="${:CMAKE_CFLAGS}"
  -DCMAKE_INSTALL_PREFIX=@@LOCATION@@
  -DCMAKE_INSTALL_RPATH=${:CMAKE_LIBRARY_PATH}
  -DPKG_CONFIG_EXECUTABLE=${pkgconfig:location}/bin/pkg-config
  -DSUPERBUILD=OFF
  -Bbuild/default
  -H.
make-binary =
  ${:cmake} --build build/default --target install
environment =
  CMAKE_INCLUDE_PATH=${curl:location}/include:${jsoncpp:location}/include:${tinyxml2:location}/include
  CMAKE_LIBRARY_PATH=${:CMAKE_LIBRARY_PATH}
  CMAKE_PROGRAM_PATH=${cmake:location}/bin
  PATH=${pkgconfig:location}/bin/:%(PATH)s
  LDFLAGS=-L${jsoncpp:location}/lib -Wl,-rpath=${jsoncpp:location}/lib

CMAKE_CFLAGS=-I${tinyxml2:location}/include
CMAKE_LIBRARY_PATH=${curl:location}/lib:${jsoncpp:location}/lib:${tinyxml2:location}/lib
