cpp-pm / hunter

CMake driven cross-platform package manager for C/C++.
BSD 2-Clause "Simplified" License
613 stars 181 forks source link

/usr/bin/ld: /home/sahoo/.hunter/_Base/cb0ea1f/a3a48bb/b64ffe3/Install/lib/libz.a(zutil.c.o): relocation R_X86_64_PC32 against symbol `z_errmsg' can not be used when making a shared object; recompile with -fPIC #678

Closed gauravsahooo closed 1 year ago

gauravsahooo commented 1 year ago

Hi,

I am getting the below-linking error while compiling ORB_SLAM. I observe that zutil is a part of hunter package it is not built with -fPIC flag, Could you please help me with the work-around

/usr/bin/ld: /home/sahoo/.hunter/_Base/cb0ea1f/a3a48bb/b64ffe3/Install/lib/libz.a(zutil.c.o): relocation R_X86_64_PC32 against symbol `z_errmsg' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: final link failed: bad value collect2: error: ld returned 1 exit status make[2]: [CMakeFiles/ORB_SLAM3.dir/build.make:537: ../lib/libORB_SLAM3.so] Error 1 make[1]: [CMakeFiles/Makefile2:531: CMakeFiles/ORB_SLAM3.dir/all] Error 2 make: *** [Makefile:130: all] Error 2

NeroBurner commented 1 year ago

you can try using a CMakeToolchain.cmake file where you set the set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) variable

https://hunter.readthedocs.io/en/latest/overview/customization/toolchain-id.html?highlight=fpic#simple-toolchains

gauravsahooo commented 1 year ago

I am building ORB_SLAM & while building ORB_SLAM this linking error is coming while linking with Depthai-core using Hunter.

I applied your suggested change inside CMakeLists.txt & toolchain.cmake but it is not working for me.

set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)

Could you please help !

[ 64%] Built target depthai-core [ 64%] Building CXX object Thirdparty/depthai-core/CMakeFiles/depthai-opencv.dir/src/opencv/ImgFrame.cpp.o [ 65%] Linking CXX static library libdepthai-opencv.a [ 65%] Built target depthai-opencv [ 65%] Linking CXX shared library ../lib/libORB_SLAM3.so

/usr/bin/ld: /home/sahoo/.hunter/_Base/cb0ea1f/a3a48bb/b64ffe3/Install/lib/libz.a(zutil.c.o): relocation R_X86_64_PC32 against symbol `z_errmsg' can not be used when making a shared object; recompile with -fPIC/usr/bin/ld: final link failed: bad value collect2: error: ld returned 1 exit status make[2]: [CMakeFiles/ORB_SLAM3.dir/build.make:537: ../lib/libORB_SLAM3.so] Error 1 make[1]: [CMakeFiles/Makefile2:531: CMakeFiles/ORB_SLAM3.dir/all] Error 2 make: *** [Makefile:130: all] Error 2

On Fri, Jun 9, 2023 at 3:09 PM NeroBurner @.***> wrote:

you can try using a CMakeToolchain.cmake file where you set the set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) variable

https://hunter.readthedocs.io/en/latest/overview/customization/toolchain-id.html?highlight=fpic#simple-toolchains

— Reply to this email directly, view it on GitHub https://github.com/cpp-pm/hunter/issues/678#issuecomment-1584552289, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWD2KC7N3MTNDM3TYL5Q4GLXKMOBFANCNFSM6AAAAAAZASTZRA . You are receiving this because you authored the thread.Message ID: @.***>

-- Thanks Gaurav Sahoo

NeroBurner commented 1 year ago

Please create a minimal example project reproducing your error. I think the following should be enough, but add more files if necessary

Provide information about the used build environment, like OS/Distro used, the compiler version, the cmake version, the hunter version

Provide the exact commands to reproduce the error with your example project

gauravsahooo commented 1 year ago

Hi Team,

I followed all steps which are recommended by you, It seems Hunter is downloading & extracting pre-build library libz.a . Could you please have a quick look at the logs & share your suggestions?

In case if hunter are using pre-build library which is not build with -fPIC flag then what should be the work-around.?

CMake version 3.16.3 Ubuntu 20.04.6 LTS Release: 20.04 Hunter version - ver.: 3.9.1

Regards, Gaurav

On Fri, Jun 9, 2023 at 7:10 PM NeroBurner @.***> wrote:

Please create a minimal example project reproducing your error. I think the following should be enough, but add more files if necessary

  • CMakeLists.txt
  • main.cpp
  • toolchain.cmake

Provide information about the used build environment, like OS/Distro used, the compiler version, the cmake version, the hunter version

Provide the exact commands to reproduce the error with your example project

— Reply to this email directly, view it on GitHub https://github.com/cpp-pm/hunter/issues/678#issuecomment-1584901273, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWD2KC66C5ZEKTUYATQGBITXKNKHNANCNFSM6AAAAAAZASTZRA . You are receiving this because you authored the thread.Message ID: @.***>

-- Thanks Gaurav Sahoo

Configuring and building Thirdparty/DBoW2 ... -- Configuring done -- Generating done -- Build files have been written to: /home/sahoo/Desktop/WD/virtual-guidedog/Localization/ORB_SLAM3/Thirdparty/DBoW2/build [100%] Built target DBoW2 Configuring and building Thirdparty/g2o ... -- BUILD TYPE:Release -- Compiling on Unix -- Configuring done -- Generating done -- Build files have been written to: /home/sahoo/Desktop/WD/virtual-guidedog/Localization/ORB_SLAM3/Thirdparty/g2o/build [100%] Built target g2o Configuring and building Thirdparty/Sophus ... -- Configuring done -- Generating done -- Build files have been written to: /home/sahoo/Desktop/WD/virtual-guidedog/Localization/ORB_SLAM3/Thirdparty/Sophus/build [ 16%] Built target test_so2 [ 16%] Built target test_rxso2 [ 25%] Built target test_common [ 33%] Built target test_geometry [ 41%] Built target test_sim2 [ 50%] Built target test_se2 [ 58%] Built target test_velocities [ 66%] Built target test_se3 [ 75%] Built target test_rxso3 [ 83%] Built target HelloSO3 [ 91%] Built target test_so3 [100%] Built target test_sim3 Uncompress vocabulary ... Configuring and building ORB_SLAM3 ... -- Using existing generated toolchain -- Using toolchain file: /home/sahoo/Desktop/WD/virtual-guidedog/Localization/ORB_SLAM3/build/Thirdparty/depthai-core/generated/toolchain.cmake -- [hunter] Calculating Toolchain-SHA1 -- [hunter] Calculating Config-SHA1 -- [hunter] HUNTER_ROOT: /home/sahoo/.hunter -- [hunter] [ Hunter-ID: cb0ea1f | Toolchain-ID: a3a48bb | Config-ID: 079a0bf ] -- [hunter] NLOHMANN_JSON_ROOT: /home/sahoo/.hunter/_Base/cb0ea1f/a3a48bb/079a0bf/Install (ver.: 3.9.1) -- [hunter] XLINK_ROOT: /home/sahoo/.hunter/_Base/cb0ea1f/a3a48bb/079a0bf/Install (ver.: luxonis-2021.4.2-develop) -- [hunter] BZIP2_ROOT: /home/sahoo/.hunter/_Base/cb0ea1f/a3a48bb/079a0bf/Install (ver.: 1.0.8-p0) -- [hunter] FP16_ROOT: /home/sahoo/.hunter/_Base/cb0ea1f/a3a48bb/079a0bf/Install (ver.: luxonis-0.0.0) -- [hunter] LIBARCHIVE-LUXONIS_ROOT: /home/sahoo/.hunter/_Base/cb0ea1f/a3a48bb/079a0bf/Install (ver.: hunter-3.5.2) -- [hunter] SPDLOG_ROOT: /home/sahoo/.hunter/_Base/cb0ea1f/a3a48bb/079a0bf/Install (ver.: 1.8.2) -- [hunter] ZLIB_ROOT: /home/sahoo/.hunter/_Base/cb0ea1f/a3a48bb/079a0bf/Install (ver.: 1.2.11-p2) -- [hunter] BACKWARD_ROOT: /home/sahoo/.hunter/_Base/cb0ea1f/a3a48bb/079a0bf/Install (ver.: 1.6) -- [hunter] LIBNOP_ROOT: /home/sahoo/.hunter/_Base/cb0ea1f/a3a48bb/079a0bf/Install (ver.: 1.0-ec8f75a) -- Checking file: /home/sahoo/Desktop/WD/virtual-guidedog/Localization/ORB_SLAM3/Thirdparty/depthai-core/shared/depthai-shared/src/datatype/DatatypeEnum.cpp -- Checking file: /home/sahoo/Desktop/WD/virtual-guidedog/Localization/ORBSLAM3/Thirdparty/depthai-core/shared/depthai-shared/src/utility/Checksum.cpp -- Performing Test FLAG-Wformat=2 -- Performing Test FLAG-Wformat=2 - Success -- Performing Test FLAG-Werror=self-assign-field -- Performing Test FLAG-Werror=self-assign-field - Failed -- Performing Test FLAG-Werror=unused-lambda-capture -- Performing Test FLAG-Werror=unused-lambda-capture - Failed -- Performing Test FLAG-Werror=return-type -- Performing Test FLAG-Werror=return-type - Success -- Performing Test FLAG-Werror=non-virtual-dtor -- Performing Test FLAG-Werror=non-virtual-dtor - Success -- Performing Test FLAG-Werror=sign-compare -- Performing Test FLAG-Werror=sign-compare - Success -- Performing Test FLAG-Werror=reorder -- Performing Test FLAG-Werror=reorder - Success -- Performing Test FLAG-Werror=switch-enum -- Performing Test FLAG_-Werror=switch-enum - Success -- Compiling depthai-core resources in PATCH_ONLY mode -- Downloading Depthai device side binaries from server... -- Downloading depthai and patch -- commit: aa3e0564c0de3ef66cb6b240ff2b65ed3ed70aba -- File already downloaded (resources): depthai-shared-commit-hash-3575b77f20e796b4e79953bf3d2ba22f0416ee8b.txt -- depthai-shared between device and host MATCH!. (device: aa3e0564c0de3ef66cb6b240ff2b65ed3ed70aba, host: aa3e0564c0de3ef66cb6b240ff2b65ed3ed70aba -- Downloading and checking depthai-device-fwp.tar.xz -- File already downloaded (resources): depthai-device-fwp-3575b77f20e796b4e79953bf3d2ba22f0416ee8b.tar.xz -- Downloading depthai bootloader -- folder: /home/sahoo/Desktop/WD/virtual-guidedog/Localization/ORB_SLAM3/build/Thirdparty/depthai-core/resources -- maturity: release -- commit_version_arg: 0.0.24 -- bootloader shared commit: b287ecbacd3b0c963b5dfcf95767123b0c143b57 -- File already downloaded (resources): depthai-bootloader-shared-commit-hash-0.0.24.txt -- depthai-bootloader-shared between device and host MATCH!. (device: b287ecbacd3b0c963b5dfcf95767123b0c143b57, host: b287ecbacd3b0c963b5dfcf95767123b0c143b57 -- Downloading and checking depthai-bootloader-fwp.tar.xz -- File already downloaded (resources): depthai-bootloader-fwp-0.0.24.tar.xz -- LIST OF RESOURCE COMPILED FILES: /home/sahoo/Desktop/WD/virtual-guidedog/Localization/ORB_SLAM3/build/Thirdparty/depthai-core/resources/depthai-device-fwp-3575b77f20e796b4e79953bf3d2ba22f0416ee8b.tar.xz;/home/sahoo/Desktop/WD/virtual-guidedog/Localization/ORB_SLAM3/build/Thirdparty/depthai-core/resources/depthai-bootloader-fwp-0.0.24.tar.xz -- ClangFormat: clang-format not found! Target 'clangformat' not available... -- ClangFormat: clang-format not found! Target 'clangformat' not available... -- OpenCV and required libraries (opencv_core;opencv_imgproc) found. OpenCV Support enabled -- BUILD_DATETIME: 2023-06-13 11:04:06 +0000, BUILD_COMMIT: 125feb8c2e16ee4bf71b7873a7b990f1c5f17b18, BUILD_COMMIT_DATETIME: 2023-04-05 21:24:25 +0300 -- Using flag -std=c++14. -- BUILD TYPE:Release -- Compiling on Unix -- Configuring done -- Generating done -- Build files have been written to: /home/sahoo/Desktop/WD/virtual-guidedog/Localization/ORB_SLAM3/build [ 4%] Built target depthai-resources [ 23%] Built target g2o Scanning dependencies of target depthai-core [ 24%] Building CXX object Thirdparty/depthai-core/CMakeFiles/depthai-core.dir/src/utility/Initialization.cpp.o [ 25%] Linking CXX static library libdepthai-core.a [ 64%] Built target depthai-core [ 65%] Built target depthai-opencv [ 65%] Linking CXX shared library ../lib/libORB_SLAM3.so /usr/bin/ld: /home/sahoo/.hunter/_Base/cb0ea1f/a3a48bb/079a0bf/Install/lib/libz.a(zutil.c.o): relocation R_X86_64_PC32 against symbol `z_errmsg' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: final link failed: bad value collect2: error: ld returned 1 exit status make[2]: [CMakeFiles/ORB_SLAM3.dir/build.make:537: ../lib/libORB_SLAM3.so] Error 1 make[1]: [CMakeFiles/Makefile2:531: CMakeFiles/ORB_SLAM3.dir/all] Error 2 make: *** [Makefile:130: all] Error 2

NeroBurner commented 1 year ago

The current hunter version is https://github.com/cpp-pm/hunter/releases/tag/v0.24.18 So I don't know which Version 3.9.1 should be

I don't see a download in your logs. The hunter-cache you're seeing is probably the local hunter cache.

You can try to remove the default hunter cache folder ~/.hunter and try again. This makes sure there is no local cache.

To be totally sure no cache server is used you can set the variable -DHUNTER_USE_CACHE_SERVERS=NO https://hunter.readthedocs.io/en/latest/reference/user-variables.html#hunter-use-cache-servers

I followed all steps which are recommended by you

Partially, no minimal example project provided, no build commands provided

gauravsahooo commented 1 year ago

Hello Cpp-Pm/Hunter,

Despite attempting various solutions, I regret to inform you that my changes have been ineffective. The build error persists, and I consistently encounter the same issue. Attached is my CMake list, and I kindly request your review and feedback on whether any modifications are necessary. To ensure a clean slate, I have cleared the hunter cache using the command "rm -rf /home/sahoo/.hunter". Upon inspecting the build.log, I did not come across any indication of zlib being built. It appears that the system is utilizing zlib directly from the hunter cache, bypassing the need for building it

usr/bin/ld: /home/sahoo/.hunter/_Base/cb0ea1f/a3a48bb/079a0bf/Install/lib/libz.a(zutil.c.o): relocation R_X86_64_PC32 against symbol `z_errmsg' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: final link failed: bad value collect2: error: ld returned 1 exit status make[2]: [CMakeFiles/ORB_SLAM3.dir/build.make:538: ../lib/libORB_SLAM3.so] Error 1 make[1]: [CMakeFiles/Makefile2:531: CMakeFiles/ORB_SLAM3.dir/all] Error 2 make: *** [Makefile:130: all] Error 2

On Tue, Jun 13, 2023 at 2:47 PM NeroBurner @.***> wrote:

The current hunter version is https://github.com/cpp-pm/hunter/releases/tag/v0.24.18 So I don't know which Version 3.9.1 should be

I don't see a download in your logs. The hunter-cache you're seeing is probably the local hunter cache.

You can try to remove the default hunter cache folder ~/.hunter and try again. This makes sure there is no local cache.

To be totally sure no cache server is used you can set the variable -DHUNTER_USE_CACHE_SERVERS=NO

https://hunter.readthedocs.io/en/latest/reference/user-variables.html#hunter-use-cache-servers

I followed all steps which are recommended by you

Partially, no minimal example project provided, no build commands provided

— Reply to this email directly, view it on GitHub https://github.com/cpp-pm/hunter/issues/678#issuecomment-1589246135, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWD2KCYTOMGVMWDGQG3M2F3XLBOPTANCNFSM6AAAAAAZASTZRA . You are receiving this because you authored the thread.Message ID: @.***>

-- Thanks Gaurav Sahoo

cmake_minimum_required(VERSION 3.4) # For Hunter

MSVC variable isn't available before 'project' call

Generalize to Win32 platform for now

if(NOT WIN32) set(HUNTER_CONFIGURATION_TYPES "Release" CACHE STRING "Hunter dependencies list of build configurations") endif()

set(HUNTER_USE_CACHE_SERVERS NO) # Disable cache servers set(HUNTER_CACHE_SERVERS_NO "") set(HUNTER_CACHE_SERVERS_EXTERNAL "")

if(NOT CMAKE_POSITION_INDEPENDENT_CODE) set(CMAKE_POSITION_INDEPENDENT_CODE ON) endif()

Set type to canonicalize relative paths for user-provided toolchain

set(CMAKE_TOOLCHAIN_FILE "" CACHE FILEPATH "CMake toolchain path")

Create a custom toolchain to pass certain options to dependencies

set(gen_toolchain "${CMAKE_CURRENT_BINARY_DIR}/generated/toolchain.cmake")

if(EXISTS "${gen_toolchain}" AND ("${_INTERNAL_DEPTHAI_ORIGINAL_CMAKE_TOOLCHAIN_FILE}" STREQUAL "${CMAKE_TOOLCHAIN_FILE}" OR NOT "${CMAKE_TOOLCHAIN_FILE}" STREQUAL "")) message(STATUS "Using existing generated toolchain") else() message(STATUS "Generating new toolchain...") configure_file( "${CMAKE_CURRENT_LIST_DIR}/cmake/toolchain/custom.cmake.in" "${gen_toolchain}" @ONLY ) endif()

set(CMAKE_TOOLCHAIN_FILE "${gen_toolchain}" CACHE STRING "" FORCE) if(DEFINED _INTERNAL_DEPTHAI_ORIGINAL_CMAKE_TOOLCHAIN_FILE) message(STATUS "Using specified toolchain file: ${_INTERNAL_DEPTHAI_ORIGINAL_CMAKE_TOOLCHAIN_FILE} combined into: ${CMAKE_TOOLCHAIN_FILE}") else() message(STATUS "Using toolchain file: ${CMAKE_TOOLCHAIN_FILE}") endif()

include("cmake/HunterGate.cmake") HunterGate( URL "https://github.com/cpp-pm/hunter/archive/v0.23.322.tar.gz" SHA1 "cb0ea1f74f4a2c49a807de34885743495fccccbe" LOCAL # Local config for dependencies )

Move binary dir if windows, to shorten the path

if(WIN32) set(HUNTER_BINARY_DIR "${HUNTER_GATE_ROOT}/_bin" CACHE STRING "Hunter binary directory") endif()

Create depthai project

project(depthai VERSION "2.21.2" LANGUAGES CXX C) get_directory_property(has_parent PARENT_DIRECTORY) if(has_parent) set(DEPTHAI_VERSION ${PROJECT_VERSION} PARENT_SCOPE) endif()

Set default build type depending on context

set(default_build_type "Release") if(EXISTS "${CMAKE_SOURCE_DIR}/.git" AND NOT DEFINED ENV{CI}) set(default_build_type "Debug") endif() if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) message(STATUS "Setting build type to '${default_build_type}' as none was specified.") set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build." FORCE)

Set the possible values of build type for cmake-gui

set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")

endif()

Set default installation directory

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Installation Directory" FORCE) endif()

Set policies

CMP0074 dictates that find_package searches environment variable "[packageName]_ROOT" along with regular variable [packageName]_ROOT

if(POLICY CMP0074) cmake_policy(SET CMP0074 NEW) # Only introduced in 3.12 endif()

if(POLICY CMP0028) cmake_policy(SET CMP0028 NEW) endif()

Set to export compile commands for tools like clang-tidy and format

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

Add module path

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/sanitizers")

Additional options

option(DEPTHAI_CLANG_FORMAT "Enable clang-format target" ON) option(DEPTHAI_CLANG_TIDY "Enable clang-tidy checks during compilation" OFF) option(DEPTHAI_SANITIZE "Enable Address and Undefined sanitizers for library, examples and tests" OFF)

Should install depthai core libraries

option(DEPTHAI_INSTALL "Enable install target for depthai-core targets" ON)

Debug option

set(DEPTHAI_XLINK_LOCAL "" CACHE STRING "Path to local XLink source to use instead of Hunter") set(DEPTHAI_SHARED_LOCAL "" CACHE STRING "Path to local depthai-shared source to use instead of submodule") set(DEPTHAI_BOOTLOADER_SHARED_LOCAL "" CACHE STRING "Path to local depthai-bootloader-shared source to use instead of submodule")

Enable backward stack printing on crash

if(ANDROID)

Backward not supported currently on Android

set(DEPTHAI_ENABLE_BACKWARD OFF CACHE BOOL "" FORCE)

else() option(DEPTHAI_ENABLE_BACKWARD "Enable stacktrace printing on crash using Backward" ON)

Additional function information for 'backward' stacktrace

if(DEPTHAI_ENABLE_BACKWARD)
    set(CMAKE_ENABLE_EXPORTS ON)
endif()

endif()

Force Colored output when using Ninja

Global option - affects all targets

option(FORCE_COLORED_OUTPUT "Always produce ANSI-colored output (GNU/Clang only)" OFF) if(FORCE_COLORED_OUTPUT) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") add_compile_options(-fdiagnostics-color=always) elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") add_compile_options(-fcolor-diagnostics) endif() endif()

Specify exporting all symbols on Windows

if(WIN32 AND BUILD_SHARED_LIBS) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON CACHE BOOL "") endif()

Constants

set(PROJECT_EXPORT_GROUP "${PROJECT_NAME}Targets")

Check if cloned or sources

find_package(Git) if(GIT_FOUND) execute_process( COMMAND ${GIT_EXECUTABLE} rev-parse --show-toplevel WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} RESULT_VARIABLE _git_root_dir_error OUTPUT_VARIABLE _git_root_dir ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE ) set(DEPTHAI_DOWNLOADED_SOURCES ON) if(_git_root_dir_error EQUAL 0 AND "${_git_root_dir}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}") set(DEPTHAI_DOWNLOADED_SOURCES OFF) endif() message(DEBUG "Git root dir (${_git_root_dir_error}): ${_git_root_dir}") message(DEBUG "DepthAI as downloaded sources: ${DEPTHAI_DOWNLOADED_SOURCES}") execute_process( COMMAND ${GIT_EXECUTABLE} rev-parse HEAD WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} OUTPUT_VARIABLE BUILD_COMMIT ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE ) execute_process( COMMAND ${GIT_EXECUTABLE} show -s --format=%ci ${BUILD_COMMIT} WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} OUTPUT_VARIABLE BUILD_COMMIT_DATETIME ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE ) endif()

Get and find dependencies

Include project dependencies

set(DEPTHAI_DEPENDENCY_INCLUDE "" CACHE FILEPATH "Optional cmake file to append to dependency processing, e.g. additional find_package()") include(depthaiDependencies)

Add threads preference

set(THREADS_PREFER_PTHREAD_FLAG ON)

Add depthai-shared, and definitions that it is PC side

include(${CMAKE_CURRENT_LIST_DIR}/shared/depthai-shared.cmake)

Add depthai-bootloader-shared

include(${CMAKE_CURRENT_LIST_DIR}/shared/depthai-bootloader-shared.cmake)

Add flags helpers

include(Flags)

End of dependencies

set(TARGET_CORE_NAME ${PROJECT_NAME}-core) set(TARGET_CORE_ALIAS core)

Create core library

add_library(${TARGET_CORE_NAME}

depthai-shared sources

"${DEPTHAI_SHARED_SOURCES}"
# depthai-bootloader-shared sources
"${DEPTHAI_BOOTLOADER_SHARED_SOURCES}"
# sources
src/device/Device.cpp
src/device/DeviceBase.cpp
src/device/DeviceBootloader.cpp
src/device/DataQueue.cpp
src/device/CallbackHandler.cpp
src/device/CalibrationHandler.cpp
src/device/Version.cpp
src/pipeline/Pipeline.cpp
src/pipeline/AssetManager.cpp
src/pipeline/Node.cpp
src/pipeline/node/XLinkIn.cpp
src/pipeline/node/XLinkOut.cpp
src/pipeline/node/ColorCamera.cpp
src/pipeline/node/Camera.cpp
src/pipeline/node/MonoCamera.cpp
src/pipeline/node/StereoDepth.cpp
src/pipeline/node/NeuralNetwork.cpp
src/pipeline/node/ImageManip.cpp
src/pipeline/node/Warp.cpp
src/pipeline/node/VideoEncoder.cpp
src/pipeline/node/DetectionNetwork.cpp
src/pipeline/node/Script.cpp
src/pipeline/node/SpatialDetectionNetwork.cpp
src/pipeline/node/SystemLogger.cpp
src/pipeline/node/SpatialLocationCalculator.cpp
src/pipeline/node/AprilTag.cpp
src/pipeline/node/ObjectTracker.cpp
src/pipeline/node/IMU.cpp
src/pipeline/node/EdgeDetector.cpp
src/pipeline/node/SPIIn.cpp
src/pipeline/node/FeatureTracker.cpp
src/pipeline/node/DetectionParser.cpp
src/pipeline/datatype/Buffer.cpp
src/pipeline/datatype/ImgFrame.cpp
src/pipeline/datatype/ImageManipConfig.cpp
src/pipeline/datatype/CameraControl.cpp
src/pipeline/datatype/NNData.cpp
src/pipeline/datatype/ImgDetections.cpp
src/pipeline/datatype/SpatialImgDetections.cpp
src/pipeline/datatype/SystemInformation.cpp
src/pipeline/datatype/StreamMessageParser.cpp
src/pipeline/datatype/SpatialLocationCalculatorData.cpp
src/pipeline/datatype/SpatialLocationCalculatorConfig.cpp
src/pipeline/datatype/AprilTags.cpp
src/pipeline/datatype/AprilTagConfig.cpp
src/pipeline/datatype/Tracklets.cpp
src/pipeline/datatype/IMUData.cpp
src/pipeline/datatype/StereoDepthConfig.cpp
src/pipeline/datatype/EdgeDetectorConfig.cpp
src/pipeline/datatype/TrackedFeatures.cpp
src/pipeline/datatype/FeatureTrackerConfig.cpp
src/utility/Initialization.cpp
src/utility/Resources.cpp
src/utility/Path.cpp
src/utility/Platform.cpp
src/utility/Environment.cpp
src/xlink/XLinkConnection.cpp
src/xlink/XLinkStream.cpp
src/openvino/OpenVINO.cpp
src/openvino/BlobReader.cpp
src/bspatch/bspatch.c

) add_library("${PROJECT_NAME}::${TARGET_CORE_ALIAS}" ALIAS ${TARGET_CORE_NAME})

Specify that we are building core

target_compile_definitions(${TARGET_CORE_NAME} PUBLIC DEPTHAI_TARGET_CORE)

Specifies name of generated IMPORTED target (set to alias)

set_target_properties(${TARGET_CORE_NAME} PROPERTIES EXPORT_NAME ${TARGET_CORE_ALIAS})

Add to list of targets to export and install

list(APPEND targets_to_export ${TARGET_CORE_NAME})

Add default flags to core

add_default_flags(${TARGET_CORE_NAME})

And clang-tidy and format

if(DEPTHAI_CLANG_TIDY) include(ClangTidy) target_clangtidy_setup(${TARGET_CORE_NAME}) endif()

Set compiler features (c++14), and disables extensions (g++14)

set_property(TARGET ${TARGET_CORE_NAME} PROPERTY CXX_STANDARD 14) set_property(TARGET ${TARGET_CORE_NAME} PROPERTY CXX_STANDARD_REQUIRED ON) set_property(TARGET ${TARGET_CORE_NAME} PROPERTY CXX_EXTENSIONS OFF)

Add interface transitive property (C++14)

if(${CMAKE_VERSION} VERSION_LESS "3.8.0") target_compile_features(${TARGET_CORE_NAME} INTERFACE cxx_generic_lambdas) else() target_compile_features(${TARGET_CORE_NAME} INTERFACE cxx_std_14) endif()

First specify options

option(DEPTHAI_BUILD_TESTS "Build tests" OFF) option(DEPTHAI_BUILD_EXAMPLES "Build examples - Requires OpenCV library to be installed" OFF) option(DEPTHAI_BUILD_DOCS "Build documentation - requires doxygen to be installed" OFF) option(DEPTHAI_OPENCV_SUPPORT "Enable optional OpenCV support" ON)

option(DEPTHAI_BINARIES_RESOURCE_COMPILE "Compile Depthai device side binaries into library" ON) option(DEPTHAI_USB2_PATCH_ONLY_MODE "Use patch file and full depthai.cmd binary for usb2 mode" ON) option(DEPTHAI_CMD_PATH "Use local path for depthai.cmd instead of downloading" OFF) if(DEPTHAI_USB2_PATCH_ONLY_MODE) option(DEPTHAI_USB2_PATCH_PATH "Use local path for depthai-usb2-patch.patch instead of downloading" OFF) else() option(DEPTHAI_USB2_CMD_PATH "Use local path for depthai-usb2.cmd instead of downloading" OFF) endif()

if(DEPTHAI_USB2_PATCH_ONLY_MODE) message(STATUS "Compiling ${TARGET_CORE_NAME} resources in PATCH_ONLY mode") else() message(STATUS "Compiling ${TARGET_CORE_NAME} depthai and depthai-usb2 resources") endif()

Set constant

set(DEPTHAI_RESOURCES_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/resources")

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) set(DEPTHAI_BOOTLOADER_SHARED_COMMIT_HASH_ENFORCE ON) endif()

Then get the Depthai device side binaries (local or download)

if(DEPTHAI_CMD_PATH OR DEPTHAI_USB2_CMD_PATH OR DEPTHAI_USB2_PATCH_PATH)

At least 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})

message(STATUS "LIST OF RESOURCE COMPILED FILES: ${RESOURCE_COMPILED_FILES}")

if(DEPTHAI_BINARIES_RESOURCE_COMPILE)

Add RC and resource compile the binares

include(CMakeRC)

set(DEPTHAI_RESOURCE_LIBRARY_NAME "depthai-resources")

# Add resource library
cmrc_add_resource_library("${DEPTHAI_RESOURCE_LIBRARY_NAME}" NAMESPACE depthai
    WHENCE "${DEPTHAI_RESOURCES_OUTPUT_DIR}"
    "${RESOURCE_COMPILED_FILES}"
)

# Link to resource library
target_link_libraries(${TARGET_CORE_NAME} PRIVATE "${DEPTHAI_RESOURCE_LIBRARY_NAME}")

# Set define that binaries are resource compiled
target_compile_definitions(${TARGET_CORE_NAME} PRIVATE DEPTHAI_RESOURCE_COMPILED_BINARIES)

else()

TODO

# Don't add RC and don't resource compile the binaries

endif()

Add include directories

target_include_directories(${TARGET_CORE_NAME} PUBLIC

Relative path to include directories after installed

    "$<INSTALL_INTERFACE:include>"
    "$<INSTALL_INTERFACE:include/${DEPTHAI_SHARED_3RDPARTY_HEADERS_PATH}>"

    # Build time path to include directories
    "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
    "$<BUILD_INTERFACE:${DEPTHAI_SHARED_PUBLIC_INCLUDE}>"
    "$<BUILD_INTERFACE:${DEPTHAI_BOOTLOADER_SHARED_PUBLIC_INCLUDE}>"
#INTERFACE
#    # ...
PRIVATE
    "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include/depthai>"
    "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/src>"
    "$<BUILD_INTERFACE:${DEPTHAI_SHARED_INCLUDE}>"
    "$<BUILD_INTERFACE:${DEPTHAI_BOOTLOADER_SHARED_INCLUDE}>"

)

target_include_directories(${TARGET_CORE_NAME} SYSTEM PUBLIC "$<BUILD_INTERFACE:${DEPTHAI_SHARED_3RDPARTY_INCLUDE}>" )

Add clang format after specifying include directories

if(DEPTHAI_CLANG_FORMAT)

HEADER DIRECTORIES

set(header_dirs "${CMAKE_CURRENT_LIST_DIR}/include" "${DEPTHAI_SHARED_PUBLIC_INCLUDE}" "${DEPTHAI_SHARED_INCLUDE}")
include(ClangFormat)
target_clangformat_setup(${TARGET_CORE_NAME} "${header_dirs}")

endif()

link libraries

target_link_libraries(${TARGET_CORE_NAME} PUBLIC nlohmann_json::nlohmann_json libnop INTERFACE XLinkPublic PRIVATE XLink Threads::Threads BZip2::bz2 FP16::fp16 archive_static spdlog::spdlog ZLIB::zlib )

Add compile & CMake definitions

set(DEPTHAI_DEVICE_VERSION "${DEPTHAI_DEVICE_SIDE_COMMIT}") target_compile_definitions(${TARGET_CORE_NAME} PRIVATE

XLink required define

    __PC__
    # Add depthai-device version
    DEPTHAI_DEVICE_VERSION="${DEPTHAI_DEVICE_VERSION}"
    # Add depthai-bootloader version
    DEPTHAI_BOOTLOADER_VERSION="${DEPTHAI_BOOTLOADER_VERSION}"

)

Add Backward dependency if enabled (On by default)

if(DEPTHAI_ENABLE_BACKWARD) target_compile_definitions(${TARGET_CORE_NAME} PRIVATE DEPTHAI_ENABLE_BACKWARD) target_link_libraries(${TARGET_CORE_NAME} PRIVATE Backward::Backward) endif()

Add patch only mode definition

if(DEPTHAI_USB2_PATCH_ONLY_MODE) target_compile_definitions(${TARGET_CORE_NAME} PRIVATE DEPTHAI_PATCH_ONLY_MODE) endif()

Helper function

macro(add_runtime_dependencies depending_target dependency) if(WIN32) if(TARGET ${dependency}) get_property(imported_configs TARGET ${dependency} PROPERTY IMPORTED_CONFIGURATIONS) set(dlls "") foreach(cfg ${imported_configs}) get_property(dll TARGET ${dependency} PROPERTY IMPORTEDLOCATION${cfg}) set(dlls ${depthai_dll_libraries} $<$<CONFIG:${cfg}>:${dll}>) endforeach() endif() file(GLOB depthai_dll_libraries "${HUNTER_INSTALL_PREFIX}/bin/*.dll")

Create a list of required dll files

    set(required_dll_files ${dlls} ${depthai_dll_libraries})
    # Copy the required dlls
    add_custom_command(TARGET ${depending_target} POST_BUILD COMMAND
        ${CMAKE_COMMAND} -E copy_if_different ${required_dll_files} $<TARGET_FILE_DIR:${depending_target}>
        COMMAND_EXPAND_LISTS
    )
    message(STATUS "Required dlls for core are: ${required_dll_files}")
endif()

endmacro()

Add libusb dll in build time

add_runtime_dependencies(${TARGET_CORE_NAME} usb-1.0)

########################

OpenCV Support

######################## set(THIRDPARTY_OPENCV_LIBRARIES "" CACHE STRING "Optional libraries to link OpenCV support, e.g. TBB::tbb") set(TARGET_OPENCV_NAME ${PROJECT_NAME}-opencv) set(TARGET_OPENCV_ALIAS opencv) if(DEPTHAI_OPENCV_SUPPORT)

Check if required libraries are available

set(REQUIRED_OPENCV_LIBRARIES "opencv_core" "opencv_imgproc")
set(OPENCV_SUPPORT_AVAILABLE ${OpenCV_FOUND})
foreach(lib ${REQUIRED_OPENCV_LIBRARIES})
    if(NOT (lib IN_LIST OpenCV_LIBS))
        set(OPENCV_SUPPORT_AVAILABLE FALSE)
    endif()
endforeach()

if(OPENCV_SUPPORT_AVAILABLE)

    # Add depthai-core-opencv library and depthai::core::opencv alias
    add_library(${TARGET_OPENCV_NAME} src/opencv/ImgFrame.cpp)
    add_library("${PROJECT_NAME}::${TARGET_OPENCV_ALIAS}" ALIAS ${TARGET_OPENCV_NAME})
    # Specifies name of generated IMPORTED target (set to alias)
    set_target_properties(${TARGET_OPENCV_NAME} PROPERTIES EXPORT_NAME ${TARGET_OPENCV_ALIAS})

    # Add default flags
    add_default_flags(${TARGET_OPENCV_NAME})
    add_flag(${TARGET_OPENCV_NAME} -Wno-switch-enum)

    # Link to OpenCV (publically)
    target_link_libraries(${TARGET_OPENCV_NAME} PUBLIC ${REQUIRED_OPENCV_LIBRARIES} ${THIRDPARTY_OPENCV_LIBRARIES})

    # Add public compile definition indicating that OpenCV support is available
    set(DEPTHAI_HAVE_OPENCV_SUPPORT ON)

    # Specify that we are building target opencv
    target_compile_definitions(${TARGET_OPENCV_NAME} PUBLIC DEPTHAI_TARGET_OPENCV)

    # Add public dependency to depthai::core library
    target_link_libraries(${TARGET_OPENCV_NAME} PUBLIC ${TARGET_CORE_NAME})

    # Add to clangformat target
    if(COMMAND target_clangformat_setup)
        target_clangformat_setup(${TARGET_OPENCV_NAME} "")
    endif()

    # Add to list of targets to export and install
    list(APPEND targets_to_export ${TARGET_OPENCV_NAME})

    message(STATUS "OpenCV and required libraries (${REQUIRED_OPENCV_LIBRARIES}) found. OpenCV Support enabled")

else()
    message(STATUS "OpenCV or required libraries (${REQUIRED_OPENCV_LIBRARIES}) not found. OpenCV Support disabled")
endif()

endif()

########################

Sanitizers

######################## if(DEPTHAI_SANITIZE) set(SANITIZE_ADDRESS ON CACHE BOOL "Enable AddressSanitizer for sanitized targets." FORCE) set(SANITIZE_UNDEFINED ON CACHE BOOL "Enable UndefinedBehaviorSanitizer for sanitized targets." FORCE) find_package(Sanitizers) add_sanitizers(${TARGET_CORE_NAME}) if(DEPTHAI_HAVE_OPENCV_SUPPORT) add_sanitizers(${TARGET_OPENCV_NAME}) endif() if(DEPTHAI_XLINK_LOCAL) add_sanitizers(XLink) if(XLINK_LIBUSB_LOCAL) add_sanitizers(usb-1.0) endif() endif() endif()

########################

Testing infrastructure

######################## include(CTest) enable_testing()

########################

Tests

######################## if (DEPTHAI_BUILD_TESTS) add_subdirectory(tests) endif()

########################

Examples (can also act as tests)

######################## if (DEPTHAI_BUILD_EXAMPLES) add_subdirectory(examples) endif()

########################

Documentation

######################## if (DEPTHAI_BUILD_DOCS) add_subdirectory(docs) endif()

########################

Build configuration

########################

Add year information

string(TIMESTAMP BUILD_DATETIME "%Y-%m-%d %H:%M:%S +0000" UTC) message(STATUS "BUILD_DATETIME: ${BUILD_DATETIME}, BUILD_COMMIT: ${BUILD_COMMIT}, BUILD_COMMIT_DATETIME: ${BUILD_COMMIT_DATETIME}")

Configure build information (version, opencv support)

configure_file("${CMAKE_CURRENT_LIST_DIR}/cmake/version.hpp.in" "${CMAKE_CURRENT_LIST_DIR}/include/depthai/build/version.hpp") configure_file("${CMAKE_CURRENT_LIST_DIR}/cmake/config.hpp.in" "${CMAKE_CURRENT_LIST_DIR}/include/depthai/build/config.hpp")

########################

Export and install

######################## include(GNUInstallDirs) include(CMakePackageConfigHelpers)

Add additional targets to export group

if(NOT BUILD_SHARED_LIBS) list(APPEND targets_to_export ${DEPTHAI_RESOURCE_LIBRARY_NAME} cmrc-base) endif()

Export targets (capability to import current build directory)

export(TARGETS ${targets_to_export} NAMESPACE ${PROJECT_NAME}:: FILE "${PROJECT_NAME}Targets.cmake")

Dependencies file

configure_file("cmake/${PROJECT_NAME}Dependencies.cmake" ${PROJECT_NAME}Dependencies.cmake COPYONLY)

Write project version

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)

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)

Config for installation

set(DEPTHAI_DEPENDENCIES_INSTALLATION_PATH_REL "./dependencies") configure_file(cmake/${PROJECT_NAME}Config.cmake.in _install/${PROJECT_NAME}Config.cmake @ONLY)

Modify RPath to point to the cmake/depthai/dependencies/lib

note: macOS is APPLE and also UNIX!

if(APPLE) set_target_properties(${TARGET_CORE_NAME} PROPERTIES INSTALL_RPATH @.**@._path/cmake/${PROJECT_NAME}/dependencies/lib") elseif(UNIX) set_target_properties(${TARGET_CORE_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN:$ORIGIN/cmake/${PROJECT_NAME}/dependencies/lib") endif()

Export to CMake registry if specified

if(CMAKE_EXPORT_PACKAGE_REGISTRY) export(PACKAGE depthai) endif()

if(DEPTHAI_INSTALL)

# Install targets
install(
    TARGETS ${targets_to_export}
    EXPORT ${PROJECT_EXPORT_GROUP}
    RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
    LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
    ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)

# Install depthai public headers
install(DIRECTORY include/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
# Install depthai-shared public headers
install(DIRECTORY "${DEPTHAI_SHARED_PUBLIC_INCLUDE}/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
# Install depthai-shared 3rdparty headers
install(DIRECTORY "${DEPTHAI_SHARED_3RDPARTY_INCLUDE}/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${DEPTHAI_SHARED_3RDPARTY_HEADERS_PATH}")
# Install depthai-bootloader-shared public headers
install(DIRECTORY "${DEPTHAI_BOOTLOADER_SHARED_PUBLIC_INCLUDE}/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
# Install Hunter dependencies
install(DIRECTORY "${HUNTER_INSTALL_PREFIX}/" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}/dependencies")
# Install resources if not RC'd
if(NOT DEPTHAI_BINARIES_RESOURCE_COMPILE)
    install(DIRECTORY "${DEPTHAI_RESOURCES_OUTPUT_DIR}/" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}")
endif()
# Install any required dll files
if(DEFINED required_dll_files)
    install(FILES ${required_dll_files} DESTINATION "${CMAKE_INSTALL_BINDIR}")
endif()

# Install export group (information about targets)
install(EXPORT ${PROJECT_EXPORT_GROUP}
    NAMESPACE ${PROJECT_NAME}::
    DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)

# Install CMake specific files
install(FILES
    "${CMAKE_CURRENT_BINARY_DIR}/_install/${PROJECT_NAME}Config.cmake"
    "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
    "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Dependencies.cmake"
    DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)

endif()

##############################

Integration settings export

############################## set(tmp_definitions "$<TARGET_PROPERTY:${TARGET_CORE_NAME},INTERFACE_COMPILE_DEFINITIONS>") set(tmp_includes "$<TARGET_PROPERTY:${TARGET_CORE_NAME},INTERFACE_INCLUDE_DIRECTORIES>") file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/depthai-core-integration.txt" CONTENT "$<$<BOOL:${tmp_definitions}>:\n-D\'$<JOIN:${tmp_definitions},\'\n-D\'>\'>\n $<$<BOOL:${tmp_includes}>:\n-I\'$<JOIN:${tmp_includes},\'\n-I\'>\'>\n" )

if(DEPTHAI_HAVE_OPENCV_SUPPORT) set(tmp_definitions "$<TARGET_PROPERTY:${TARGET_OPENCV_NAME},INTERFACE_COMPILE_DEFINITIONS>") set(tmp_includes "$<TARGET_PROPERTY:${TARGET_OPENCV_NAME},INTERFACE_INCLUDE_DIRECTORIES>") file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/depthai-opencv-integration.txt" CONTENT "$<$<BOOL:${tmp_definitions}>:\n-D\'$<JOIN:${tmp_definitions},\'\n-D\'>\'>\n $<$<BOOL:${tmp_includes}>:\n-I\'$<JOIN:${tmp_includes},\'\n-I\'>\'>\n" ) endif() cmake_minimum_required(VERSION 3.0) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/Thirdparty/depthai-core EXCLUDE_FROM_ALL) project(ORB_SLAM3)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DZLIB_INCLUDE_DIRS=/usr/include -DZLIB_LIBRARIES=/usr/local/lib64/libz.so")

IF(NOT CMAKE_BUILD_TYPE) SET(CMAKE_BUILD_TYPE Release) ENDIF()

MESSAGE("Build type: " ${CMAKE_BUILD_TYPE})

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O3 -fPIC") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O3 -fPIC") set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -march=native") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -march=native")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")

set(HUNTER_USE_CACHE_SERVERS NO) # Disable cache servers set(HUNTER_CACHE_SERVERS_NO "") set(HUNTER_CACHE_SERVERS_EXTERNAL "")

if(NOT CMAKE_POSITION_INDEPENDENT_CODE) set(CMAKE_POSITION_INDEPENDENT_CODE ON) endif()

set(depthai_DIR "${PROJECT_SOURCE_DIR}/Thirdparty/depthai/build")

add_definitions(-w)

Check C++14 or C++0x support

include(CheckCXXCompilerFlag) CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX11) CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X) if(COMPILER_SUPPORTS_CXX11) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") add_definitions(-DCOMPILEDWITHC11) message(STATUS "Using flag -std=c++14.") elseif(COMPILER_SUPPORTS_CXX0X) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") add_definitions(-DCOMPILEDWITHC0X) message(STATUS "Using flag -std=c++0x.") else() message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++14 support. Please use a different C++ compiler.") endif()

LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules)

find_package(OpenCV 4.4) if(NOT OpenCV_FOUND) message(FATAL_ERROR "OpenCV > 4.4 not found.") endif()

MESSAGE("OPENCV VERSION:") MESSAGE(${OpenCV_VERSION})

find_package(Eigen3 3.1.0 REQUIRED) find_package(Pangolin REQUIRED) find_package(realsense2)

find_package(depthai CONFIG REQUIRED)

include_directories( ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/include/CameraModels ${PROJECT_SOURCE_DIR}/Thirdparty/Sophus ${EIGEN3_INCLUDE_DIR} ${Pangolin_INCLUDE_DIRS} )

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)

add_library(${PROJECT_NAME} SHARED src/System.cc src/Tracking.cc src/LocalMapping.cc src/LoopClosing.cc src/ORBextractor.cc src/ORBmatcher.cc src/FrameDrawer.cc src/Converter.cc src/MapPoint.cc src/KeyFrame.cc src/Atlas.cc src/Map.cc src/MapDrawer.cc src/Optimizer.cc src/Frame.cc src/KeyFrameDatabase.cc src/Sim3Solver.cc src/Viewer.cc src/ImuTypes.cc src/G2oTypes.cc src/CameraModels/Pinhole.cpp src/CameraModels/KannalaBrandt8.cpp src/OptimizableTypes.cpp src/MLPnPsolver.cpp src/GeometricTools.cc src/TwoViewReconstruction.cc src/Config.cc src/Settings.cc include/System.h include/Tracking.h include/LocalMapping.h include/LoopClosing.h include/ORBextractor.h include/ORBmatcher.h include/FrameDrawer.h include/Converter.h include/MapPoint.h include/KeyFrame.h include/Atlas.h include/Map.h include/MapDrawer.h include/Optimizer.h include/Frame.h include/KeyFrameDatabase.h include/Sim3Solver.h include/Viewer.h include/ImuTypes.h include/G2oTypes.h include/CameraModels/GeometricCamera.h include/CameraModels/Pinhole.h include/CameraModels/KannalaBrandt8.h include/OptimizableTypes.h include/MLPnPsolver.h include/GeometricTools.h include/TwoViewReconstruction.h include/SerializationUtils.h include/Config.h include/Settings.h)

add_subdirectory(Thirdparty/g2o)

target_link_libraries(${PROJECT_NAME} PUBLIC ${OpenCV_LIBS} ${EIGEN3_LIBS} ${Pangolin_LIBRARIES} ${PROJECT_SOURCE_DIR}/Thirdparty/DBoW2/lib/libDBoW2.so ${PROJECT_SOURCE_DIR}/Thirdparty/g2o/lib/libg2o.so -lboost_serialization -lcrypto )

target_link_libraries(${PROJECT_NAME} PRIVATE depthai::opencv)

If RealSense SDK is found the library is added and its examples compiled

if(realsense2_FOUND) include_directories(${PROJECT_NAME} ${realsense_INCLUDE_DIR} ) target_link_libraries(${PROJECT_NAME} ${realsense2_LIBRARY} ) endif()

Build examples

RGB-D examples

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/Examples/RGB-D)

add_executable(rgbd_tum Examples/RGB-D/rgbd_tum.cc) target_link_libraries(rgbd_tum ${PROJECT_NAME})

if(realsense2_FOUND) add_executable(rgbd_realsense_D435i Examples/RGB-D/rgbd_realsense_D435i.cc) target_link_libraries(rgbd_realsense_D435i ${PROJECT_NAME}) endif()

RGB-D inertial examples

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/Examples/RGB-D-Inertial)

if(realsense2_FOUND) add_executable(rgbd_inertial_realsense_D435i Examples/RGB-D-Inertial/rgbd_inertial_realsense_D435i.cc) target_link_libraries(rgbd_inertial_realsense_D435i ${PROJECT_NAME}) endif()

Stereo examples

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/Examples/Stereo)

add_executable(stereo_kitti Examples/Stereo/stereo_kitti.cc) target_link_libraries(stereo_kitti ${PROJECT_NAME})

add_executable(stereo_euroc Examples/Stereo/stereo_euroc.cc) target_link_libraries(stereo_euroc ${PROJECT_NAME})

add_executable(stereo_tum_vi Examples/Stereo/stereo_tum_vi.cc) target_link_libraries(stereo_tum_vi ${PROJECT_NAME})

if(realsense2_FOUND) add_executable(stereo_realsense_t265 Examples/Stereo/stereo_realsense_t265.cc) target_link_libraries(stereo_realsense_t265 ${PROJECT_NAME})

add_executable(stereo_realsense_D435i
        Examples/Stereo/stereo_realsense_D435i.cc)
target_link_libraries(stereo_realsense_D435i ${PROJECT_NAME})

endif()

Monocular examples

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/Examples/Monocular)

add_executable(mono_tum Examples/Monocular/mono_tum.cc) target_link_libraries(mono_tum ${PROJECT_NAME})

add_executable(mono_webcam Examples/Monocular/mono_webcam.cc)

target_link_libraries(mono_webcam ${PROJECT_NAME})

add_executable(mono_kitti Examples/Monocular/mono_kitti.cc) target_link_libraries(mono_kitti ${PROJECT_NAME})

add_executable(mono_euroc Examples/Monocular/mono_euroc.cc) target_link_libraries(mono_euroc ${PROJECT_NAME})

add_executable(mono_tum_vi Examples/Monocular/mono_tum_vi.cc) target_link_libraries(mono_tum_vi ${PROJECT_NAME})

if(realsense2_FOUND) add_executable(mono_realsense_t265 Examples/Monocular/mono_realsense_t265.cc) target_link_libraries(mono_realsense_t265 ${PROJECT_NAME})

add_executable(mono_realsense_D435i
        Examples/Monocular/mono_realsense_D435i.cc)
target_link_libraries(mono_realsense_D435i ${PROJECT_NAME})

endif()

Monocular inertial examples

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/Examples/Monocular-Inertial)

add_executable(mono_inertial_euroc Examples/Monocular-Inertial/mono_inertial_euroc.cc) target_link_libraries(mono_inertial_euroc ${PROJECT_NAME})

add_executable(mono_inertial_tum_vi Examples/Monocular-Inertial/mono_inertial_tum_vi.cc) target_link_libraries(mono_inertial_tum_vi ${PROJECT_NAME})

if(realsense2_FOUND) add_executable(mono_inertial_realsense_t265 Examples/Monocular-Inertial/mono_inertial_realsense_t265.cc) target_link_libraries(mono_inertial_realsense_t265 ${PROJECT_NAME})

add_executable(mono_inertial_realsense_D435i
        Examples/Monocular-Inertial/mono_inertial_realsense_D435i.cc)
target_link_libraries(mono_inertial_realsense_D435i ${PROJECT_NAME})

endif()

Stereo Inertial examples

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/Examples/Stereo-Inertial)

add_executable(stereo_OAK_D_S2 Examples/Stereo-Inertial/stereo_OAK_D_S2.cc) target_link_libraries(stereo_OAK_D_S2 ${PROJECT_NAME} depthai::opencv)

add_executable(stereo_inertial_euroc Examples/Stereo-Inertial/stereo_inertial_euroc.cc) target_link_libraries(stereo_inertial_euroc ${PROJECT_NAME})

add_executable(stereo_inertial_tum_vi Examples/Stereo-Inertial/stereo_inertial_tum_vi.cc) target_link_libraries(stereo_inertial_tum_vi ${PROJECT_NAME})

if(realsense2_FOUND) add_executable(stereo_inertial_realsense_t265 Examples/Stereo-Inertial/stereo_inertial_realsense_t265.cc) target_link_libraries(stereo_inertial_realsense_t265 ${PROJECT_NAME})

add_executable(stereo_inertial_realsense_D435i
        Examples/Stereo-Inertial/stereo_inertial_realsense_D435i.cc)
target_link_libraries(stereo_inertial_realsense_D435i ${PROJECT_NAME})

endif()

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/Examples/Calibration) if(realsense2_FOUND) add_executable(recorder_realsense_D435i Examples/Calibration/recorder_realsense_D435i.cc) target_link_libraries(recorder_realsense_D435i ${PROJECT_NAME})

add_executable(recorder_realsense_T265
        Examples/Calibration/recorder_realsense_T265.cc)
target_link_libraries(recorder_realsense_T265 ${PROJECT_NAME})

endif()

NeroBurner commented 1 year ago

please provide a minimal project (create one on GitHub and link it here) and the exact commands to trigger your error, so that I can have a look at it.

gauravsahooo commented 1 year ago

Hello Cpp-Pm/Hunter,

I cannot share the files as it is company data but I can give u an idea in brief what I am trying to do. I am getting this error at the time of linking depth-core as deathcore -is using hunter. I have shared the cake with you where it is not mentioned to build Zlib just it extracts the Zlib library from the hunter package. If we mentioned in cmake not use zlib from the package & build zlib in the machine hope this error will not come. please suggest I have attached cmake & share deathcore link.

https://github.com/luxonis/depthai-core

On Thu, Jun 29, 2023 at 6:02 PM NeroBurner @.***> wrote:

please provide a minimal project (create one on GitHub and link it here) and the exact commands to trigger your error, so that I can have a look at it.

— Reply to this email directly, view it on GitHub https://github.com/cpp-pm/hunter/issues/678#issuecomment-1613463312, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWD2KC5ZJHSM3OKYRTYIKCDXNWRLBANCNFSM6AAAAAAZASTZRA . You are receiving this because you authored the thread.Message ID: @.***>

-- Thanks Gaurav Sahoo

cmake_minimum_required(VERSION 3.4) # For Hunter

MSVC variable isn't available before 'project' call

Generalize to Win32 platform for now

if(NOT WIN32) set(HUNTER_CONFIGURATION_TYPES "Release" CACHE STRING "Hunter dependencies list of build configurations") endif()

set(HUNTER_USE_CACHE_SERVERS NO) # Disable cache servers set(HUNTER_CACHE_SERVERS_NO "") set(HUNTER_CACHE_SERVERS_EXTERNAL "")

if(NOT CMAKE_POSITION_INDEPENDENT_CODE) set(CMAKE_POSITION_INDEPENDENT_CODE ON) endif()

Set type to canonicalize relative paths for user-provided toolchain

set(CMAKE_TOOLCHAIN_FILE "" CACHE FILEPATH "CMake toolchain path")

Create a custom toolchain to pass certain options to dependencies

set(gen_toolchain "${CMAKE_CURRENT_BINARY_DIR}/generated/toolchain.cmake")

if(EXISTS "${gen_toolchain}" AND ("${_INTERNAL_DEPTHAI_ORIGINAL_CMAKE_TOOLCHAIN_FILE}" STREQUAL "${CMAKE_TOOLCHAIN_FILE}" OR NOT "${CMAKE_TOOLCHAIN_FILE}" STREQUAL "")) message(STATUS "Using existing generated toolchain") else() message(STATUS "Generating new toolchain...") configure_file( "${CMAKE_CURRENT_LIST_DIR}/cmake/toolchain/custom.cmake.in" "${gen_toolchain}" @ONLY ) endif()

set(CMAKE_TOOLCHAIN_FILE "${gen_toolchain}" CACHE STRING "" FORCE) if(DEFINED _INTERNAL_DEPTHAI_ORIGINAL_CMAKE_TOOLCHAIN_FILE) message(STATUS "Using specified toolchain file: ${_INTERNAL_DEPTHAI_ORIGINAL_CMAKE_TOOLCHAIN_FILE} combined into: ${CMAKE_TOOLCHAIN_FILE}") else() message(STATUS "Using toolchain file: ${CMAKE_TOOLCHAIN_FILE}") endif()

include("cmake/HunterGate.cmake") HunterGate( URL "https://github.com/cpp-pm/hunter/archive/v0.23.322.tar.gz" SHA1 "cb0ea1f74f4a2c49a807de34885743495fccccbe" LOCAL # Local config for dependencies )

Move binary dir if windows, to shorten the path

if(WIN32) set(HUNTER_BINARY_DIR "${HUNTER_GATE_ROOT}/_bin" CACHE STRING "Hunter binary directory") endif()

Create depthai project

project(depthai VERSION "2.21.2" LANGUAGES CXX C) get_directory_property(has_parent PARENT_DIRECTORY) if(has_parent) set(DEPTHAI_VERSION ${PROJECT_VERSION} PARENT_SCOPE) endif()

Set default build type depending on context

set(default_build_type "Release") if(EXISTS "${CMAKE_SOURCE_DIR}/.git" AND NOT DEFINED ENV{CI}) set(default_build_type "Debug") endif() if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) message(STATUS "Setting build type to '${default_build_type}' as none was specified.") set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build." FORCE)

Set the possible values of build type for cmake-gui

set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")

endif()

Set default installation directory

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Installation Directory" FORCE) endif()

Set policies

CMP0074 dictates that find_package searches environment variable "[packageName]_ROOT" along with regular variable [packageName]_ROOT

if(POLICY CMP0074) cmake_policy(SET CMP0074 NEW) # Only introduced in 3.12 endif()

if(POLICY CMP0028) cmake_policy(SET CMP0028 NEW) endif()

Set to export compile commands for tools like clang-tidy and format

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

Add module path

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/sanitizers")

Additional options

option(DEPTHAI_CLANG_FORMAT "Enable clang-format target" ON) option(DEPTHAI_CLANG_TIDY "Enable clang-tidy checks during compilation" OFF) option(DEPTHAI_SANITIZE "Enable Address and Undefined sanitizers for library, examples and tests" OFF)

Should install depthai core libraries

option(DEPTHAI_INSTALL "Enable install target for depthai-core targets" ON)

Debug option

set(DEPTHAI_XLINK_LOCAL "" CACHE STRING "Path to local XLink source to use instead of Hunter") set(DEPTHAI_SHARED_LOCAL "" CACHE STRING "Path to local depthai-shared source to use instead of submodule") set(DEPTHAI_BOOTLOADER_SHARED_LOCAL "" CACHE STRING "Path to local depthai-bootloader-shared source to use instead of submodule")

Enable backward stack printing on crash

if(ANDROID)

Backward not supported currently on Android

set(DEPTHAI_ENABLE_BACKWARD OFF CACHE BOOL "" FORCE)

else() option(DEPTHAI_ENABLE_BACKWARD "Enable stacktrace printing on crash using Backward" ON)

Additional function information for 'backward' stacktrace

if(DEPTHAI_ENABLE_BACKWARD)
    set(CMAKE_ENABLE_EXPORTS ON)
endif()

endif()

Force Colored output when using Ninja

Global option - affects all targets

option(FORCE_COLORED_OUTPUT "Always produce ANSI-colored output (GNU/Clang only)" OFF) if(FORCE_COLORED_OUTPUT) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") add_compile_options(-fdiagnostics-color=always) elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") add_compile_options(-fcolor-diagnostics) endif() endif()

Specify exporting all symbols on Windows

if(WIN32 AND BUILD_SHARED_LIBS) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON CACHE BOOL "") endif()

Constants

set(PROJECT_EXPORT_GROUP "${PROJECT_NAME}Targets")

Check if cloned or sources

find_package(Git) if(GIT_FOUND) execute_process( COMMAND ${GIT_EXECUTABLE} rev-parse --show-toplevel WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} RESULT_VARIABLE _git_root_dir_error OUTPUT_VARIABLE _git_root_dir ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE ) set(DEPTHAI_DOWNLOADED_SOURCES ON) if(_git_root_dir_error EQUAL 0 AND "${_git_root_dir}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}") set(DEPTHAI_DOWNLOADED_SOURCES OFF) endif() message(DEBUG "Git root dir (${_git_root_dir_error}): ${_git_root_dir}") message(DEBUG "DepthAI as downloaded sources: ${DEPTHAI_DOWNLOADED_SOURCES}") execute_process( COMMAND ${GIT_EXECUTABLE} rev-parse HEAD WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} OUTPUT_VARIABLE BUILD_COMMIT ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE ) execute_process( COMMAND ${GIT_EXECUTABLE} show -s --format=%ci ${BUILD_COMMIT} WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} OUTPUT_VARIABLE BUILD_COMMIT_DATETIME ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE ) endif()

Get and find dependencies

Include project dependencies

set(DEPTHAI_DEPENDENCY_INCLUDE "" CACHE FILEPATH "Optional cmake file to append to dependency processing, e.g. additional find_package()") include(depthaiDependencies)

Add threads preference

set(THREADS_PREFER_PTHREAD_FLAG ON)

Add depthai-shared, and definitions that it is PC side

include(${CMAKE_CURRENT_LIST_DIR}/shared/depthai-shared.cmake)

Add depthai-bootloader-shared

include(${CMAKE_CURRENT_LIST_DIR}/shared/depthai-bootloader-shared.cmake)

Add flags helpers

include(Flags)

End of dependencies

set(TARGET_CORE_NAME ${PROJECT_NAME}-core) set(TARGET_CORE_ALIAS core)

Create core library

add_library(${TARGET_CORE_NAME}

depthai-shared sources

"${DEPTHAI_SHARED_SOURCES}"
# depthai-bootloader-shared sources
"${DEPTHAI_BOOTLOADER_SHARED_SOURCES}"
# sources
src/device/Device.cpp
src/device/DeviceBase.cpp
src/device/DeviceBootloader.cpp
src/device/DataQueue.cpp
src/device/CallbackHandler.cpp
src/device/CalibrationHandler.cpp
src/device/Version.cpp
src/pipeline/Pipeline.cpp
src/pipeline/AssetManager.cpp
src/pipeline/Node.cpp
src/pipeline/node/XLinkIn.cpp
src/pipeline/node/XLinkOut.cpp
src/pipeline/node/ColorCamera.cpp
src/pipeline/node/Camera.cpp
src/pipeline/node/MonoCamera.cpp
src/pipeline/node/StereoDepth.cpp
src/pipeline/node/NeuralNetwork.cpp
src/pipeline/node/ImageManip.cpp
src/pipeline/node/Warp.cpp
src/pipeline/node/VideoEncoder.cpp
src/pipeline/node/DetectionNetwork.cpp
src/pipeline/node/Script.cpp
src/pipeline/node/SpatialDetectionNetwork.cpp
src/pipeline/node/SystemLogger.cpp
src/pipeline/node/SpatialLocationCalculator.cpp
src/pipeline/node/AprilTag.cpp
src/pipeline/node/ObjectTracker.cpp
src/pipeline/node/IMU.cpp
src/pipeline/node/EdgeDetector.cpp
src/pipeline/node/SPIIn.cpp
src/pipeline/node/FeatureTracker.cpp
src/pipeline/node/DetectionParser.cpp
src/pipeline/datatype/Buffer.cpp
src/pipeline/datatype/ImgFrame.cpp
src/pipeline/datatype/ImageManipConfig.cpp
src/pipeline/datatype/CameraControl.cpp
src/pipeline/datatype/NNData.cpp
src/pipeline/datatype/ImgDetections.cpp
src/pipeline/datatype/SpatialImgDetections.cpp
src/pipeline/datatype/SystemInformation.cpp
src/pipeline/datatype/StreamMessageParser.cpp
src/pipeline/datatype/SpatialLocationCalculatorData.cpp
src/pipeline/datatype/SpatialLocationCalculatorConfig.cpp
src/pipeline/datatype/AprilTags.cpp
src/pipeline/datatype/AprilTagConfig.cpp
src/pipeline/datatype/Tracklets.cpp
src/pipeline/datatype/IMUData.cpp
src/pipeline/datatype/StereoDepthConfig.cpp
src/pipeline/datatype/EdgeDetectorConfig.cpp
src/pipeline/datatype/TrackedFeatures.cpp
src/pipeline/datatype/FeatureTrackerConfig.cpp
src/utility/Initialization.cpp
src/utility/Resources.cpp
src/utility/Path.cpp
src/utility/Platform.cpp
src/utility/Environment.cpp
src/xlink/XLinkConnection.cpp
src/xlink/XLinkStream.cpp
src/openvino/OpenVINO.cpp
src/openvino/BlobReader.cpp
src/bspatch/bspatch.c

) add_library("${PROJECT_NAME}::${TARGET_CORE_ALIAS}" ALIAS ${TARGET_CORE_NAME})

Specify that we are building core

target_compile_definitions(${TARGET_CORE_NAME} PUBLIC DEPTHAI_TARGET_CORE)

Specifies name of generated IMPORTED target (set to alias)

set_target_properties(${TARGET_CORE_NAME} PROPERTIES EXPORT_NAME ${TARGET_CORE_ALIAS})

Add to list of targets to export and install

list(APPEND targets_to_export ${TARGET_CORE_NAME})

Add default flags to core

add_default_flags(${TARGET_CORE_NAME})

And clang-tidy and format

if(DEPTHAI_CLANG_TIDY) include(ClangTidy) target_clangtidy_setup(${TARGET_CORE_NAME}) endif()

Set compiler features (c++14), and disables extensions (g++14)

set_property(TARGET ${TARGET_CORE_NAME} PROPERTY CXX_STANDARD 14) set_property(TARGET ${TARGET_CORE_NAME} PROPERTY CXX_STANDARD_REQUIRED ON) set_property(TARGET ${TARGET_CORE_NAME} PROPERTY CXX_EXTENSIONS OFF)

Add interface transitive property (C++14)

if(${CMAKE_VERSION} VERSION_LESS "3.8.0") target_compile_features(${TARGET_CORE_NAME} INTERFACE cxx_generic_lambdas) else() target_compile_features(${TARGET_CORE_NAME} INTERFACE cxx_std_14) endif()

First specify options

option(DEPTHAI_BUILD_TESTS "Build tests" OFF) option(DEPTHAI_BUILD_EXAMPLES "Build examples - Requires OpenCV library to be installed" OFF) option(DEPTHAI_BUILD_DOCS "Build documentation - requires doxygen to be installed" OFF) option(DEPTHAI_OPENCV_SUPPORT "Enable optional OpenCV support" ON)

option(DEPTHAI_BINARIES_RESOURCE_COMPILE "Compile Depthai device side binaries into library" ON) option(DEPTHAI_USB2_PATCH_ONLY_MODE "Use patch file and full depthai.cmd binary for usb2 mode" ON) option(DEPTHAI_CMD_PATH "Use local path for depthai.cmd instead of downloading" OFF) if(DEPTHAI_USB2_PATCH_ONLY_MODE) option(DEPTHAI_USB2_PATCH_PATH "Use local path for depthai-usb2-patch.patch instead of downloading" OFF) else() option(DEPTHAI_USB2_CMD_PATH "Use local path for depthai-usb2.cmd instead of downloading" OFF) endif()

if(DEPTHAI_USB2_PATCH_ONLY_MODE) message(STATUS "Compiling ${TARGET_CORE_NAME} resources in PATCH_ONLY mode") else() message(STATUS "Compiling ${TARGET_CORE_NAME} depthai and depthai-usb2 resources") endif()

Set constant

set(DEPTHAI_RESOURCES_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/resources")

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) set(DEPTHAI_BOOTLOADER_SHARED_COMMIT_HASH_ENFORCE ON) endif()

Then get the Depthai device side binaries (local or download)

if(DEPTHAI_CMD_PATH OR DEPTHAI_USB2_CMD_PATH OR DEPTHAI_USB2_PATCH_PATH)

At least 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})

message(STATUS "LIST OF RESOURCE COMPILED FILES: ${RESOURCE_COMPILED_FILES}")

if(DEPTHAI_BINARIES_RESOURCE_COMPILE)

Add RC and resource compile the binares

include(CMakeRC)

set(DEPTHAI_RESOURCE_LIBRARY_NAME "depthai-resources")

# Add resource library
cmrc_add_resource_library("${DEPTHAI_RESOURCE_LIBRARY_NAME}" NAMESPACE depthai
    WHENCE "${DEPTHAI_RESOURCES_OUTPUT_DIR}"
    "${RESOURCE_COMPILED_FILES}"
)

# Link to resource library
target_link_libraries(${TARGET_CORE_NAME} PRIVATE "${DEPTHAI_RESOURCE_LIBRARY_NAME}")

# Set define that binaries are resource compiled
target_compile_definitions(${TARGET_CORE_NAME} PRIVATE DEPTHAI_RESOURCE_COMPILED_BINARIES)

else()

TODO

# Don't add RC and don't resource compile the binaries

endif()

Add include directories

target_include_directories(${TARGET_CORE_NAME} PUBLIC

Relative path to include directories after installed

    "$<INSTALL_INTERFACE:include>"
    "$<INSTALL_INTERFACE:include/${DEPTHAI_SHARED_3RDPARTY_HEADERS_PATH}>"

    # Build time path to include directories
    "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
    "$<BUILD_INTERFACE:${DEPTHAI_SHARED_PUBLIC_INCLUDE}>"
    "$<BUILD_INTERFACE:${DEPTHAI_BOOTLOADER_SHARED_PUBLIC_INCLUDE}>"
#INTERFACE
#    # ...
PRIVATE
    "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include/depthai>"
    "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/src>"
    "$<BUILD_INTERFACE:${DEPTHAI_SHARED_INCLUDE}>"
    "$<BUILD_INTERFACE:${DEPTHAI_BOOTLOADER_SHARED_INCLUDE}>"

)

target_include_directories(${TARGET_CORE_NAME} SYSTEM PUBLIC "$<BUILD_INTERFACE:${DEPTHAI_SHARED_3RDPARTY_INCLUDE}>" )

Add clang format after specifying include directories

if(DEPTHAI_CLANG_FORMAT)

HEADER DIRECTORIES

set(header_dirs "${CMAKE_CURRENT_LIST_DIR}/include" "${DEPTHAI_SHARED_PUBLIC_INCLUDE}" "${DEPTHAI_SHARED_INCLUDE}")
include(ClangFormat)
target_clangformat_setup(${TARGET_CORE_NAME} "${header_dirs}")

endif()

link libraries

target_link_libraries(${TARGET_CORE_NAME} PUBLIC nlohmann_json::nlohmann_json libnop INTERFACE XLinkPublic PRIVATE XLink Threads::Threads BZip2::bz2 FP16::fp16 archive_static spdlog::spdlog ZLIB::zlib )

Add compile & CMake definitions

set(DEPTHAI_DEVICE_VERSION "${DEPTHAI_DEVICE_SIDE_COMMIT}") target_compile_definitions(${TARGET_CORE_NAME} PRIVATE

XLink required define

    __PC__
    # Add depthai-device version
    DEPTHAI_DEVICE_VERSION="${DEPTHAI_DEVICE_VERSION}"
    # Add depthai-bootloader version
    DEPTHAI_BOOTLOADER_VERSION="${DEPTHAI_BOOTLOADER_VERSION}"

)

Add Backward dependency if enabled (On by default)

if(DEPTHAI_ENABLE_BACKWARD) target_compile_definitions(${TARGET_CORE_NAME} PRIVATE DEPTHAI_ENABLE_BACKWARD) target_link_libraries(${TARGET_CORE_NAME} PRIVATE Backward::Backward) endif()

Add patch only mode definition

if(DEPTHAI_USB2_PATCH_ONLY_MODE) target_compile_definitions(${TARGET_CORE_NAME} PRIVATE DEPTHAI_PATCH_ONLY_MODE) endif()

Helper function

macro(add_runtime_dependencies depending_target dependency) if(WIN32) if(TARGET ${dependency}) get_property(imported_configs TARGET ${dependency} PROPERTY IMPORTED_CONFIGURATIONS) set(dlls "") foreach(cfg ${imported_configs}) get_property(dll TARGET ${dependency} PROPERTY IMPORTEDLOCATION${cfg}) set(dlls ${depthai_dll_libraries} $<$<CONFIG:${cfg}>:${dll}>) endforeach() endif() file(GLOB depthai_dll_libraries "${HUNTER_INSTALL_PREFIX}/bin/*.dll")

Create a list of required dll files

    set(required_dll_files ${dlls} ${depthai_dll_libraries})
    # Copy the required dlls
    add_custom_command(TARGET ${depending_target} POST_BUILD COMMAND
        ${CMAKE_COMMAND} -E copy_if_different ${required_dll_files} $<TARGET_FILE_DIR:${depending_target}>
        COMMAND_EXPAND_LISTS
    )
    message(STATUS "Required dlls for core are: ${required_dll_files}")
endif()

endmacro()

Add libusb dll in build time

add_runtime_dependencies(${TARGET_CORE_NAME} usb-1.0)

########################

OpenCV Support

######################## set(THIRDPARTY_OPENCV_LIBRARIES "" CACHE STRING "Optional libraries to link OpenCV support, e.g. TBB::tbb") set(TARGET_OPENCV_NAME ${PROJECT_NAME}-opencv) set(TARGET_OPENCV_ALIAS opencv) if(DEPTHAI_OPENCV_SUPPORT)

Check if required libraries are available

set(REQUIRED_OPENCV_LIBRARIES "opencv_core" "opencv_imgproc")
set(OPENCV_SUPPORT_AVAILABLE ${OpenCV_FOUND})
foreach(lib ${REQUIRED_OPENCV_LIBRARIES})
    if(NOT (lib IN_LIST OpenCV_LIBS))
        set(OPENCV_SUPPORT_AVAILABLE FALSE)
    endif()
endforeach()

if(OPENCV_SUPPORT_AVAILABLE)

    # Add depthai-core-opencv library and depthai::core::opencv alias
    add_library(${TARGET_OPENCV_NAME} src/opencv/ImgFrame.cpp)
    add_library("${PROJECT_NAME}::${TARGET_OPENCV_ALIAS}" ALIAS ${TARGET_OPENCV_NAME})
    # Specifies name of generated IMPORTED target (set to alias)
    set_target_properties(${TARGET_OPENCV_NAME} PROPERTIES EXPORT_NAME ${TARGET_OPENCV_ALIAS})

    # Add default flags
    add_default_flags(${TARGET_OPENCV_NAME})
    add_flag(${TARGET_OPENCV_NAME} -Wno-switch-enum)

    # Link to OpenCV (publically)
    target_link_libraries(${TARGET_OPENCV_NAME} PUBLIC ${REQUIRED_OPENCV_LIBRARIES} ${THIRDPARTY_OPENCV_LIBRARIES})

    # Add public compile definition indicating that OpenCV support is available
    set(DEPTHAI_HAVE_OPENCV_SUPPORT ON)

    # Specify that we are building target opencv
    target_compile_definitions(${TARGET_OPENCV_NAME} PUBLIC DEPTHAI_TARGET_OPENCV)

    # Add public dependency to depthai::core library
    target_link_libraries(${TARGET_OPENCV_NAME} PUBLIC ${TARGET_CORE_NAME})

    # Add to clangformat target
    if(COMMAND target_clangformat_setup)
        target_clangformat_setup(${TARGET_OPENCV_NAME} "")
    endif()

    # Add to list of targets to export and install
    list(APPEND targets_to_export ${TARGET_OPENCV_NAME})

    message(STATUS "OpenCV and required libraries (${REQUIRED_OPENCV_LIBRARIES}) found. OpenCV Support enabled")

else()
    message(STATUS "OpenCV or required libraries (${REQUIRED_OPENCV_LIBRARIES}) not found. OpenCV Support disabled")
endif()

endif()

########################

Sanitizers

######################## if(DEPTHAI_SANITIZE) set(SANITIZE_ADDRESS ON CACHE BOOL "Enable AddressSanitizer for sanitized targets." FORCE) set(SANITIZE_UNDEFINED ON CACHE BOOL "Enable UndefinedBehaviorSanitizer for sanitized targets." FORCE) find_package(Sanitizers) add_sanitizers(${TARGET_CORE_NAME}) if(DEPTHAI_HAVE_OPENCV_SUPPORT) add_sanitizers(${TARGET_OPENCV_NAME}) endif() if(DEPTHAI_XLINK_LOCAL) add_sanitizers(XLink) if(XLINK_LIBUSB_LOCAL) add_sanitizers(usb-1.0) endif() endif() endif()

########################

Testing infrastructure

######################## include(CTest) enable_testing()

########################

Tests

######################## if (DEPTHAI_BUILD_TESTS) add_subdirectory(tests) endif()

########################

Examples (can also act as tests)

######################## if (DEPTHAI_BUILD_EXAMPLES) add_subdirectory(examples) endif()

########################

Documentation

######################## if (DEPTHAI_BUILD_DOCS) add_subdirectory(docs) endif()

########################

Build configuration

########################

Add year information

string(TIMESTAMP BUILD_DATETIME "%Y-%m-%d %H:%M:%S +0000" UTC) message(STATUS "BUILD_DATETIME: ${BUILD_DATETIME}, BUILD_COMMIT: ${BUILD_COMMIT}, BUILD_COMMIT_DATETIME: ${BUILD_COMMIT_DATETIME}")

Configure build information (version, opencv support)

configure_file("${CMAKE_CURRENT_LIST_DIR}/cmake/version.hpp.in" "${CMAKE_CURRENT_LIST_DIR}/include/depthai/build/version.hpp") configure_file("${CMAKE_CURRENT_LIST_DIR}/cmake/config.hpp.in" "${CMAKE_CURRENT_LIST_DIR}/include/depthai/build/config.hpp")

########################

Export and install

######################## include(GNUInstallDirs) include(CMakePackageConfigHelpers)

Add additional targets to export group

if(NOT BUILD_SHARED_LIBS) list(APPEND targets_to_export ${DEPTHAI_RESOURCE_LIBRARY_NAME} cmrc-base) endif()

Export targets (capability to import current build directory)

export(TARGETS ${targets_to_export} NAMESPACE ${PROJECT_NAME}:: FILE "${PROJECT_NAME}Targets.cmake")

Dependencies file

configure_file("cmake/${PROJECT_NAME}Dependencies.cmake" ${PROJECT_NAME}Dependencies.cmake COPYONLY)

Write project version

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)

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)

Config for installation

set(DEPTHAI_DEPENDENCIES_INSTALLATION_PATH_REL "./dependencies") configure_file(cmake/${PROJECT_NAME}Config.cmake.in _install/${PROJECT_NAME}Config.cmake @ONLY)

Modify RPath to point to the cmake/depthai/dependencies/lib

note: macOS is APPLE and also UNIX!

if(APPLE) set_target_properties(${TARGET_CORE_NAME} PROPERTIES INSTALL_RPATH @.**@._path/cmake/${PROJECT_NAME}/dependencies/lib") elseif(UNIX) set_target_properties(${TARGET_CORE_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN:$ORIGIN/cmake/${PROJECT_NAME}/dependencies/lib") endif()

Export to CMake registry if specified

if(CMAKE_EXPORT_PACKAGE_REGISTRY) export(PACKAGE depthai) endif()

if(DEPTHAI_INSTALL)

# Install targets
install(
    TARGETS ${targets_to_export}
    EXPORT ${PROJECT_EXPORT_GROUP}
    RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
    LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
    ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)

# Install depthai public headers
install(DIRECTORY include/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
# Install depthai-shared public headers
install(DIRECTORY "${DEPTHAI_SHARED_PUBLIC_INCLUDE}/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
# Install depthai-shared 3rdparty headers
install(DIRECTORY "${DEPTHAI_SHARED_3RDPARTY_INCLUDE}/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${DEPTHAI_SHARED_3RDPARTY_HEADERS_PATH}")
# Install depthai-bootloader-shared public headers
install(DIRECTORY "${DEPTHAI_BOOTLOADER_SHARED_PUBLIC_INCLUDE}/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
# Install Hunter dependencies
install(DIRECTORY "${HUNTER_INSTALL_PREFIX}/" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}/dependencies")
# Install resources if not RC'd
if(NOT DEPTHAI_BINARIES_RESOURCE_COMPILE)
    install(DIRECTORY "${DEPTHAI_RESOURCES_OUTPUT_DIR}/" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}")
endif()
# Install any required dll files
if(DEFINED required_dll_files)
    install(FILES ${required_dll_files} DESTINATION "${CMAKE_INSTALL_BINDIR}")
endif()

# Install export group (information about targets)
install(EXPORT ${PROJECT_EXPORT_GROUP}
    NAMESPACE ${PROJECT_NAME}::
    DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)

# Install CMake specific files
install(FILES
    "${CMAKE_CURRENT_BINARY_DIR}/_install/${PROJECT_NAME}Config.cmake"
    "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
    "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Dependencies.cmake"
    DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)

endif()

##############################

Integration settings export

############################## set(tmp_definitions "$<TARGET_PROPERTY:${TARGET_CORE_NAME},INTERFACE_COMPILE_DEFINITIONS>") set(tmp_includes "$<TARGET_PROPERTY:${TARGET_CORE_NAME},INTERFACE_INCLUDE_DIRECTORIES>") file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/depthai-core-integration.txt" CONTENT "$<$<BOOL:${tmp_definitions}>:\n-D\'$<JOIN:${tmp_definitions},\'\n-D\'>\'>\n $<$<BOOL:${tmp_includes}>:\n-I\'$<JOIN:${tmp_includes},\'\n-I\'>\'>\n" )

if(DEPTHAI_HAVE_OPENCV_SUPPORT) set(tmp_definitions "$<TARGET_PROPERTY:${TARGET_OPENCV_NAME},INTERFACE_COMPILE_DEFINITIONS>") set(tmp_includes "$<TARGET_PROPERTY:${TARGET_OPENCV_NAME},INTERFACE_INCLUDE_DIRECTORIES>") file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/depthai-opencv-integration.txt" CONTENT "$<$<BOOL:${tmp_definitions}>:\n-D\'$<JOIN:${tmp_definitions},\'\n-D\'>\'>\n $<$<BOOL:${tmp_includes}>:\n-I\'$<JOIN:${tmp_includes},\'\n-I\'>\'>\n" ) endif()

NeroBurner commented 1 year ago

-fpic seems to be an undetectable flag (at least for hunter). So we need to explicitly tell hunter, that such a flag is part of the toolchain file. Here is a minimal toolchain-fpic.cmake file which satisfies those requirements

toolchain-pic.cmake

set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
list(APPEND HUNTER_TOOLCHAIN_UNDETECTABLE_ID "pic")

Having a CMakeLists.txt with the following contents triggers the fpic bug you mentioned

...
# ...
# initialize project
# 

# get zlib from hunter
hunter_add_package(ZLIB)
find_package(ZLIB CONFIG REQUIRED)

# link to shared library, which fails if zlib is built without -fpic
add_library(boo-lib SHARED main.c)
target_link_libraries(boo-lib PRIVATE ZLIB::zlib)

now the following will fail at build time. This is because zlib by default with gcc is built without -fpic

cmake -S . -B build_default
cmake --build build_default

Now we take the same minimal project and use the toolchain file, which tells hunter to recompile everything because of the -fpic flag. This will work as zlib provided by hunter is now built with -fpic

cmake -S . -B build_with_fpic -DCMAKE_TOOLCHAIN_FILE=${PWD}/toolchain-pic.cmake
cmake --build build_with_fpic/
gauravsahooo commented 1 year ago

Hi,

I have created pic.cmake & added necessary lines, Attached in email. Added below changes in cmakelist.txt

hunter_add_package(ZLIB)find_package(ZLIB CONFIG REQUIRED)

link libraries

target_link_libraries(${TARGET_CORE_NAME} PUBLIC nlohmann_json::nlohmann_json libnop INTERFACE XLinkPublic PRIVATE XLink Threads::Threads BZip2::bz2 FP16::fp16 archive_static spdlog::spdlog

Added this line in cmakelist.txt whic is attached in this email cmake -S . -B build_with_fpic -DCMAKE_TOOLCHAIN_FILE=${PWD}/toolchain-pic.cmake

cmake --build build_with_fpic/

Unfortunately with above changes still it is not working getting same error.

/usr/bin/ld: /home/sahoo/.hunter/_Base/cb0ea1f/a3a48bb/079a0bf/Install/lib/libz.a(zutil.c.o): relocation R_X86_64_PC32 against symbol `z_errmsg' can not be used when making a shared object; recompile with -fPIC/usr/bin/ld: final link failed: bad value collect2: error: ld returned 1 exit status make[2]: [CMakeFiles/ORB_SLAM3.dir/build.make:538: ../lib/libORB_SLAM3.so] Error 1 make[1]: [CMakeFiles/Makefile2:531: CMakeFiles/ORB_SLAM3.dir/all] Error 2 make: *** [Makefile:130: all] Error 2

On Fri, Jun 30, 2023 at 9:23 PM NeroBurner @.***> wrote:

-fpic seems to be an undetectable flag (at least for hunter). So we need to explicitly tell hunter, that such a flag is part of the toolchain file. Here is a minimal toolchain-fpic.cmake file which satisfies those requirements

toolchain-pic.cmake https://github.com/cpp-pm/hunter/files/11919849/toolchain-pic.cmake.txt

set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)list(APPEND HUNTER_TOOLCHAIN_UNDETECTABLE_ID "pic")

Having a CMakeLists.txt with the following contents triggers the fpic bug you mentioned

...# ...# initialize project#

get zlib from hunter

hunter_add_package(ZLIB)find_package(ZLIB CONFIG REQUIRED)

link to shared library, which fails if zlib is built without -fpicadd_library(boo-lib SHARED main.c)target_link_libraries(boo-lib PRIVATE ZLIB::zlib)


now the following will fail at build time. This is because zlib by default with gcc is built without -fpic

cmake -S . -B build_default cmake --build build_default

Now we take the same minimal project and use the toolchain file, which tells hunter to recompile everything because of the -fpic flag. This will work as zlib provided by hunter is now built with -fpic

cmake -S . -B build_with_fpic -DCMAKE_TOOLCHAIN_FILE=${PWD}/toolchain-pic.cmake cmake --build build_with_fpic/

— Reply to this email directly, view it on GitHub https://github.com/cpp-pm/hunter/issues/678#issuecomment-1615104114, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWD2KCYXWNW6PP4TPU4K2J3XN4RU3ANCNFSM6AAAAAAZASTZRA . You are receiving this because you authored the thread.Message ID: @.***>

-- Thanks Gaurav Sahoo

cmake_minimum_required(VERSION 3.4) # For Hunter

MSVC variable isn't available before 'project' call

Generalize to Win32 platform for now

if(NOT WIN32) set(HUNTER_CONFIGURATION_TYPES "Release" CACHE STRING "Hunter dependencies list of build configurations") endif()

set(HUNTER_USE_CACHE_SERVERS NO) # Disable cache servers set(HUNTER_CACHE_SERVERS_NO "") set(HUNTER_CACHE_SERVERS_EXTERNAL "")

if(NOT CMAKE_POSITION_INDEPENDENT_CODE) set(CMAKE_POSITION_INDEPENDENT_CODE ON) endif()

set(ZLIB_PIC ON CACHE BOOL "Build zlib with PIC support")

Set type to canonicalize relative paths for user-provided toolchain

set(CMAKE_TOOLCHAIN_FILE "" CACHE FILEPATH "CMake toolchain path")

Create a custom toolchain to pass certain options to dependencies

set(gen_toolchain "${CMAKE_CURRENT_BINARY_DIR}/generated/toolchain.cmake")

if(EXISTS "${gen_toolchain}" AND ("${_INTERNAL_DEPTHAI_ORIGINAL_CMAKE_TOOLCHAIN_FILE}" STREQUAL "${CMAKE_TOOLCHAIN_FILE}" OR NOT "${CMAKE_TOOLCHAIN_FILE}" STREQUAL "")) message(STATUS "Using existing generated toolchain") else() message(STATUS "Generating new toolchain...") configure_file( "${CMAKE_CURRENT_LIST_DIR}/cmake/toolchain/custom.cmake.in" "${gen_toolchain}" @ONLY ) endif()

set(CMAKE_TOOLCHAIN_FILE "${gen_toolchain}" CACHE STRING "" FORCE) if(DEFINED _INTERNAL_DEPTHAI_ORIGINAL_CMAKE_TOOLCHAIN_FILE) message(STATUS "Using specified toolchain file: ${_INTERNAL_DEPTHAI_ORIGINAL_CMAKE_TOOLCHAIN_FILE} combined into: ${CMAKE_TOOLCHAIN_FILE}") else() message(STATUS "Using toolchain file: ${CMAKE_TOOLCHAIN_FILE}") endif()

include("cmake/HunterGate.cmake") HunterGate( URL "https://github.com/cpp-pm/hunter/archive/v0.23.322.tar.gz" SHA1 "cb0ea1f74f4a2c49a807de34885743495fccccbe" LOCAL # Local config for dependencies )

Move binary dir if windows, to shorten the path

if(WIN32) set(HUNTER_BINARY_DIR "${HUNTER_GATE_ROOT}/_bin" CACHE STRING "Hunter binary directory") endif()

Create depthai project

project(depthai VERSION "2.21.2" LANGUAGES CXX C) get_directory_property(has_parent PARENT_DIRECTORY) if(has_parent) set(DEPTHAI_VERSION ${PROJECT_VERSION} PARENT_SCOPE) endif()

Set default build type depending on context

set(default_build_type "Release") if(EXISTS "${CMAKE_SOURCE_DIR}/.git" AND NOT DEFINED ENV{CI}) set(default_build_type "Debug") endif() if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) message(STATUS "Setting build type to '${default_build_type}' as none was specified.") set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build." FORCE)

Set the possible values of build type for cmake-gui

set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")

endif()

Set default installation directory

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Installation Directory" FORCE) endif()

Set policies

CMP0074 dictates that find_package searches environment variable "[packageName]_ROOT" along with regular variable [packageName]_ROOT

if(POLICY CMP0074) cmake_policy(SET CMP0074 NEW) # Only introduced in 3.12 endif()

if(POLICY CMP0028) cmake_policy(SET CMP0028 NEW) endif()

Set to export compile commands for tools like clang-tidy and format

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

Add module path

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/sanitizers")

Additional options

option(DEPTHAI_CLANG_FORMAT "Enable clang-format target" ON) option(DEPTHAI_CLANG_TIDY "Enable clang-tidy checks during compilation" OFF) option(DEPTHAI_SANITIZE "Enable Address and Undefined sanitizers for library, examples and tests" OFF)

Should install depthai core libraries

option(DEPTHAI_INSTALL "Enable install target for depthai-core targets" ON)

Debug option

set(DEPTHAI_XLINK_LOCAL "" CACHE STRING "Path to local XLink source to use instead of Hunter") set(DEPTHAI_SHARED_LOCAL "" CACHE STRING "Path to local depthai-shared source to use instead of submodule") set(DEPTHAI_BOOTLOADER_SHARED_LOCAL "" CACHE STRING "Path to local depthai-bootloader-shared source to use instead of submodule")

Enable backward stack printing on crash

if(ANDROID)

Backward not supported currently on Android

set(DEPTHAI_ENABLE_BACKWARD OFF CACHE BOOL "" FORCE)

else() option(DEPTHAI_ENABLE_BACKWARD "Enable stacktrace printing on crash using Backward" ON)

Additional function information for 'backward' stacktrace

if(DEPTHAI_ENABLE_BACKWARD)
    set(CMAKE_ENABLE_EXPORTS ON)
endif()

endif()

Force Colored output when using Ninja

Global option - affects all targets

option(FORCE_COLORED_OUTPUT "Always produce ANSI-colored output (GNU/Clang only)" OFF) if(FORCE_COLORED_OUTPUT) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") add_compile_options(-fdiagnostics-color=always) elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") add_compile_options(-fcolor-diagnostics) endif() endif()

Specify exporting all symbols on Windows

if(WIN32 AND BUILD_SHARED_LIBS) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON CACHE BOOL "") endif()

Constants

set(PROJECT_EXPORT_GROUP "${PROJECT_NAME}Targets")

Check if cloned or sources

find_package(Git) if(GIT_FOUND) execute_process( COMMAND ${GIT_EXECUTABLE} rev-parse --show-toplevel WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} RESULT_VARIABLE _git_root_dir_error OUTPUT_VARIABLE _git_root_dir ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE ) set(DEPTHAI_DOWNLOADED_SOURCES ON) if(_git_root_dir_error EQUAL 0 AND "${_git_root_dir}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}") set(DEPTHAI_DOWNLOADED_SOURCES OFF) endif() message(DEBUG "Git root dir (${_git_root_dir_error}): ${_git_root_dir}") message(DEBUG "DepthAI as downloaded sources: ${DEPTHAI_DOWNLOADED_SOURCES}") execute_process( COMMAND ${GIT_EXECUTABLE} rev-parse HEAD WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} OUTPUT_VARIABLE BUILD_COMMIT ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE ) execute_process( COMMAND ${GIT_EXECUTABLE} show -s --format=%ci ${BUILD_COMMIT} WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} OUTPUT_VARIABLE BUILD_COMMIT_DATETIME ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE ) endif()

Get and find dependencies

Include project dependencies

set(DEPTHAI_DEPENDENCY_INCLUDE "" CACHE FILEPATH "Optional cmake file to append to dependency processing, e.g. additional find_package()") include(depthaiDependencies)

Add threads preference

set(THREADS_PREFER_PTHREAD_FLAG ON)

Add depthai-shared, and definitions that it is PC side

include(${CMAKE_CURRENT_LIST_DIR}/shared/depthai-shared.cmake)

Add depthai-bootloader-shared

include(${CMAKE_CURRENT_LIST_DIR}/shared/depthai-bootloader-shared.cmake)

Add flags helpers

include(Flags)

End of dependencies

set(TARGET_CORE_NAME ${PROJECT_NAME}-core) set(TARGET_CORE_ALIAS core)

Create core library

add_library(${TARGET_CORE_NAME}

depthai-shared sources

"${DEPTHAI_SHARED_SOURCES}"
# depthai-bootloader-shared sources
"${DEPTHAI_BOOTLOADER_SHARED_SOURCES}"
# sources
src/device/Device.cpp
src/device/DeviceBase.cpp
src/device/DeviceBootloader.cpp
src/device/DataQueue.cpp
src/device/CallbackHandler.cpp
src/device/CalibrationHandler.cpp
src/device/Version.cpp
src/pipeline/Pipeline.cpp
src/pipeline/AssetManager.cpp
src/pipeline/Node.cpp
src/pipeline/node/XLinkIn.cpp
src/pipeline/node/XLinkOut.cpp
src/pipeline/node/ColorCamera.cpp
src/pipeline/node/Camera.cpp
src/pipeline/node/MonoCamera.cpp
src/pipeline/node/StereoDepth.cpp
src/pipeline/node/NeuralNetwork.cpp
src/pipeline/node/ImageManip.cpp
src/pipeline/node/Warp.cpp
src/pipeline/node/VideoEncoder.cpp
src/pipeline/node/DetectionNetwork.cpp
src/pipeline/node/Script.cpp
src/pipeline/node/SpatialDetectionNetwork.cpp
src/pipeline/node/SystemLogger.cpp
src/pipeline/node/SpatialLocationCalculator.cpp
src/pipeline/node/AprilTag.cpp
src/pipeline/node/ObjectTracker.cpp
src/pipeline/node/IMU.cpp
src/pipeline/node/EdgeDetector.cpp
src/pipeline/node/SPIIn.cpp
src/pipeline/node/FeatureTracker.cpp
src/pipeline/node/DetectionParser.cpp
src/pipeline/datatype/Buffer.cpp
src/pipeline/datatype/ImgFrame.cpp
src/pipeline/datatype/ImageManipConfig.cpp
src/pipeline/datatype/CameraControl.cpp
src/pipeline/datatype/NNData.cpp
src/pipeline/datatype/ImgDetections.cpp
src/pipeline/datatype/SpatialImgDetections.cpp
src/pipeline/datatype/SystemInformation.cpp
src/pipeline/datatype/StreamMessageParser.cpp
src/pipeline/datatype/SpatialLocationCalculatorData.cpp
src/pipeline/datatype/SpatialLocationCalculatorConfig.cpp
src/pipeline/datatype/AprilTags.cpp
src/pipeline/datatype/AprilTagConfig.cpp
src/pipeline/datatype/Tracklets.cpp
src/pipeline/datatype/IMUData.cpp
src/pipeline/datatype/StereoDepthConfig.cpp
src/pipeline/datatype/EdgeDetectorConfig.cpp
src/pipeline/datatype/TrackedFeatures.cpp
src/pipeline/datatype/FeatureTrackerConfig.cpp
src/utility/Initialization.cpp
src/utility/Resources.cpp
src/utility/Path.cpp
src/utility/Platform.cpp
src/utility/Environment.cpp
src/xlink/XLinkConnection.cpp
src/xlink/XLinkStream.cpp
src/openvino/OpenVINO.cpp
src/openvino/BlobReader.cpp
src/bspatch/bspatch.c

) add_library("${PROJECT_NAME}::${TARGET_CORE_ALIAS}" ALIAS ${TARGET_CORE_NAME})

Specify that we are building core

target_compile_definitions(${TARGET_CORE_NAME} PUBLIC DEPTHAI_TARGET_CORE)

Specifies name of generated IMPORTED target (set to alias)

set_target_properties(${TARGET_CORE_NAME} PROPERTIES EXPORT_NAME ${TARGET_CORE_ALIAS})

Add to list of targets to export and install

list(APPEND targets_to_export ${TARGET_CORE_NAME})

list(APPEND HUNTER_TOOLCHAIN_UNDETECTABLE_ID "-fPIC")

Add default flags to core

add_default_flags(${TARGET_CORE_NAME})

And clang-tidy and format

if(DEPTHAI_CLANG_TIDY) include(ClangTidy) target_clangtidy_setup(${TARGET_CORE_NAME}) endif()

Set compiler features (c++14), and disables extensions (g++14)

set_property(TARGET ${TARGET_CORE_NAME} PROPERTY CXX_STANDARD 14) set_property(TARGET ${TARGET_CORE_NAME} PROPERTY CXX_STANDARD_REQUIRED ON) set_property(TARGET ${TARGET_CORE_NAME} PROPERTY CXX_EXTENSIONS OFF)

Add interface transitive property (C++14)

if(${CMAKE_VERSION} VERSION_LESS "3.8.0") target_compile_features(${TARGET_CORE_NAME} INTERFACE cxx_generic_lambdas) else() target_compile_features(${TARGET_CORE_NAME} INTERFACE cxx_std_14) endif()

First specify options

option(DEPTHAI_BUILD_TESTS "Build tests" OFF) option(DEPTHAI_BUILD_EXAMPLES "Build examples - Requires OpenCV library to be installed" OFF) option(DEPTHAI_BUILD_DOCS "Build documentation - requires doxygen to be installed" OFF) option(DEPTHAI_OPENCV_SUPPORT "Enable optional OpenCV support" ON)

option(DEPTHAI_BINARIES_RESOURCE_COMPILE "Compile Depthai device side binaries into library" ON) option(DEPTHAI_USB2_PATCH_ONLY_MODE "Use patch file and full depthai.cmd binary for usb2 mode" ON) option(DEPTHAI_CMD_PATH "Use local path for depthai.cmd instead of downloading" OFF) if(DEPTHAI_USB2_PATCH_ONLY_MODE) option(DEPTHAI_USB2_PATCH_PATH "Use local path for depthai-usb2-patch.patch instead of downloading" OFF) else() option(DEPTHAI_USB2_CMD_PATH "Use local path for depthai-usb2.cmd instead of downloading" OFF) endif()

if(DEPTHAI_USB2_PATCH_ONLY_MODE) message(STATUS "Compiling ${TARGET_CORE_NAME} resources in PATCH_ONLY mode") else() message(STATUS "Compiling ${TARGET_CORE_NAME} depthai and depthai-usb2 resources") endif()

Set constant

set(DEPTHAI_RESOURCES_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/resources")

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) set(DEPTHAI_BOOTLOADER_SHARED_COMMIT_HASH_ENFORCE ON) endif()

Then get the Depthai device side binaries (local or download)

if(DEPTHAI_CMD_PATH OR DEPTHAI_USB2_CMD_PATH OR DEPTHAI_USB2_PATCH_PATH)

At least 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})

message(STATUS "LIST OF RESOURCE COMPILED FILES: ${RESOURCE_COMPILED_FILES}")

if(DEPTHAI_BINARIES_RESOURCE_COMPILE)

Add RC and resource compile the binares

include(CMakeRC)

set(DEPTHAI_RESOURCE_LIBRARY_NAME "depthai-resources")

# Add resource library
cmrc_add_resource_library("${DEPTHAI_RESOURCE_LIBRARY_NAME}" NAMESPACE depthai
    WHENCE "${DEPTHAI_RESOURCES_OUTPUT_DIR}"
    "${RESOURCE_COMPILED_FILES}"
)

# Link to resource library
target_link_libraries(${TARGET_CORE_NAME} PRIVATE "${DEPTHAI_RESOURCE_LIBRARY_NAME}")

# Set define that binaries are resource compiled
target_compile_definitions(${TARGET_CORE_NAME} PRIVATE DEPTHAI_RESOURCE_COMPILED_BINARIES)

else()

TODO

# Don't add RC and don't resource compile the binaries

endif()

Add include directories

target_include_directories(${TARGET_CORE_NAME} PUBLIC

Relative path to include directories after installed

    "$<INSTALL_INTERFACE:include>"
    "$<INSTALL_INTERFACE:include/${DEPTHAI_SHARED_3RDPARTY_HEADERS_PATH}>"

    # Build time path to include directories
    "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
    "$<BUILD_INTERFACE:${DEPTHAI_SHARED_PUBLIC_INCLUDE}>"
    "$<BUILD_INTERFACE:${DEPTHAI_BOOTLOADER_SHARED_PUBLIC_INCLUDE}>"
#INTERFACE
#    # ...
PRIVATE
    "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include/depthai>"
    "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/src>"
    "$<BUILD_INTERFACE:${DEPTHAI_SHARED_INCLUDE}>"
    "$<BUILD_INTERFACE:${DEPTHAI_BOOTLOADER_SHARED_INCLUDE}>"

)

target_include_directories(${TARGET_CORE_NAME} SYSTEM PUBLIC "$<BUILD_INTERFACE:${DEPTHAI_SHARED_3RDPARTY_INCLUDE}>" )

Add clang format after specifying include directories

if(DEPTHAI_CLANG_FORMAT)

HEADER DIRECTORIES

set(header_dirs "${CMAKE_CURRENT_LIST_DIR}/include" "${DEPTHAI_SHARED_PUBLIC_INCLUDE}" "${DEPTHAI_SHARED_INCLUDE}")
include(ClangFormat)
target_clangformat_setup(${TARGET_CORE_NAME} "${header_dirs}")

endif()

hunter_add_package(ZLIB) find_package(ZLIB CONFIG REQUIRED)

link libraries

target_link_libraries(${TARGET_CORE_NAME} PUBLIC nlohmann_json::nlohmann_json libnop INTERFACE XLinkPublic PRIVATE XLink Threads::Threads BZip2::bz2 FP16::fp16 archive_static spdlog::spdlog ZLIB::zlib )

target_link_libraries(${TARGET_CORE_NAME} PRIVATE ZLIB::ZLIB)

Add compile & CMake definitions

set(DEPTHAI_DEVICE_VERSION "${DEPTHAI_DEVICE_SIDE_COMMIT}") target_compile_definitions(${TARGET_CORE_NAME} PRIVATE

XLink required define

    __PC__
    # Add depthai-device version
    DEPTHAI_DEVICE_VERSION="${DEPTHAI_DEVICE_VERSION}"
    # Add depthai-bootloader version
    DEPTHAI_BOOTLOADER_VERSION="${DEPTHAI_BOOTLOADER_VERSION}"

)

Add Backward dependency if enabled (On by default)

if(DEPTHAI_ENABLE_BACKWARD) target_compile_definitions(${TARGET_CORE_NAME} PRIVATE DEPTHAI_ENABLE_BACKWARD) target_link_libraries(${TARGET_CORE_NAME} PRIVATE Backward::Backward) endif()

Add patch only mode definition

if(DEPTHAI_USB2_PATCH_ONLY_MODE) target_compile_definitions(${TARGET_CORE_NAME} PRIVATE DEPTHAI_PATCH_ONLY_MODE) endif()

Helper function

macro(add_runtime_dependencies depending_target dependency) if(WIN32) if(TARGET ${dependency}) get_property(imported_configs TARGET ${dependency} PROPERTY IMPORTED_CONFIGURATIONS) set(dlls "") foreach(cfg ${imported_configs}) get_property(dll TARGET ${dependency} PROPERTY IMPORTEDLOCATION${cfg}) set(dlls ${depthai_dll_libraries} $<$<CONFIG:${cfg}>:${dll}>) endforeach() endif() file(GLOB depthai_dll_libraries "${HUNTER_INSTALL_PREFIX}/bin/*.dll")

Create a list of required dll files

    set(required_dll_files ${dlls} ${depthai_dll_libraries})
    # Copy the required dlls
    add_custom_command(TARGET ${depending_target} POST_BUILD COMMAND
        ${CMAKE_COMMAND} -E copy_if_different ${required_dll_files} $<TARGET_FILE_DIR:${depending_target}>
        COMMAND_EXPAND_LISTS
    )
    message(STATUS "Required dlls for core are: ${required_dll_files}")
endif()

endmacro()

Add libusb dll in build time

add_runtime_dependencies(${TARGET_CORE_NAME} usb-1.0)

########################

OpenCV Support

######################## set(THIRDPARTY_OPENCV_LIBRARIES "" CACHE STRING "Optional libraries to link OpenCV support, e.g. TBB::tbb") set(TARGET_OPENCV_NAME ${PROJECT_NAME}-opencv) set(TARGET_OPENCV_ALIAS opencv) if(DEPTHAI_OPENCV_SUPPORT)

Check if required libraries are available

set(REQUIRED_OPENCV_LIBRARIES "opencv_core" "opencv_imgproc")
set(OPENCV_SUPPORT_AVAILABLE ${OpenCV_FOUND})
foreach(lib ${REQUIRED_OPENCV_LIBRARIES})
    if(NOT (lib IN_LIST OpenCV_LIBS))
        set(OPENCV_SUPPORT_AVAILABLE FALSE)
    endif()
endforeach()

if(OPENCV_SUPPORT_AVAILABLE)

    # Add depthai-core-opencv library and depthai::core::opencv alias
    add_library(${TARGET_OPENCV_NAME} src/opencv/ImgFrame.cpp)
    add_library("${PROJECT_NAME}::${TARGET_OPENCV_ALIAS}" ALIAS ${TARGET_OPENCV_NAME})
    # Specifies name of generated IMPORTED target (set to alias)
    set_target_properties(${TARGET_OPENCV_NAME} PROPERTIES EXPORT_NAME ${TARGET_OPENCV_ALIAS})

    # Add default flags
    add_default_flags(${TARGET_OPENCV_NAME})
    add_flag(${TARGET_OPENCV_NAME} -Wno-switch-enum)

    # Link to OpenCV (publically)
    target_link_libraries(${TARGET_OPENCV_NAME} PUBLIC ${REQUIRED_OPENCV_LIBRARIES} ${THIRDPARTY_OPENCV_LIBRARIES})

    # Add public compile definition indicating that OpenCV support is available
    set(DEPTHAI_HAVE_OPENCV_SUPPORT ON)

    # Specify that we are building target opencv
    target_compile_definitions(${TARGET_OPENCV_NAME} PUBLIC DEPTHAI_TARGET_OPENCV)

    # Add public dependency to depthai::core library
    target_link_libraries(${TARGET_OPENCV_NAME} PUBLIC ${TARGET_CORE_NAME})

    # Add to clangformat target
    if(COMMAND target_clangformat_setup)
        target_clangformat_setup(${TARGET_OPENCV_NAME} "")
    endif()

    # Add to list of targets to export and install
    list(APPEND targets_to_export ${TARGET_OPENCV_NAME})

    message(STATUS "OpenCV and required libraries (${REQUIRED_OPENCV_LIBRARIES}) found. OpenCV Support enabled")

else()
    message(STATUS "OpenCV or required libraries (${REQUIRED_OPENCV_LIBRARIES}) not found. OpenCV Support disabled")
endif()

endif()

########################

Sanitizers

######################## if(DEPTHAI_SANITIZE) set(SANITIZE_ADDRESS ON CACHE BOOL "Enable AddressSanitizer for sanitized targets." FORCE) set(SANITIZE_UNDEFINED ON CACHE BOOL "Enable UndefinedBehaviorSanitizer for sanitized targets." FORCE) find_package(Sanitizers) add_sanitizers(${TARGET_CORE_NAME}) if(DEPTHAI_HAVE_OPENCV_SUPPORT) add_sanitizers(${TARGET_OPENCV_NAME}) endif() if(DEPTHAI_XLINK_LOCAL) add_sanitizers(XLink) if(XLINK_LIBUSB_LOCAL) add_sanitizers(usb-1.0) endif() endif() endif()

########################

Testing infrastructure

######################## include(CTest) enable_testing()

########################

Tests

######################## if (DEPTHAI_BUILD_TESTS) add_subdirectory(tests) endif()

########################

Examples (can also act as tests)

######################## if (DEPTHAI_BUILD_EXAMPLES) add_subdirectory(examples) endif()

########################

Documentation

######################## if (DEPTHAI_BUILD_DOCS) add_subdirectory(docs) endif()

########################

Build configuration

########################

Add year information

string(TIMESTAMP BUILD_DATETIME "%Y-%m-%d %H:%M:%S +0000" UTC) message(STATUS "BUILD_DATETIME: ${BUILD_DATETIME}, BUILD_COMMIT: ${BUILD_COMMIT}, BUILD_COMMIT_DATETIME: ${BUILD_COMMIT_DATETIME}")

Configure build information (version, opencv support)

configure_file("${CMAKE_CURRENT_LIST_DIR}/cmake/version.hpp.in" "${CMAKE_CURRENT_LIST_DIR}/include/depthai/build/version.hpp") configure_file("${CMAKE_CURRENT_LIST_DIR}/cmake/config.hpp.in" "${CMAKE_CURRENT_LIST_DIR}/include/depthai/build/config.hpp")

########################

Export and install

######################## include(GNUInstallDirs) include(CMakePackageConfigHelpers)

Add additional targets to export group

if(NOT BUILD_SHARED_LIBS) list(APPEND targets_to_export ${DEPTHAI_RESOURCE_LIBRARY_NAME} cmrc-base) endif()

Export targets (capability to import current build directory)

export(TARGETS ${targets_to_export} NAMESPACE ${PROJECT_NAME}:: FILE "${PROJECT_NAME}Targets.cmake")

Dependencies file

configure_file("cmake/${PROJECT_NAME}Dependencies.cmake" ${PROJECT_NAME}Dependencies.cmake COPYONLY)

Write project version

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)

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)

Config for installation

set(DEPTHAI_DEPENDENCIES_INSTALLATION_PATH_REL "./dependencies") configure_file(cmake/${PROJECT_NAME}Config.cmake.in _install/${PROJECT_NAME}Config.cmake @ONLY)

Modify RPath to point to the cmake/depthai/dependencies/lib

note: macOS is APPLE and also UNIX!

if(APPLE) set_target_properties(${TARGET_CORE_NAME} PROPERTIES INSTALL_RPATH @.**@._path/cmake/${PROJECT_NAME}/dependencies/lib") elseif(UNIX) set_target_properties(${TARGET_CORE_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN:$ORIGIN/cmake/${PROJECT_NAME}/dependencies/lib") endif()

Export to CMake registry if specified

if(CMAKE_EXPORT_PACKAGE_REGISTRY) export(PACKAGE depthai) endif()

if(DEPTHAI_INSTALL)

# Install targets
install(
    TARGETS ${targets_to_export}
    EXPORT ${PROJECT_EXPORT_GROUP}
    RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
    LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
    ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)

# Install depthai public headers
install(DIRECTORY include/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
# Install depthai-shared public headers
install(DIRECTORY "${DEPTHAI_SHARED_PUBLIC_INCLUDE}/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
# Install depthai-shared 3rdparty headers
install(DIRECTORY "${DEPTHAI_SHARED_3RDPARTY_INCLUDE}/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${DEPTHAI_SHARED_3RDPARTY_HEADERS_PATH}")
# Install depthai-bootloader-shared public headers
install(DIRECTORY "${DEPTHAI_BOOTLOADER_SHARED_PUBLIC_INCLUDE}/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
# Install Hunter dependencies
install(DIRECTORY "${HUNTER_INSTALL_PREFIX}/" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}/dependencies")
# Install resources if not RC'd
if(NOT DEPTHAI_BINARIES_RESOURCE_COMPILE)
    install(DIRECTORY "${DEPTHAI_RESOURCES_OUTPUT_DIR}/" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}")
endif()
# Install any required dll files
if(DEFINED required_dll_files)
    install(FILES ${required_dll_files} DESTINATION "${CMAKE_INSTALL_BINDIR}")
endif()

# Install export group (information about targets)
install(EXPORT ${PROJECT_EXPORT_GROUP}
    NAMESPACE ${PROJECT_NAME}::
    DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)

# Install CMake specific files
install(FILES
    "${CMAKE_CURRENT_BINARY_DIR}/_install/${PROJECT_NAME}Config.cmake"
    "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
    "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Dependencies.cmake"
    DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)

endif()

##############################

Integration settings export

############################## set(tmp_definitions "$<TARGET_PROPERTY:${TARGET_CORE_NAME},INTERFACE_COMPILE_DEFINITIONS>") set(tmp_includes "$<TARGET_PROPERTY:${TARGET_CORE_NAME},INTERFACE_INCLUDE_DIRECTORIES>") file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/depthai-core-integration.txt" CONTENT "$<$<BOOL:${tmp_definitions}>:\n-D\'$<JOIN:${tmp_definitions},\'\n-D\'>\'>\n $<$<BOOL:${tmp_includes}>:\n-I\'$<JOIN:${tmp_includes},\'\n-I\'>\'>\n" )

if(DEPTHAI_HAVE_OPENCV_SUPPORT) set(tmp_definitions "$<TARGET_PROPERTY:${TARGET_OPENCV_NAME},INTERFACE_COMPILE_DEFINITIONS>") set(tmp_includes "$<TARGET_PROPERTY:${TARGET_OPENCV_NAME},INTERFACE_INCLUDE_DIRECTORIES>") file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/depthai-opencv-integration.txt" CONTENT "$<$<BOOL:${tmp_definitions}>:\n-D\'$<JOIN:${tmp_definitions},\'\n-D\'>\'>\n $<$<BOOL:${tmp_includes}>:\n-I\'$<JOIN:${tmp_includes},\'\n-I\'>\'>\n" ) endif()

NeroBurner commented 1 year ago

Added this line in cmakelist.txt whic is attached in this email cmake -S . -B build_with_fpic -DCMAKE_TOOLCHAIN_FILE=${PWD}/toolchain-pic.cmake

What do you mean by that? Those are commands for the command line. Those don't belong into the cmakelists.txt file. You use those commands to configure and build your cmake project

NeroBurner commented 1 year ago

closed due to inactivity, feel free to reopen