luxonis / depthai-core

DepthAI C++ Library
MIT License
234 stars 126 forks source link

Error during build using Yocto #447

Open oto313 opened 2 years ago

oto313 commented 2 years ago

I am using Yocto build system to integrate depthai into linux. It fails with error

The first command that fails:

FAILED: CMakeFiles/depthai-core.dir/src/device/Device.cpp.o
/base/build/tmp/work/cortexa9t2hf-neon-poky-linux-gnueabi/depthai/2.15.2-r0/recipe-sysroot-native/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++ -DBACKWARD_HAS_BACKTRACE=0 -DBACKWARD_HAS_BACKTRACE_SYMBOL=1 -DBACKWARD_HAS_BFD=0 -DBACKWARD_HAS_DW=0 -DBACKWARD_HAS_DWARF=0 -DBACKWARD_HAS_LIBUNWIND=0 -DBACKWARD_HAS_UNWIND=1 -DDEPTHAI_BOOTLOADER_VERSION=\"0.0.17\" -DDEPTHAI_DEVICE_VERSION=\"afe8d00c868344c73ee897e26278f80a444b9763\" -DDEPTHAI_ENABLE_BACKWARD -DDEPTHAI_PATCH_ONLY_MODE -DDEPTHAI_RESOURCE_COMPILED_BINARIES -DDEPTHAI_TARGET_CORE -DJSON_USE_IMPLICIT_CONVERSIONS=1 -DLIBARCHIVE_STATIC -DSPDLOG_COMPILED_LIB -DXLINK_USE_MX_ID_NAME=ON -D__PC__ -I/base/build/tmp/work/cortexa9t2hf-neon-poky-linux-gnueabi/depthai/2.15.2-r0/git/include -I/base/build/tmp/work/cortexa9t2hf-neon-poky-linux-gnueabi/depthai/2.15.2-r0/git/shared/depthai-shared/include -I/base/build/tmp/work/cortexa9t2hf-neon-poky-linux-gnueabi/depthai/2.15.2-r0/git/shared/depthai-bootloader-shared/include -I/base/build/tmp/work/cortexa9t2hf-neon-poky-linux-gnueabi/depthai/2.15.2-r0/git/include/depthai -I/base/build/tmp/work/cortexa9t2hf-neon-poky-linux-gnueabi/depthai/2.15.2-r0/git/src -I/base/build/tmp/work/cortexa9t2hf-neon-poky-linux-gnueabi/depthai/2.15.2-r0/git/shared/depthai-shared/src -I/base/build/tmp/work/cortexa9t2hf-neon-poky-linux-gnueabi/depthai/2.15.2-r0/git/shared/depthai-bootloader-shared/src -I/home/ysoft-ci/.hunter/_Base/cb0ea1f/32ad177/c6f42ce/Install/include -I/home/ysoft-ci/.hunter/_Base/cb0ea1f/32ad177/c6f42ce/Install/lib/backward -isystem /base/build/tmp/work/cortexa9t2hf-neon-poky-linux-gnueabi/depthai/2.15.2-r0/git/shared/depthai-shared/3rdparty -isystem /base/build/tmp/work/cortexa9t2hf-neon-poky-linux-gnueabi/depthai/2.15.2-r0/build/_cmrc/include -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 -fstack-protector-strong  -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security -Wdate-time  --sysroot=/base/build/tmp/work/cortexa9t2hf-neon-poky-linux-gnueabi/depthai/2.15.2-r0/recipe-sysroot  -O2 -pipe -g -feliminate-unused-debug-types -fmacro-prefix-map=/base/build/tmp/work/cortexa9t2hf-neon-poky-linux-gnueabi/depthai/2.15.2-r0=/usr/src/debug/depthai/2.15.2-r0                      -fdebug-prefix-map=/base/build/tmp/work/cortexa9t2hf-neon-poky-linux-gnueabi/depthai/2.15.2-r0=/usr/src/debug/depthai/2.15.2-r0                      -fdebug-prefix-map=/base/build/tmp/work/cortexa9t2hf-neon-poky-linux-gnueabi/depthai/2.15.2-r0/recipe-sysroot=                      -fdebug-prefix-map=/base/build/tmp/work/cortexa9t2hf-neon-poky-linux-gnueabi/depthai/2.15.2-r0/recipe-sysroot-native=  -fvisibility-inlines-hidden  -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 -fstack-protector-strong  -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security -Wdate-time  --sysroot=/base/build/tmp/work/cortexa9t2hf-neon-poky-linux-gnueabi/depthai/2.15.2-r0/recipe-sysroot -g -Wall -Wextra -Woverloaded-virtual -Wformat=2 -Wmisleading-indentation -Wduplicated-cond -Wduplicated-branches -Wnull-dereference -Wdouble-promotion -Wsign-compare -Wtype-limits -Werror=return-type -Werror=non-virtual-dtor -Werror=sign-compare -Werror=reorder -Werror=switch-enum -std=c++14 -MD -MT CMakeFiles/depthai-core.dir/src/device/Device.cpp.o -MF CMakeFiles/depthai-core.dir/src/device/Device.cpp.o.d -o CMakeFiles/depthai-core.dir/src/device/Device.cpp.o -c /base/build/tmp/work/cortexa9t2hf-neon-poky-linux-gnueabi/depthai/2.15.2-r0/git/src/device/Device.cpp

Error:

/home/ysoft-ci/.hunter/_Base/cb0ea1f/32ad177/c6f42ce/Install/include/nlohmann/json.hpp:21496:9: error: enumeration value 'string' not handled in switch [-Werror=switch-enum]
21496 |         switch (m_type)
      |         ^~~~~~
/home/ysoft-ci/.hunter/_Base/cb0ea1f/32ad177/c6f42ce/Install/include/nlohmann/json.hpp:21496:9: error: enumeration value 'boolean' not handled in switch [-Werror=switch-enum]
/home/ysoft-ci/.hunter/_Base/cb0ea1f/32ad177/c6f42ce/Install/include/nlohmann/json.hpp:21496:9: error: enumeration value 'number_integer' not handled in switch [-Werror=switch-enum]
/home/ysoft-ci/.hunter/_Base/cb0ea1f/32ad177/c6f42ce/Install/include/nlohmann/json.hpp:21496:9: error: enumeration value 'number_unsigned' not handled in switch [-Werror=switch-enum]
/home/ysoft-ci/.hunter/_Base/cb0ea1f/32ad177/c6f42ce/Install/include/nlohmann/json.hpp:21496:9: error: enumeration value 'number_float' not handled in switch [-Werror=switch-enum]
/home/ysoft-ci/.hunter/_Base/cb0ea1f/32ad177/c6f42ce/Install/include/nlohmann/json.hpp:21496:9: error: enumeration value 'binary' not handled in switch [-Werror=switch-enum]
/home/ysoft-ci/.hunter/_Base/cb0ea1f/32ad177/c6f42ce/Install/include/nlohmann/json.hpp:21496:9: error: enumeration value 'discarded' not handled in switch [-Werror=switch-enum]
In file included from /base/build/tmp/work/cortexa9t2hf-neon-poky-linux-gnueabi/depthai/2.15.2-r0/git/shared/depthai-shared/include/depthai-shared/utility/Serialization.hpp:14,
                 from /base/build/tmp/work/cortexa9t2hf-neon-poky-linux-gnueabi/depthai/2.15.2-r0/git/shared/depthai-shared/include/depthai-shared/datatype/RawBuffer.hpp:6,
                 from /base/build/tmp/work/cortexa9t2hf-neon-poky-linux-gnueabi/depthai/2.15.2-r0/git/include/depthai/pipeline/datatype/ADatatype.hpp:6,
                 from /base/build/tmp/work/cortexa9t2hf-neon-poky-linux-gnueabi/depthai/2.15.2-r0/git/include/depthai/device/DataQueue.hpp:9,
                 from /base/build/tmp/work/cortexa9t2hf-neon-poky-linux-gnueabi/depthai/2.15.2-r0/git/include/depthai/device/Device.hpp:13,
                 from /base/build/tmp/work/cortexa9t2hf-neon-poky-linux-gnueabi/depthai/2.15.2-r0/git/src/device/Device.cpp:1:

It looks like that you are setting flag compiler -Werror=switch-enum . But these flags are used also in 3rdparty libraries which are used through header files.

I tried also build it on Ubuntu and it works. But I do not understand why it works on native linux. When I look into included header files (eg. json.hpp) I see that not all cases in switch are handled. So it should definitely fail.

for example here at json.hpp


  21494     size_type size() const noexcept
  21495     {
  21496         switch (m_type)
  21497         {
  21498             case value_t::null:
  21499             {
  21500                 // null values are empty
  21501                 return 0;
  21502             }
  21503
  21504             case value_t::array:
  21505             {
  21506                 // delegate call to array_t::size()
  21507                 return m_value.array->size();
  21508             }
  21509
  21510             case value_t::object:
  21511             {
  21512                 // delegate call to object_t::size()
  21513                 return m_value.object->size();
  21514             }
  21515
  21516             default:
  21517             {
  21518                 // all other types have size 1
  21519                 return 1;
  21520             }
  21521         }
  21522     }

enum definition at value_t.hpp

enum class value_t : std::uint8_t
{
    null,             ///< null value
    object,           ///< object (unordered set of name/value pairs)
    array,            ///< array (ordered collection of values)
    string,           ///< string value
    boolean,          ///< boolean value
    number_integer,   ///< number value (signed integer)
    number_unsigned,  ///< number value (unsigned integer)
    number_float,     ///< number value (floating-point)
    binary,           ///< binary array (ordered collection of bytes)
    discarded         ///< discarded by the parser callback function
};

So I propose to remove -Werror=switch-enum flag from cmake/Flags.cmake When I remove this flag it works as expected.

Complete error output of command: error.txt

themarpe commented 2 years ago

Hi @oto313 - do you mind checking why there is such a difference in this two scenarios?

Also, what version of GCC are you using to compile the sources?

We'll have to check how this could be mitigated, as this flag is quite useful in our codebase

oto313 commented 2 years ago

I also do not understand why there is such difference. But in Yocto it make sense that it turn switch warnings into errors. Maybe some fix in a newer GCC

Compiler: GCC 11.2

themarpe commented 2 years ago

@oto313

Temporary I'd then suggest adding a patch file and according bb layer to build in Yocto without issues.

Will have to dig more to resolve this.

oto313 commented 2 years ago

Ok Great to hear that you plan to address this issue. Thanks

windelbouwman commented 2 years ago

Hi @oto313 ,

Glad somebody else tries to package depthai-core in yocto. I made some bitbake recipes for this, and faced a couple of issues. Step one for me was to disable the hunter package manager.

See also this issue: #411 .

Is there already a layer of some sort? Or a repository for yocto bitbake recipes?

themarpe commented 2 years ago

For Yocto, I'd just compile & install depthai-core as usual (into some working directory), and then specify the rules in layer to install that folder to sysroot (eg /usr or /usr/local, ...)

That should work as intended

themarpe commented 2 years ago

@oto313

I assume that the difference could be in -isystem vs -I means of specifying include directories. Hunter dependencies are under -isystem which might be the reason it doesn't apply the flag in some cases.

Maybe check if that is so in this case as well (verbose build and copy back the whole build command that is executed)

oto313 commented 2 years ago

@windelbouwman I successfully built depthai after apply patch to Flags.cmake. I can share recipe (tried on honister):

SUMMARY = "DepthAI API allows users to connect to, configure and communicate with their OAK devices"
HOMEPAGE = "https://github.com/luxonis/depthai-core"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=39a6484daa66eaf84c7ee9c45e34db02"
DEPENDS = "libusb1"

SRC_URI = "gitsm://github.com/luxonis/depthai-core.git;nobranch=1;tag=v2.15.2;protocol=git \
           file://fix-enum-error.patch \
           "

S = "${WORKDIR}/git"

inherit cmake pkgconfig

OECMAKE_C_FLAGS += " -fPIC "
OECMAKE_CXX_FLAGS += " -fPIC "

PACKAGECONFIG ?= ""
PACKAGECONFIG[opencv] = "-DDEPTHAI_OPENCV_SUPPORT=TRUE, -DDEPTHAI_OPENCV_SUPPORT=FALSE, opencv"

PACKAGES = "${PN} ${PN}-dev ${PN}-staticdev"

FILES:${PN}-staticdev = "${libdir}/lib*.a ${libdir}/cmake/depthai"
FILES:${PN}-dev = "${includedir}/* ${libdir}/cmake/depthai/*.cmake"

Note that I am not Yocto expert. Somebody maybe could improve the recipe. The fPIC switch is required on ARM because some static library needs to be build with relocatable code.

@themarpe Ok I will try. Thanks

windelbouwman commented 2 years ago

Below is my attempted bitbake recipe. Couple of notes:


SUMMARY = "DepthAI C++ Library"
HOMEPAGE = "https://github.com/luxonis/depthai-core"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=39a6484daa66eaf84c7ee9c45e34db02"

# These resources are required as resources, note that these are very coupled to the version of depthai-core:
# See: cmake/Depthai/DepthaiBootloaderConfig.cmake
#   depthai bootloader: release-0.0.17
#   https://artifacts.luxonis.com/artifactory/luxonis-myriad-release-local/depthai-bootloader/0.0.17/depthai-bootloader-fwp-0.0.17.tar.xz
# See: cmake/Depthai/DepthaiDownloader.cmake
#   depthai device side
#   https://artifacts.luxonis.com/artifactory/luxonis-myriad-snapshot-local/depthai-device-side/afe8d00c868344c73ee897e26278f80a444b9763/depthai-device-fwp-afe8d00c868344c73ee897e26278f80a444b9763.tar.xz

SRC_URI = "https://github.com/luxonis/${BPN}/releases/download/v${PV}/${BPN}-v${PV}.tar.gz;name=src \
           https://artifacts.luxonis.com/artifactory/luxonis-myriad-release-local/depthai-bootloader/0.0.17/depthai-bootloader-fwp-0.0.17.tar.xz;unpack=0;name=bootloader-fwp \
           https://artifacts.luxonis.com/artifactory/luxonis-myriad-snapshot-local/depthai-device-side/afe8d00c868344c73ee897e26278f80a444b9763/depthai-device-fwp-afe8d00c868344c73ee897e26278f80a444b9763.tar.xz;unpack=0;name=device-fwp \
           file://80-movidius.rules \
           file://0001-Adapt-cmake-configuration-to-be-compatible-with-open.patch \
           file://0002-Remove-downloading-from-CMakeLists.txt.patch \
           "

# These three downloads are a coupled set, when updating the src, update the other blobs as well!
SRC_URI[src.sha256sum] = "dea755d06ed19a1ea57cf6474a80c47302d7edd27060234447c17a93b9602877"
SRC_URI[bootloader-fwp.sha256sum] = "27ea0d797498f7fff1d82e9524ea6a244a5998424b523eab9b353944548bcbef"
SRC_URI[device-fwp.sha256sum] = "5cc6e63d5c10430c3cc73f74278c928a39d36b860160403962e898e63ef96046"

S = "${WORKDIR}/${BPN}-v${PV}"

inherit cmake

# DEPTHAI_BINARIES_RESOURCE_COMPILE=OFF should disable the inclusion of bootloader and application as a resource.
# HUNTER_ENABLED=OFF disables the hunter C++ package manager (since we use bitbake)
# DEPTHAI_ENABLE_BACKWARD=OFF disables the use of a fancy C++ backtrace printing library called 'backward'
# BUILD_SHARED_LIBS=ON ensures we build shared libraries
# using DEPTHAI_BOOTLOADER_SHARED_LOCAL prevents GIT submodule initialization
EXTRA_OECMAKE:append = " \
    -DHUNTER_ENABLED=OFF \
    -DCMAKE_BUILD_TYPE=Release \
    -DDEPTHAI_CLANG_FORMAT=OFF \
    -DDEPTHAI_CLANG_TIDY=OFF \
    -DDEPTHAI_ENABLE_BACKWARD=OFF \
    -DDEPTHAI_BINARIES_RESOURCE_COMPILE=ON \
    -DBUILD_SHARED_LIBS=ON \
    -DDEPTHAI_BOOTLOADER_SHARED_LOCAL=${S}/shared/depthai-bootloader-shared \
    -DDEPTHAI_SHARED_LOCAL=${S}/shared/depthai-shared \
    -DDEPTHAI_BUILD_EXAMPLES=OFF \
    -DDEPTHAI_BUILD_TESTS=OFF \
    -DDEPTHAI_BUILD_DOCS=OFF \
    -DDEPTHAI_BOOTLOADER_FWP=${WORKDIR}/depthai-bootloader-fwp-0.0.17.tar.xz \
    -DDEPTHAI_DEVICE_FWP=${WORKDIR}/depthai-device-fwp-afe8d00c868344c73ee897e26278f80a444b9763.tar.xz \
    "

DEPENDS = " \
    bzip2 \
    spdlog \
    libarchive \
    zlib \
    xz \
    nlohmann-json \
    luxonis-xlink \
    luxonis-libnop \
    luxonis-fp16 \
"

do_install:append() {
    # These permissions are required, otherwise the OAK-D device will report as X_LINK_UNBOOTED
    install -Dm 0644 ${WORKDIR}/80-movidius.rules ${D}${sysconfdir}/udev/rules.d/80-movidius.rules
}

# -dev package depthai-core-dev contains non-symlink .so '/usr/lib/libdepthai-core.so' [dev-elf]
FILES_SOLIBSDEV = ""
FILES:${PN} += " \
    ${libdir}/lib*${SOLIBSDEV} \
    ${sysconfdir}/udev/rules.d/80-movidius.rules \
"
oto313 commented 2 years ago

@windelbouwman do you have and can you provide all recipes you used to build depthai-core? I am building the project by yocto with Hunter, but I have run into some issues. So the only way to do the proper build is without the hunter. Thanks

windelbouwman commented 2 years ago

Sure, this is my set of recipes.

It would be nice to store these in some public repo. Another note is that many patches done here should be somehow included in the depthai source code, such that the recipes become simpler.

Another note is that the git hashes must be manually determined by checking the hunter dependencies file, where specific commits are referred. This is a bit tricky.

depthai-core_2.15.2.bb


SUMMARY = "DepthAI C++ Library"
HOMEPAGE = "https://github.com/luxonis/depthai-core"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=39a6484daa66eaf84c7ee9c45e34db02"

# These resources are required as resources, note that these are very coupled to the version of depthai-core:
# See: cmake/Depthai/DepthaiBootloaderConfig.cmake
#   depthai bootloader: release-0.0.17
#   https://artifacts.luxonis.com/artifactory/luxonis-myriad-release-local/depthai-bootloader/0.0.17/depthai-bootloader-fwp-0.0.17.tar.xz
# See: cmake/Depthai/DepthaiDownloader.cmake
#   depthai device side
#   https://artifacts.luxonis.com/artifactory/luxonis-myriad-snapshot-local/depthai-device-side/afe8d00c868344c73ee897e26278f80a444b9763/depthai-device-fwp-afe8d00c868344c73ee897e26278f80a444b9763.tar.xz

SRC_URI = "https://github.com/luxonis/${BPN}/releases/download/v${PV}/${BPN}-v${PV}.tar.gz;name=src \
           https://artifacts.luxonis.com/artifactory/luxonis-myriad-release-local/depthai-bootloader/0.0.17/depthai-bootloader-fwp-0.0.17.tar.xz;unpack=0;name=bootloader-fwp \
           https://artifacts.luxonis.com/artifactory/luxonis-myriad-snapshot-local/depthai-device-side/afe8d00c868344c73ee897e26278f80a444b9763/depthai-device-fwp-afe8d00c868344c73ee897e26278f80a444b9763.tar.xz;unpack=0;name=device-fwp \
           file://80-movidius.rules \
           file://0001-Adapt-cmake-configuration-to-be-compatible-with-open.patch \
           file://0002-Remove-downloading-from-CMakeLists.txt.patch \
           "

# These three downloads are a coupled set, when updating the src, update the other blobs as well!
SRC_URI[src.sha256sum] = "dea755d06ed19a1ea57cf6474a80c47302d7edd27060234447c17a93b9602877"
SRC_URI[bootloader-fwp.sha256sum] = "27ea0d797498f7fff1d82e9524ea6a244a5998424b523eab9b353944548bcbef"
SRC_URI[device-fwp.sha256sum] = "5cc6e63d5c10430c3cc73f74278c928a39d36b860160403962e898e63ef96046"

S = "${WORKDIR}/${BPN}-v${PV}"

inherit cmake

# DEPTHAI_BINARIES_RESOURCE_COMPILE=OFF should disable the inclusion of bootloader and application as a resource.
# HUNTER_ENABLED=OFF disables the hunter C++ package manager (since we use bitbake)
# DEPTHAI_ENABLE_BACKWARD=OFF disables the use of a fancy C++ backtrace printing library called 'backward'
# BUILD_SHARED_LIBS=ON ensures we build shared libraries
# using DEPTHAI_BOOTLOADER_SHARED_LOCAL prevents GIT submodule initialization
EXTRA_OECMAKE:append = " \
    -DHUNTER_ENABLED=OFF \
    -DCMAKE_BUILD_TYPE=Release \
    -DDEPTHAI_CLANG_FORMAT=OFF \
    -DDEPTHAI_CLANG_TIDY=OFF \
    -DDEPTHAI_ENABLE_BACKWARD=OFF \
    -DDEPTHAI_BINARIES_RESOURCE_COMPILE=ON \
    -DBUILD_SHARED_LIBS=ON \
    -DDEPTHAI_BOOTLOADER_SHARED_LOCAL=${S}/shared/depthai-bootloader-shared \
    -DDEPTHAI_SHARED_LOCAL=${S}/shared/depthai-shared \
    -DDEPTHAI_BUILD_EXAMPLES=OFF \
    -DDEPTHAI_BUILD_TESTS=OFF \
    -DDEPTHAI_BUILD_DOCS=OFF \
    -DDEPTHAI_BOOTLOADER_FWP=${WORKDIR}/depthai-bootloader-fwp-0.0.17.tar.xz \
    -DDEPTHAI_DEVICE_FWP=${WORKDIR}/depthai-device-fwp-afe8d00c868344c73ee897e26278f80a444b9763.tar.xz \
    "

DEPENDS = " \
    bzip2 \
    spdlog \
    libarchive \
    zlib \
    xz \
    nlohmann-json \
    luxonis-xlink \
    luxonis-libnop \
    luxonis-fp16 \
"

do_install:append() {
    # These permissions are required, otherwise the OAK-D device will report as X_LINK_UNBOOTED
    install -Dm 0644 ${WORKDIR}/80-movidius.rules ${D}${sysconfdir}/udev/rules.d/80-movidius.rules
}

# -dev package depthai-core-dev contains non-symlink .so '/usr/lib/libdepthai-core.so' [dev-elf]
FILES_SOLIBSDEV = ""
FILES:${PN} += " \
    ${libdir}/lib*${SOLIBSDEV} \
    ${sysconfdir}/udev/rules.d/80-movidius.rules \
"

0001-Adapt-cmake-configuration-to-be-compatible-with-open.patch

From 68c100d2c164f084255699c2d88a779f062578b1 Mon Sep 17 00:00:00 2001
From: Windel Bouwman <windel@windel.nl>
Date: Fri, 1 Apr 2022 16:20:13 +0200
Subject: [PATCH] Adapt cmake configuration to be compatible with openembedded.

---
 CMakeLists.txt                  | 89 +++++++++++++++++----------------
 cmake/GitCommitHash.cmake       |  2 +-
 cmake/depthaiDependencies.cmake | 12 ++---
 3 files changed, 54 insertions(+), 49 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index cf366f7..1e08086 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -113,7 +113,7 @@ endif()
 set(PROJECT_EXPORT_GROUP "${PROJECT_NAME}Targets")

 ## Check if cloned or sources
-find_package(Git)
+# find_package(Git)
 if(GIT_FOUND)
     execute_process(
         COMMAND ${GIT_EXECUTABLE} rev-parse --is-inside-work-tree
@@ -292,50 +292,50 @@ if($ENV{CI})
     set(DEPTHAI_BOOTLOADER_SHARED_COMMIT_HASH_ENFORCE ON)
 endif()

+if(DEPTHAI_BINARIES_RESOURCE_COMPILE)

-# Then get the Depthai device side binaries (local or download)
-if(DEPTHAI_CMD_PATH OR DEPTHAI_USB2_CMD_PATH OR DEPTHAI_USB2_PATCH_PATH)
-    # Atleast one of the paths is set. include binaries locally
-    message(STATUS "Using local Depthai device side binaries...")
+    # Then get the Depthai device side binaries (local or download)
+    if(DEPTHAI_CMD_PATH OR DEPTHAI_USB2_CMD_PATH OR DEPTHAI_USB2_PATCH_PATH)
+        # Atleast one of the paths is set. include binaries locally
+        message(STATUS "Using local Depthai device side binaries...")

-    DepthaiLocal(
-        PATCH_ONLY ${DEPTHAI_USB2_PATCH_ONLY_MODE}
-        "${DEPTHAI_RESOURCES_OUTPUT_DIR}"            # Output folder
-        DEPTHAI_RESOURCE_LIST                       # List of output resources
-        "${DEPTHAI_CMD_PATH}"                       # depthai.cmd
-        "${DEPTHAI_USB2_CMD_PATH}"                  # depthai-usb2.cmd
-        "${DEPTHAI_USB2_PATCH_PATH}"                # depthai-usb2-patch.patch
-    )
+        DepthaiLocal(
+            PATCH_ONLY ${DEPTHAI_USB2_PATCH_ONLY_MODE}
+            "${DEPTHAI_RESOURCES_OUTPUT_DIR}"            # Output folder
+            DEPTHAI_RESOURCE_LIST                       # List of output resources
+            "${DEPTHAI_CMD_PATH}"                       # depthai.cmd
+            "${DEPTHAI_USB2_CMD_PATH}"                  # depthai-usb2.cmd
+            "${DEPTHAI_USB2_PATCH_PATH}"                # depthai-usb2-patch.patch
+        )

-else()
-    # No user specified paths, download from server
-    message(STATUS "Downloading Depthai device side binaries from server...")
-
-    DepthaiDownload(
-        "${DEPTHAI_SHARED_COMMIT_HASH}" "${DEPTHAI_SHARED_COMMIT_HASH_ENFORCE}"
-        PATCH_ONLY ${DEPTHAI_USB2_PATCH_ONLY_MODE}
-        "${DEPTHAI_RESOURCES_OUTPUT_DIR}"            # Output folder
-        DEPTHAI_RESOURCE_LIST                       # List of output resources
-        "${DEPTHAI_DEVICE_SIDE_MATURITY}"           # Maturity
-        "${DEPTHAI_DEVICE_SIDE_COMMIT}"             # commit hash
-        "${DEPTHAI_DEVICE_SIDE_VERSION}"            # Optional version
+    else()
+        # No user specified paths, download from server
+        message(STATUS "Downloading Depthai device side binaries from server...")
+
+        DepthaiDownload(
+            "${DEPTHAI_SHARED_COMMIT_HASH}" "${DEPTHAI_SHARED_COMMIT_HASH_ENFORCE}"
+            PATCH_ONLY ${DEPTHAI_USB2_PATCH_ONLY_MODE}
+            "${DEPTHAI_RESOURCES_OUTPUT_DIR}"            # Output folder
+            DEPTHAI_RESOURCE_LIST                       # List of output resources
+            "${DEPTHAI_DEVICE_SIDE_MATURITY}"           # Maturity
+            "${DEPTHAI_DEVICE_SIDE_COMMIT}"             # commit hash
+            "${DEPTHAI_DEVICE_SIDE_VERSION}"            # Optional version
+        )
+    endif()
+    list(APPEND RESOURCE_COMPILED_FILES ${DEPTHAI_RESOURCE_LIST})
+
+    # Add bootloader
+    DepthaiBootloaderDownload(
+        "${DEPTHAI_BOOTLOADER_SHARED_COMMIT_HASH}" "${DEPTHAI_BOOTLOADER_SHARED_COMMIT_HASH_ENFORCE}"
+        "${DEPTHAI_RESOURCES_OUTPUT_DIR}"                # Output folder
+        DEPTHAI_BOOTLOADER_RESOURCE_LIST                # List of output resources
+        "${DEPTHAI_BOOTLOADER_MATURITY}"                # Maturity
+        "${DEPTHAI_BOOTLOADER_VERSION}"                 # if maturity == snapshot -> hash else version
     )
-endif()
-list(APPEND RESOURCE_COMPILED_FILES ${DEPTHAI_RESOURCE_LIST})
+    list(APPEND RESOURCE_COMPILED_FILES ${DEPTHAI_BOOTLOADER_RESOURCE_LIST})

-# Add bootloader
-DepthaiBootloaderDownload(
-    "${DEPTHAI_BOOTLOADER_SHARED_COMMIT_HASH}" "${DEPTHAI_BOOTLOADER_SHARED_COMMIT_HASH_ENFORCE}"
-    "${DEPTHAI_RESOURCES_OUTPUT_DIR}"                # Output folder
-    DEPTHAI_BOOTLOADER_RESOURCE_LIST                # List of output resources
-    "${DEPTHAI_BOOTLOADER_MATURITY}"                # Maturity
-    "${DEPTHAI_BOOTLOADER_VERSION}"                 # if maturity == snapshot -> hash else version
-)
-list(APPEND RESOURCE_COMPILED_FILES ${DEPTHAI_BOOTLOADER_RESOURCE_LIST})
-
-message(STATUS "LIST OF RESOURCE COMPILED FILES: ${RESOURCE_COMPILED_FILES}")
+    message(STATUS "LIST OF RESOURCE COMPILED FILES: ${RESOURCE_COMPILED_FILES}")

-if(DEPTHAI_BINARIES_RESOURCE_COMPILE)
     # Add RC and resource compile the binares
     include(CMakeRC)

@@ -400,11 +400,11 @@ target_link_libraries(${TARGET_CORE_NAME}
         libnop
     PRIVATE
         Threads::Threads
-        BZip2::bz2
+        BZip2::BZip2
         FP16::fp16
-        archive_static
+        LibArchive::LibArchive
         spdlog::spdlog
-        ZLIB::zlib
+        ZLIB::ZLIB
 )

 # Add compile definitions
@@ -559,8 +559,10 @@ configure_file("cmake/${PROJECT_NAME}Dependencies.cmake" ${PROJECT_NAME}Dependen
 write_basic_package_version_file(${PROJECT_NAME}ConfigVersion.cmake VERSION ${PROJECT_VERSION} COMPATIBILITY AnyNewerVersion)

 # Configure config file (one for exporting build directory, one for installation)
+if(HUNTER_ENABLED)
 file(RELATIVE_PATH DEPTHAI_DEPENDENCIES_INSTALLATION_PATH_REL "${CMAKE_CURRENT_BINARY_DIR}" "${HUNTER_INSTALL_PREFIX}")
 configure_file(cmake/${PROJECT_NAME}Config.cmake.in ${PROJECT_NAME}Config.cmake @ONLY)
+endif()

 # Config for installation
 set(DEPTHAI_DEPENDENCIES_INSTALLATION_PATH_REL "./dependencies")
@@ -591,7 +593,10 @@ if(DEPTHAI_INSTALL)
     # Install depthai-bootloader-shared public headers
     install(DIRECTORY "${DEPTHAI_BOOTLOADER_SHARED_PUBLIC_INCLUDE}/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
     # Install Hunter dependencies
+    if(HUNTER_ENABLED)
     install(DIRECTORY "${HUNTER_INSTALL_PREFIX}/" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}/dependencies")
+    endif()
+
     # Install resources if not RC'd
     if(NOT DEPTHAI_BINARIES_RESOURCE_COMPILE)
         install(DIRECTORY "${DEPTHAI_RESOURCES_OUTPUT_DIR}/" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}")
diff --git a/cmake/GitCommitHash.cmake b/cmake/GitCommitHash.cmake
index 0b1a406..87a4c39 100644
--- a/cmake/GitCommitHash.cmake
+++ b/cmake/GitCommitHash.cmake
@@ -1,5 +1,5 @@
 # for commit hash
-find_package(Git)
+# find_package(Git)

 set(commit_version "unknown")

diff --git a/cmake/depthaiDependencies.cmake b/cmake/depthaiDependencies.cmake
index bbbd606..8c8387b 100644
--- a/cmake/depthaiDependencies.cmake
+++ b/cmake/depthaiDependencies.cmake
@@ -23,19 +23,19 @@ endif()
 if(NOT CONFIG_MODE OR (CONFIG_MODE AND NOT DEPTHAI_SHARED_LIBS))

     # BZip2 (for bspatch)
-    find_package(BZip2 ${_QUIET} CONFIG REQUIRED)
+    find_package(BZip2 REQUIRED)

     # FP16 for conversions
-    find_package(FP16 ${_QUIET} CONFIG REQUIRED)
+    find_package(FP16 REQUIRED)

     # libarchive for firmware packages
-    find_package(archive_static ${_QUIET} CONFIG REQUIRED)
-    find_package(lzma ${_QUIET} CONFIG REQUIRED)
+    find_package(LibArchive REQUIRED)
+    find_package(LibLZMA REQUIRED)
     # ZLIB for compressing Apps
-    find_package(ZLIB CONFIG REQUIRED)
+    find_package(ZLIB REQUIRED)

     # spdlog for library and device logging
-    find_package(spdlog ${_QUIET} CONFIG REQUIRED)
+    find_package(spdlog REQUIRED)

     # Backward
     if(DEPTHAI_ENABLE_BACKWARD)

0002-Remove-downloading-from-CMakeLists.txt.patch


From 25095a8439c83b339a780c3df2b01372103033e8 Mon Sep 17 00:00:00 2001
From: Windel Bouwman <windel@windel.nl>
Date: Mon, 4 Apr 2022 16:03:45 +0200
Subject: [PATCH] Remove downloading from CMakeLists.txt

---
 CMakeLists.txt | 50 ++++----------------------------------------------
 1 file changed, 4 insertions(+), 46 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1e08086..f859d1c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -276,16 +276,12 @@ endif()

 # Set constant
 set(DEPTHAI_RESOURCES_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/resources")
+message(STATUS "resource folder: ${DEPTHAI_RESOURCES_OUTPUT_DIR}")

 # Include configuration
 include(Depthai/DepthaiDeviceSideConfig)    # Depthai device binary commit/version configuration
 include(Depthai/DepthaiBootloaderConfig)    # Depthai bootloader binary commit/version configuration

-# Include downloaders
-include(DepthaiDownloader)                  # Depthai device binary downloader
-include(DepthaiBootloaderDownloader)        # Depthai bootloader binary downloader
-
-
 # depthai-shared enforce commit hash match if CI
 if($ENV{CI})
     set(DEPTHAI_SHARED_COMMIT_HASH_ENFORCE ON)
@@ -293,47 +289,9 @@ if($ENV{CI})
 endif()

 if(DEPTHAI_BINARIES_RESOURCE_COMPILE)
-
-    # Then get the Depthai device side binaries (local or download)
-    if(DEPTHAI_CMD_PATH OR DEPTHAI_USB2_CMD_PATH OR DEPTHAI_USB2_PATCH_PATH)
-        # Atleast one of the paths is set. include binaries locally
-        message(STATUS "Using local Depthai device side binaries...")
-
-        DepthaiLocal(
-            PATCH_ONLY ${DEPTHAI_USB2_PATCH_ONLY_MODE}
-            "${DEPTHAI_RESOURCES_OUTPUT_DIR}"            # Output folder
-            DEPTHAI_RESOURCE_LIST                       # List of output resources
-            "${DEPTHAI_CMD_PATH}"                       # depthai.cmd
-            "${DEPTHAI_USB2_CMD_PATH}"                  # depthai-usb2.cmd
-            "${DEPTHAI_USB2_PATCH_PATH}"                # depthai-usb2-patch.patch
-        )
-
-    else()
-        # No user specified paths, download from server
-        message(STATUS "Downloading Depthai device side binaries from server...")
-
-        DepthaiDownload(
-            "${DEPTHAI_SHARED_COMMIT_HASH}" "${DEPTHAI_SHARED_COMMIT_HASH_ENFORCE}"
-            PATCH_ONLY ${DEPTHAI_USB2_PATCH_ONLY_MODE}
-            "${DEPTHAI_RESOURCES_OUTPUT_DIR}"            # Output folder
-            DEPTHAI_RESOURCE_LIST                       # List of output resources
-            "${DEPTHAI_DEVICE_SIDE_MATURITY}"           # Maturity
-            "${DEPTHAI_DEVICE_SIDE_COMMIT}"             # commit hash
-            "${DEPTHAI_DEVICE_SIDE_VERSION}"            # Optional version
-        )
-    endif()
-    list(APPEND RESOURCE_COMPILED_FILES ${DEPTHAI_RESOURCE_LIST})
-
-    # Add bootloader
-    DepthaiBootloaderDownload(
-        "${DEPTHAI_BOOTLOADER_SHARED_COMMIT_HASH}" "${DEPTHAI_BOOTLOADER_SHARED_COMMIT_HASH_ENFORCE}"
-        "${DEPTHAI_RESOURCES_OUTPUT_DIR}"                # Output folder
-        DEPTHAI_BOOTLOADER_RESOURCE_LIST                # List of output resources
-        "${DEPTHAI_BOOTLOADER_MATURITY}"                # Maturity
-        "${DEPTHAI_BOOTLOADER_VERSION}"                 # if maturity == snapshot -> hash else version
-    )
-    list(APPEND RESOURCE_COMPILED_FILES ${DEPTHAI_BOOTLOADER_RESOURCE_LIST})
-
+    file(COPY "${DEPTHAI_BOOTLOADER_FWP}" DESTINATION "${DEPTHAI_RESOURCES_OUTPUT_DIR}")
+    file(COPY "${DEPTHAI_DEVICE_FWP}" DESTINATION "${DEPTHAI_RESOURCES_OUTPUT_DIR}")
+    file(GLOB RESOURCE_COMPILED_FILES "${DEPTHAI_RESOURCES_OUTPUT_DIR}/*.tar.xz")
     message(STATUS "LIST OF RESOURCE COMPILED FILES: ${RESOURCE_COMPILED_FILES}")

     # Add RC and resource compile the binares

luxonis-fp16_git.bb


SUMMARY = "Conversion to/from half-precision floating point formats"
HOMEPAGE = "https://github.com/luxonis/FP16"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=998fb0b16ad8a4fb8bd41bf3faf2d21c"

# See: https://github.com/luxonis/depthai-core/blob/v2.15.2/cmake/Hunter/config.cmake
SRC_URI = "git://github.com/luxonis/FP16.git;branch=master"
SRCREV = "c911175d2717e562976e606c6e5f799bf40cf94e"

S = "${WORKDIR}/git"

# TODO: this repo is downloaded during configure stage:
# https://github.com/Maratyszcza/psimd

EXTRA_OECMAKE:append = " \
    -DFP16_BUILD_TESTS=OFF \
    -DFP16_BUILD_BENCHMARKS=OFF \
    "

inherit cmake

luxonis-xlink_git.bb


SUMMARY = "A cross-platform library for communicating with devices over various physical links."
HOMEPAGE = "https://github.com/luxonis/XLink"
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://CMakeLists.txt;beginline=2;endline=2;md5=653b254f286b881bdce1d14afdede628"

# See: https://github.com/luxonis/depthai-core/blob/v2.15.2/cmake/Hunter/config.cmake
SRC_URI = "git://github.com/luxonis/XLink.git;branch=develop \
           file://0001-Use-pkg-config-to-find-libusb-1.0.patch \
           "
SRCREV = "e30ce8053f1795f5e63c1f4bd03e722153299c15"

S = "${WORKDIR}/git"

EXTRA_OECMAKE:append = " \
    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_SHARED_LIBS=ON \
    "

DEPENDS = " \
    libusb1 \
"

inherit cmake

# TODO: this should not happen, but xlink SO file is unversioned.
FILES_SOLIBSDEV = ""
FILES:${PN} += " \
    ${libdir}/lib*${SOLIBSDEV} \
"

0001-Use-pkg-config-to-find-libusb-1.0.patch


From 1570d7468bd8ef1de5147db15c2c0ab6c40293fe Mon Sep 17 00:00:00 2001
From: Windel Bouwman <windel@windel.nl>
Date: Tue, 5 Apr 2022 09:41:05 +0200
Subject: [PATCH] Use pkg-config to find libusb-1.0

---
 CMakeLists.txt    |  4 ++--
 cmake/XLink.cmake | 14 ++++++--------
 2 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index c9682e2..d0d0bc6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -22,12 +22,12 @@ if(WIN32)
     target_compile_definitions(${TARGET_NAME} PRIVATE WIN32_LEAN_AND_MEAN)
 else()
     target_include_directories(${TARGET_NAME}
-        PRIVATE "${LIBUSB_INCLUDE_DIR}"
+        PRIVATE "${MY_LIBUSB_INCLUDE_DIRS}"
     )

     target_link_libraries(${TARGET_NAME}
         PRIVATE Threads::Threads
-        PUBLIC ${LIBUSB_LIBRARY}
+        PUBLIC "${MY_LIBUSB_LIBRARIES}"
     )
 endif()

diff --git a/cmake/XLink.cmake b/cmake/XLink.cmake
index 4d4f6a0..eb58418 100644
--- a/cmake/XLink.cmake
+++ b/cmake/XLink.cmake
@@ -19,17 +19,15 @@ if(WIN32)
     list(APPEND XLINK_SOURCES ${XLINK_PLATFORM_SRC})
 else()
     find_package(Threads REQUIRED)
-
-    find_path(LIBUSB_INCLUDE_DIR NAMES libusb.h PATH_SUFFIXES "include" "libusb" "libusb-1.0")
-    find_library(LIBUSB_LIBRARY NAMES usb-1.0 PATH_SUFFIXES "lib")
-
-    if(NOT LIBUSB_INCLUDE_DIR OR NOT LIBUSB_LIBRARY)
-        message(FATAL_ERROR "libusb is required")
-    endif()
+    find_package(PkgConfig REQUIRED)
+    pkg_check_modules(MY_LIBUSB
+        REQUIRED 
+        libusb-1.0
+    )

     set(XLINK_PLATFORM_INCLUDE "${XLINK_ROOT_DIR}/src/pc/MacOS" )
     list(APPEND XLINK_SOURCES "${XLINK_ROOT_DIR}/src/pc/MacOS/pthread_semaphore.c")
 endif(WIN32)

 #This is for the Movidius team
-set(XLINK_INCLUDE_DIRECTORIES ${XLINK_INCLUDE} ${LIBUSB_INCLUDE_DIR})
+set(XLINK_INCLUDE_DIRECTORIES ${XLINK_INCLUDE})

luxonis-libnop_git.bb


SUMMARY = "libnop: C++ Native Object Protocols"
HOMEPAGE = "https://github.com/luxonis/libnop"

LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://LICENSE;md5=4e5640559f0849cf863b1dc47bac078b"

# See: https://github.com/luxonis/depthai-core/blob/v2.15.2/cmake/Hunter/config.cmake
SRC_URI = "git://github.com/luxonis/libnop.git;branch=develop"
SRCREV = "ec8f75aa4df3454f73b5d7a7fe0680f3701b1744"

S = "${WORKDIR}/git"

inherit cmake
bartoszptak commented 1 year ago

Hi @windelbouwman ! Thank you for your code, it works well on VCK190 with Petalinux. Is the code anywhere available as a GitHub meta-repository? If not, can I create one with reference to your comment?