Skip to content

Commit

Permalink
Merge branch 'release_2.15.0' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
themarpe committed Feb 23, 2022
2 parents c2ccafd + ff7f462 commit 5cafb68
Show file tree
Hide file tree
Showing 111 changed files with 2,498 additions and 856 deletions.
2 changes: 2 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
---
Checks: '-*,clang-analyzer-*,clang-diagnostic-*,readability-*,modernize-*,boost-*,bugprone-*,cppcoreguidelines-*,google-*,hicpp-*,performance-*,readability-*,-google-readability-namespace-comments,-readability-inconsistent-declaration-parameter-name,-readability-braces-around-statements,-hicpp-signed-bitwise,-google-runtime-references,-cppcoreguidelines-avoid-magic-numbers,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-readability-magic-numbers,-hicpp-explicit-conversions,-hicpp-uppercase-literal-suffix,-readability-uppercase-literal-suffix,-hicpp-no-array-decay,-hicpp-special-member-functions,-bugprone-narrowing-conversions,-modernize-use-nodiscard,-google-readability-braces-around-statements,-hicpp-braces-around-statements,-bugprone-suspicious-semicolon,-readability-named-parameter,-hicpp-named-parameter,-modernize-use-trailing-return-type,-cppcoreguidelines-non-private-member-variables-in-classes,-cppcoreguidelines-pro-bounds-constant-array-index'
# TODO(themarpe) - Gradually bring back errors
#WarningsAsErrors: 'modernize-*,cppcoreguidelines-*,boost-*,performance-*,google-build-using-namespace,readability-else-after-return,google-readability-todo'
WarningsAsErrors: 'bugprone-throw-keyword-missing'
HeaderFilterRegex: 'core/.*\.hpp'
AnalyzeTemporaryDtors: false
FormatStyle: .clang-format
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/main.workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ jobs:
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
cmake: ['3.10.x', ''] # Older version (Ubuntu 18.04) and newest

exclude:
- os: windows-latest
cmake: '3.10.x'
steps:
- name: Cache .hunter folder
if: matrix.os != 'windows-latest'
Expand Down Expand Up @@ -118,6 +120,13 @@ jobs:
cmake -H. -Bbuild -D'DEPTHAI_BUILD_EXAMPLES=ON' -D'DEPTHAI_BUILD_TESTS=ON' ${{ env.CMAKE_ARGS }}
cmake --build build -- -j4
# CMake binaries unavailable
# - name: Build (old CMake, MSVC)
# if: matrix.cmake == '3.10.x' && matrix.os == 'windows-latest'
# run: |
# cmake -H. -Bbuild -D'DEPTHAI_BUILD_EXAMPLES=ON' -D'DEPTHAI_BUILD_TESTS=ON'
# cmake --build build

- name: Build (newest CMake)
if: matrix.cmake != '3.10.x'
run: |
Expand Down
70 changes: 70 additions & 0 deletions .github/workflows/test.workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: DepthAI Core HIL Testing

on:
workflow_dispatch:
push:
branches:
- main
- develop
tags:
- 'v*'
pull_request:
branches:
- main
- develop

# Only allow latest run on same branch to be tested
concurrency:
group: ci-tests-${{ github.ref }}-1
cancel-in-progress: true

jobs:

# Testing
test:
strategy:
matrix:
os: ['windows', 'macos', 'linux']
arch: ['x64']
flavor: ['vanilla', 'asan-ubsan', 'tsan']
exclude:
- os: 'windows'
arch: 'x64'
flavor: 'tsan'
fail-fast: false
runs-on: ['self-hosted', '${{ matrix.os }}', '${{ matrix.arch }}']

steps:
- name: Cache .hunter folder
uses: actions/cache@v2
with:
path: $HOME/.hun_${{ matrix.flavor }}
key: hunter-${{ matrix.os }}-${{ matrix.cmake }}
- uses: actions/checkout@v2
with:
submodules: 'recursive'

- name: Specify toolchain path
if: matrix.flavor == 'vanilla'
run: echo "CMAKE_TOOLCHAIN_PATH=" >> $GITHUB_ENV
- name: Specify toolchain path
if: matrix.flavor != 'vanilla'
run: echo "CMAKE_TOOLCHAIN_PATH=$PWD/cmake/toolchain/${{ matrix.flavor }}.cmake" >> $GITHUB_ENV

- name: Configure, Build and Test
if: matrix.os != 'linux'
run: |
cmake -S . -B build -D CMAKE_BUILD_TYPE=Release -D HUNTER_ROOT=$HOME/.hun_${{ matrix.flavor }} -D DEPTHAI_BUILD_EXAMPLES=ON -D DEPTHAI_BUILD_TESTS=ON -D DEPTHAI_TEST_EXAMPLES=ON
cmake --build build --parallel 8 --config Release
cd build
ctest -C Release --output-on-failure -L usb
- name: Configure, Build and Test
if: matrix.os == 'linux'
run: |
export DISPLAY=:99
xdpyinfo -display $DISPLAY >/dev/null 2>&1 || (Xvfb $DISPLAY &)
cmake -S . -B build -D CMAKE_BUILD_TYPE=Release -D HUNTER_ROOT=$HOME/.hun_${{ matrix.flavor }} -D DEPTHAI_BUILD_EXAMPLES=ON -D DEPTHAI_BUILD_TESTS=ON -D DEPTHAI_TEST_EXAMPLES=ON
cmake --build build --parallel 8 --config Release
cd build
ctest -C Release --output-on-failure -L usb
47 changes: 29 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ if(NOT WIN32)
set(HUNTER_CONFIGURATION_TYPES "Release" CACHE STRING "Hunter dependencies list of build configurations")
endif()

# Read the BUILD_SHARED_LIBS option and select PIC toolchain
if(BUILD_SHARED_LIBS)
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_LIST_DIR}/cmake/toolchain/pic.cmake" CACHE STRING "")
endif()
# Specify exporting all symbols on Windows
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON CACHE BOOL "")
# Create a custom toolchain to pass certain options to dependencies
set(gen_toolchain "${CMAKE_CURRENT_BINARY_DIR}/generated/toolchain.cmake")
configure_file(
"${CMAKE_CURRENT_LIST_DIR}/cmake/toolchain/custom.cmake.in"
"${gen_toolchain}"
@ONLY
)
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")
Expand All @@ -28,7 +33,7 @@ if(WIN32)
endif()

# Create depthai project
project(depthai VERSION "2.14.1" LANGUAGES CXX C)
project(depthai VERSION "2.15.0" LANGUAGES CXX C)
get_directory_property(has_parent PARENT_DIRECTORY)
if(has_parent)
set(DEPTHAI_VERSION ${PROJECT_VERSION} PARENT_SCOPE)
Expand Down Expand Up @@ -99,6 +104,11 @@ if(FORCE_COLORED_OUTPUT)
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")

Expand Down Expand Up @@ -179,6 +189,7 @@ add_library(${TARGET_CORE_NAME}
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
Expand All @@ -195,6 +206,8 @@ add_library(${TARGET_CORE_NAME}
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
Expand All @@ -204,6 +217,7 @@ add_library(${TARGET_CORE_NAME}
src/utility/Initialization.cpp
src/utility/Resources.cpp
src/utility/Platform.cpp
src/utility/Environment.cpp
src/xlink/XLinkConnection.cpp
src/xlink/XLinkStream.cpp
src/openvino/OpenVINO.cpp
Expand Down Expand Up @@ -403,15 +417,6 @@ target_compile_definitions(${TARGET_CORE_NAME}
# Add depthai-bootloader version
DEPTHAI_BOOTLOADER_VERSION="${DEPTHAI_BOOTLOADER_VERSION}"
)
# Check if MSVC and add a conforming preprocessor flag (libnop serialization macros)
if (MSVC)
if(MSVC_VERSION LESS 1925)
target_compile_options(${TARGET_CORE_NAME} PUBLIC "/experimental:preprocessor")
else()
target_compile_options(${TARGET_CORE_NAME} PUBLIC "/Zc:preprocessor")
endif()
endif()


# Add Backward dependency if enabled (On by default)
if(DEPTHAI_ENABLE_BACKWARD)
Expand Down Expand Up @@ -486,7 +491,13 @@ 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} ${TARGET_OPENCV_NAME})
add_sanitizers(${TARGET_CORE_NAME})
if(DEPTHAI_HAVE_OPENCV_SUPPORT)
add_sanitizers(${TARGET_OPENCV_NAME})
endif()
if(DEPTHAI_XLINK_LOCAL)
add_sanitizers(XLink)
endif()
endif()

########################
Expand Down
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,23 @@ cmake --build build --target install
If `CMAKE_INSTALL_PREFIX` isn't specified, the library is installed under build folder `install`.


## Environment variables

The following environment variables can be set to alter default behavior of the library without having to recompile

| Environment variable | Description |
|--------------|-----------|
| DEPTHAI_INSTALL_SIGNAL_HANDLER | Set to 0 to disable installing Backward signal handler for stack trace printing |
| DEPTHAI_WATCHDOG | Sets device watchdog timeout. Useful for debugging (`DEPTHAI_WATCHDOG=0`), to prevent device reset while the process is paused. |
| DEPTHAI_WATCHDOG_INITIAL_DELAY | Specifies delay after which the device watchdog starts. |
| DEPTHAI_SEARCH_TIMEOUT | Specifies timeout in milliseconds for device searching in blocking functions. |
| DEPTHAI_CONNECT_TIMEOUT | Specifies timeout in milliseconds for establishing a connection to a given device. |
| DEPTHAI_BOOTUP_TIMEOUT | Specifies timeout in milliseconds for waiting the device to boot after sending the binary. |
| DEPTHAI_PROTOCOL | Restricts default search to the specified protocol. Options: any, usb, tcpip. |
| DEPTHAI_DEVICE_BINARY | Overrides device Firmware binary. Mostly for internal debugging purposes. |
| DEPTHAI_BOOTLOADER_BINARY_USB | Overrides device USB Bootloader binary. Mostly for internal debugging purposes. |
| DEPTHAI_BOOTLOADER_BINARY_ETH | Overrides device Network Bootloader binary. Mostly for internal debugging purposes. |

## Running tests

To run the tests build the library with the following options
Expand All @@ -151,10 +168,17 @@ cmake -S. -Bbuild -D'DEPTHAI_TEST_EXAMPLES=ON' -D'DEPTHAI_BUILD_TESTS=ON' -D'DEP
cmake --build build
```

Then navigate to `build` folder and run `ctest`
Then navigate to `build` folder and run `ctest` with specified labels that denote device type to test on.
Currently available labels:
- usb
- poe

```
cd build
ctest
# Run tests on USB devices
ctest -L usb
# Run tests on PoE devices
ctest -L poe
```

## Style check
Expand Down
10 changes: 7 additions & 3 deletions cmake/ClangTidy.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
function(target_clangtidy_setup target)

if(NOT CLANG_TIDY_BIN)
find_program(CLANG_TIDY_BIN clang-tidy)
endif()
set(CLANG_TIDY_NAMES clang-tidy clang-tidy-10 clang-tidy-11)
foreach(clangtidy ${CLANG_TIDY_NAMES})
if(CLANG_TIDY_BIN)
break()
endif()
find_program(CLANG_TIDY_BIN ${clangtidy})
endforeach()

if(NOT CLANG_TIDY_BIN)
message(FATAL_ERROR "clang-tidy is not installed. Aborting...")
Expand Down
2 changes: 1 addition & 1 deletion cmake/Depthai/DepthaiBootloaderConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ set(DEPTHAI_BOOTLOADER_MATURITY "release")
#set(DEPTHAI_BOOTLOADER_MATURITY "snapshot")

# "version if applicable"
set(DEPTHAI_BOOTLOADER_VERSION "0.0.15")
set(DEPTHAI_BOOTLOADER_VERSION "0.0.17")
#set(DEPTHAI_BOOTLOADER_VERSION "870bec4ca0ef026ddb9c490a38dfe9d097614554")
2 changes: 1 addition & 1 deletion cmake/Depthai/DepthaiDeviceSideConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot")

# "full commit hash of device side binary"
set(DEPTHAI_DEVICE_SIDE_COMMIT "f503b7adfd44b696187b7825a12a134ded0ca3f3")
set(DEPTHAI_DEVICE_SIDE_COMMIT "fbbd61aaa70e094d40800e8e6cbb23548ecc24af")

# "version if applicable"
set(DEPTHAI_DEVICE_SIDE_VERSION "")
89 changes: 62 additions & 27 deletions cmake/Flags.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## setup compilation flags
# conditionally applies flag. If flag is supported by current compiler, it will be added to compile options.
include(CMakeParseArguments)
include(CheckCXXCompilerFlag)

# conditionally applies flag. If flag is supported by current compiler, it will be added to compile options.
function(add_flag target flag)
check_cxx_compiler_flag(${flag} FLAG_${flag})
if (FLAG_${flag} EQUAL 1)
Expand All @@ -9,38 +11,71 @@ function(add_flag target flag)
endfunction()

function(add_default_flags target)
cmake_parse_arguments(ADF "LEAN" "" "" ${ARGN})
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(AppleClang|Clang|GNU)$")
# enable those flags
add_flag(${target} -Wall)
add_flag(${target} -Wextra)
add_flag(${target} -Woverloaded-virtual) # warn if you overload (not override) a virtual function
add_flag(${target} -Wformat=2) # warn on security issues around functions that format output (ie printf)
add_flag(${target} -Wmisleading-indentation) # (only in GCC >= 6.0) warn if indentation implies blocks where blocks do not exist
add_flag(${target} -Wduplicated-cond) # (only in GCC >= 6.0) warn if if / else chain has duplicated conditions
add_flag(${target} -Wduplicated-branches) # (only in GCC >= 7.0) warn if if / else branches have duplicated code
add_flag(${target} -Wnull-dereference) # (only in GCC >= 6.0) warn if a null dereference is detected
add_flag(${target} -Wdouble-promotion) # (GCC >= 4.6, Clang >= 3.8) warn if float is implicit promoted to double
add_flag(${target} -Wsign-compare)
add_flag(${target} -Wtype-limits) # size_t - size_t >= 0 -> always true
if(NOT ADF_LEAN)
# enable those flags
add_flag(${target} -Wall)
add_flag(${target} -Wextra)
add_flag(${target} -Woverloaded-virtual) # warn if you overload (not override) a virtual function
add_flag(${target} -Wformat=2) # warn on security issues around functions that format output (ie printf)
add_flag(${target} -Wmisleading-indentation) # (only in GCC >= 6.0) warn if indentation implies blocks where blocks do not exist
add_flag(${target} -Wduplicated-cond) # (only in GCC >= 6.0) warn if if / else chain has duplicated conditions
add_flag(${target} -Wduplicated-branches) # (only in GCC >= 7.0) warn if if / else branches have duplicated code
add_flag(${target} -Wnull-dereference) # (only in GCC >= 6.0) warn if a null dereference is detected
add_flag(${target} -Wdouble-promotion) # (GCC >= 4.6, Clang >= 3.8) warn if float is implicit promoted to double
add_flag(${target} -Wsign-compare)
add_flag(${target} -Wtype-limits) # size_t - size_t >= 0 -> always true

# disable those flags
# add_flag(${target} -Wno-unused-command-line-argument) # clang: warning: argument unused during compilation: '--coverage' [-Wunused-command-line-argument]
# add_flag(${target} -Wno-unused-parameter) # prints too many useless warnings
# add_flag(${target} -Wno-format-nonliteral) # prints way too many warnings from spdlog
# add_flag(${target} -Wno-gnu-zero-variadic-macro-arguments) # https://stackoverflow.com/questions/21266380/is-the-gnu-zero-variadic-macro-arguments-safe-to-ignore
# disable those flags
# add_flag(${target} -Wno-unused-command-line-argument) # clang: warning: argument unused during compilation: '--coverage' [-Wunused-command-line-argument]
# add_flag(${target} -Wno-unused-parameter) # prints too many useless warnings
# add_flag(${target} -Wno-format-nonliteral) # prints way too many warnings from spdlog
# add_flag(${target} -Wno-gnu-zero-variadic-macro-arguments) # https://stackoverflow.com/questions/21266380/is-the-gnu-zero-variadic-macro-arguments-safe-to-ignore

# promote to errors
add_flag(${target} -Werror=self-assign-field) # error if self assign - bugprone
add_flag(${target} -Werror=unused-lambda-capture) # error if lambda capture is unused
add_flag(${target} -Werror=return-type) # warning: control reaches end of non-void function [-Wreturn-type]
add_flag(${target} -Werror=non-virtual-dtor) # warn the user if a class with virtual functions has a non-virtual destructor. This helps catch hard to track down memory errors
add_flag(${target} -Werror=sign-compare) # warn the user if they compare a signed and unsigned numbers
add_flag(${target} -Werror=reorder) # field '$1' will be initialized after field '$2'
add_flag(${target} -Werror=switch-enum) # if switch case is missing - error
# promote to errors
add_flag(${target} -Werror=self-assign-field) # error if self assign - bugprone
add_flag(${target} -Werror=unused-lambda-capture) # error if lambda capture is unused
add_flag(${target} -Werror=return-type) # warning: control reaches end of non-void function [-Wreturn-type]
add_flag(${target} -Werror=non-virtual-dtor) # warn the user if a class with virtual functions has a non-virtual destructor. This helps catch hard to track down memory errors
add_flag(${target} -Werror=sign-compare) # warn the user if they compare a signed and unsigned numbers
add_flag(${target} -Werror=reorder) # field '$1' will be initialized after field '$2'
add_flag(${target} -Werror=switch-enum) # if switch case is missing - error
endif()

elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# using Visual Studio C++
# TODO(warchant): add flags https://github.com/lefticus/cppbestpractices/blob/master/02-Use_the_Tools_Available.md#msvc
if(NOT ADF_LEAN)
# TODO(warchant): add flags https://github.com/lefticus/cppbestpractices/blob/master/02-Use_the_Tools_Available.md#msvc
endif()

# disable INTERPROCEDURAL_OPTIMIZATION and enable /LTCG for issue https://github.com/luxonis/depthai-core/issues/334
if(WIN32)
get_target_property(_EXPORT ${target} WINDOWS_EXPORT_ALL_SYMBOLS)
if(_EXPORT)
if(CMAKE_BUILD_TYPE)
string(TOUPPER "_${CMAKE_BUILD_TYPE}" _BUILD_TYPE)
else()
set(_BUILD_TYPE "")
endif()
set(_PROP_NAME INTERPROCEDURAL_OPTIMIZATION${_BUILD_TYPE})
get_property(_PROP_SET TARGET ${target} PROPERTY ${_PROP_NAME} SET)
if(NOT _PROP_SET)
set(_PROP_NAME INTERPROCEDURAL_OPTIMIZATION)
endif()
get_target_property(_INTER_OPT ${target} ${_PROP_NAME})
if(_INTER_OPT)
set_target_properties(${target} PROPERTIES ${_PROP_NAME} OFF)
# check_linker_flag() only available in cmake 3.18+
target_link_options(${target} PRIVATE /LTCG)
endif()
unset(_BUILD_TYPE)
unset(_INTER_OPT)
unset(_PROP_NAME)
unset(_PROP_SET)
endif()
unset(_EXPORT)
endif()
endif()

endfunction()
Loading

0 comments on commit 5cafb68

Please sign in to comment.