[buildout]
extends =
  ../cmake/buildout.cfg
  ../curl/buildout.cfg
  ../git/buildout.cfg
  ../jsoncpp/buildout.cfg
  ../lxml-python/buildout.cfg
  ../macros/macro.pythonpath.eggs.cfg
  ../tinyxml2/buildout.cfg
  ../zlib/buildout.cfg

parts =
  mavsdk

[gcc]
min_version = 7.1

[c-astral-xml-definition]
recipe = slapos.recipe.build:gitclone
repository = https://lab.nexedi.com/nexedi/c-astral-c-library.git
revision = v2.1
git-executable = ${git:location}/bin/git

[mavsdk-source]
recipe = slapos.recipe.build:gitclone
repository = https://github.com/mavlink/MAVSDK.git
revision = v1.4.13
git-executable = ${git:location}/bin/git
ignore-cloning-submodules = true

[future]
recipe = zc.recipe.egg:custom
egg = future

[mavsdk-env]
CMAKE_INCLUDE_PATH=${curl:location}/include:${jsoncpp:location}/include:${tinyxml2:location}/include
CMAKE_LIBRARY_PATH=${curl:location}/lib:${jsoncpp:location}/lib:${tinyxml2:location}/lib:${zlib:location}/lib
CMAKE_PROGRAM_PATH=${cmake:location}/bin
PATH=${pkgconfig:location}/bin/:${git:location}/bin/:%(PATH)s
LDFLAGS=-L${curl:location}/lib -Wl,-rpath=${curl:location}/lib -L${jsoncpp:location}/lib -Wl,-rpath=${jsoncpp:location}/lib -L${tinyxml2:location}/lib -Wl,-rpath=${tinyxml2:location}/lib -L${zlib:location}/lib -Wl,-rpath=${zlib:location}/lib -Wl,-rpath=@@LOCATION@@/lib

[mavsdk-pythonpath]
<= macro.pythonpath.eggs
environment = mavsdk-env
eggs =
  ${future:egg}
  ${lxml-python:egg}

[mavsdk]
recipe = slapos.recipe.cmmi
path = ${mavsdk-source:location}
cmake = ${cmake:location}/bin/cmake
depends = ${mavsdk-pythonpath:recipe}
pre-configure =
  ${git:location}/bin/git submodule update --init --recursive
  sed -i 's#message_definitions/v1.0#${c-astral-xml-definition:location}#' ${mavsdk-source:location}/third_party/mavlink/CMakeLists.txt
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=${mavsdk-env:CMAKE_LIBRARY_PATH}:@@LOCATION@@/lib
  -DPKG_CONFIG_EXECUTABLE=${pkgconfig:location}/bin/pkg-config
  -DSUPERBUILD=OFF
  -Bbuild/default
  -H.
  -Wno-dev
make-binary =
  ${:cmake} --build build/default --target install
environment = mavsdk-env

CMAKE_CFLAGS=-I${tinyxml2:location}/include

[c-astral-wrapper]
recipe = slapos.recipe.cmmi
configure-command = true
url = https://lab.nexedi.com/nexedi/c-astral-wrapper/-/archive/v2.0/c-astral-wrapper-v2.0.tar.gz
md5sum = ee2d05d225a57d17318282ff595fd498
environment =
  CPLUS_INCLUDE_PATH=${qjs-wrapper-source:location}/include:${mavsdk:location}/include:${mavsdk:location}/include/mavsdk
  LDFLAGS=-L${mavsdk:location}/lib -Wl,-rpath=${mavsdk:location}/lib
