Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
themarpe committed May 4, 2021
2 parents 3507400 + dd15141 commit 9cfcfa7
Show file tree
Hide file tree
Showing 73 changed files with 1,037 additions and 414 deletions.
50 changes: 44 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,24 @@ if(WIN32)
endif()

# Create depthai project
project(depthai VERSION "2.2.1" LANGUAGES CXX C)
project(depthai VERSION "2.3.0" 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)
Expand Down Expand Up @@ -77,6 +89,20 @@ if(GIT_FOUND)
RESULT_VARIABLE DEPTHAI_DOWNLOADED_SOURCES
OUTPUT_QUIET ERROR_QUIET
)
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
Expand Down Expand Up @@ -150,6 +176,8 @@ add_library(${TARGET_CORE_NAME}
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
Expand Down Expand Up @@ -276,10 +304,6 @@ else()

endif()


# Configure build information (version, ...)
configure_file("${CMAKE_CURRENT_LIST_DIR}/cmake/version.hpp.in" "${CMAKE_CURRENT_LIST_DIR}/include/depthai/build/version.hpp")

# Add include directories
target_include_directories(${TARGET_CORE_NAME}
PUBLIC
Expand Down Expand Up @@ -375,7 +399,10 @@ if(DEPTHAI_OPENCV_SUPPORT)
target_link_libraries(${TARGET_OPENCV_NAME} PUBLIC ${REQUIRED_OPENCV_LIBRARIES})

# Add public compile definition indicating that OpenCV support is available
target_compile_definitions(${TARGET_OPENCV_NAME} PUBLIC DEPTHAI_OPENCV_SUPPORT)
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})
Expand Down Expand Up @@ -430,6 +457,17 @@ 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
########################
Expand Down
101 changes: 75 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,65 +21,114 @@ MacOS: `brew install libusb`

Linux: `sudo apt install libusb-1.0-0-dev`

## Using as library
## Integration

To use this library in your own project you can use CMake `add_subdirectory` pointing to the root of this repository
Optionally append `EXCLUDE_FROM_ALL` to hide depthai-core related targets, etc...
### CMake

Targets available to link to are:
- depthai::core - Core library, without using opencv internally
- depthai::opencv - Core + support for opencv related helper functions (requires OpenCV4)

#### Using find_package

Build static or dynamic version of library and install (See: [Building](##building) and [Installing](##installing))

Add `find_package` and `target_link_libraries` to your project
```
find_package(depthai CONFIG REQUIRED)
...
target_link_libraries([my-app] PRIVATE depthai::opencv)
```
add_subdirectory(depthai-core)

And point CMake to either build directory or install directory:
```
-D depthai_DIR=depthai-core/build
```
or
```
add_subdirectory(depthai-core EXCLUDE_FROM_ALL)
-D depthai_DIR=depthai-core/build/install/lib/cmake/depthai
```
And at the end link to your target (PUBLIC or PRIVATE depending on your needs)

If library was installed to default search path like `/usr/local` on Linux, specifying `depthai_DIR` isn't necessary as CMake will find it automatically.

#### Using add_subdirectory

This method is more intrusive but simpler as it doesn't require building the library separately.

Add `add_subdirectory` which points to `depthai-core` folder **before** project command. Then link to any required targets.
```
target_link_libraries(my-app PUBLIC depthai-core)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/depthai-core EXCLUDE_FROM_ALL)
...
project(my-app)
...
target_link_libraries([my-app] PRIVATE depthai::opencv)
```

### Non-CMake integration (Visual Studio, Xcode, CodeBlocks, ...)

To integrate into a different build system than CMake, prefered way is compiling as dynamic library and pointing to correct include directories.
1. First build as dynamic library: [Building Dynamic library](###dynamic-library)
2. Then install: [Installing](##installing)
3. Set needed library directories:
- `build/install/lib` (for linking to either depthai-core or depthai-opencv)
- `build/install/bin` (for .dll's)
4. And include directories
- `build/install/include` (library headers)
- `build/install/include/depthai-shared/3rdparty` (shared 3rdparty headers)
- `build/install/lib/cmake/depthai/dependencies/include` (dependencies headers)

> ℹ️ Threading library might need to be linked to explicitly.
## Building

Make sure submodules are updated
Make sure submodules are updated
```
git submodule update --init --recursive
```

**Static library**
> ℹ️ To speed up build times, use `cmake --build build --parallel [num CPU cores]` (CMake >= 3.12).
For older versions use: Linux/macOS: `cmake --build build -- -j[num CPU cores]`, MSVC: `cmake --build build -- /MP[num CPU cores]`

### Static library
```
mkdir build && cd build
cmake ..
cmake --build . --parallel 8
cmake -H. -Bbuild
cmake --build build
```

**Dynamic library**
### Dynamic library
```
mkdir build && cd build
cmake .. -D BUILD_SHARED_LIBS=ON
cmake --build . --parallel 8
cmake -H. -Bbuild -D BUILD_SHARED_LIBS=ON
cmake --build build
```
## Installing

To install specify optional prefix and build target install
```
cmake .. -D CMAKE_INSTALL_PREFIX=[path/to/install/dir]
cmake --build . --parallel 8
cmake --build . --target install --parallel 8
cmake -H. -Bbuild -D CMAKE_INSTALL_PREFIX=[path/to/install/dir]
cmake --build build
cmake --build build --target install
```

If `CMAKE_INSTALL_PREFIX` isn't specified, the library is installed under build folder `install`.

## Running tests

To run the tests build the library with the following options
```
mkdir build_tests && cd build_tests
cmake .. -D DEPTHAI_TEST_EXAMPLES=ON -D DEPTHAI_BUILD_TESTS=ON -D DEPTHAI_BUILD_EXAMPLES=ON
cmake --build . --parallel 8
cmake -H. -Bbuild -D DEPTHAI_TEST_EXAMPLES=ON -D DEPTHAI_BUILD_TESTS=ON -D DEPTHAI_BUILD_EXAMPLES=ON
cmake --build build
```

Then navigate to `build` folder and run `ctest`
```
cd build
ctest
```

## Style check

The library uses clang format to enforce a certain style.
If a style check is failing, run the `clangformat` target, check the output and push changes
The library uses clang format to enforce a certain coding style.
If a style check is failing, run the `clangformat` target, check the output and push changes.

To use this target clang format must be installed, preferably clang-format-10
```
Expand All @@ -88,7 +137,7 @@ sudo apt install clang-format-10

And to apply formatting
```
cmake --build [build/dir] --target clangformat
cmake --build build --target clangformat
```

## Documentation generation
Expand Down Expand Up @@ -119,7 +168,7 @@ This retains the libraries source code, so that debugger can step through it (th
## Troubleshooting

### Hunter
Hunter is a CMake-only dependency manager for C/C++ projects.
Hunter is a CMake-only dependency manager for C/C++ projects.

If you are stuck with error message which mentions external libraries (subdirectory of `.hunter`) like the following:
```
Expand Down
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 "595330292c4bd1955e4e8046b0f42af2dba4b124")
set(DEPTHAI_DEVICE_SIDE_COMMIT "16652fb049b5a9b47e3098d94fb9cedc353f82e9")

# "version if applicable"
set(DEPTHAI_DEVICE_SIDE_VERSION "")
14 changes: 14 additions & 0 deletions cmake/config.hpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Generated by CMake build tool.
*/
#pragma once

// This build supports OpenCV integration?
#cmakedefine DEPTHAI_HAVE_OPENCV_SUPPORT

// Build specific settings overwrite
#ifdef DEPTHAI_TARGET_CORE
#ifndef DEPTHAI_TARGET_OPENCV
#undef DEPTHAI_HAVE_OPENCV_SUPPORT
#endif
#endif
26 changes: 15 additions & 11 deletions cmake/version.hpp.in
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
/*
* Generated by CMake build tool.
* To modify version, open CMakeLists.txt and bump the version in project() function
/*
* Generated by CMake build tool.
* To modify version, open CMakeLists.txt and bump the version in project() function
*/

#pragma once

namespace dai
{
namespace build
{
constexpr static const char* VERSION = "${PROJECT_VERSION}";
constexpr static const int VERSION_MAJOR = ${PROJECT_VERSION_MAJOR};
constexpr static const int VERSION_MINOR = ${PROJECT_VERSION_MINOR};
constexpr static const int VERSION_PATCH = ${PROJECT_VERSION_PATCH};
} // namespace Build
namespace build
{
constexpr static const char* VERSION = "${PROJECT_VERSION}";
constexpr static const int VERSION_MAJOR = ${PROJECT_VERSION_MAJOR};
constexpr static const int VERSION_MINOR = ${PROJECT_VERSION_MINOR};
constexpr static const int VERSION_PATCH = ${PROJECT_VERSION_PATCH};

constexpr static const char* COMMIT = "${BUILD_COMMIT}";
constexpr static const char* COMMIT_DATETIME = "${BUILD_COMMIT_DATETIME}";
constexpr static const char* BUILD_DATETIME = "${BUILD_DATETIME}";
} // namespace build
} // namespace dai
2 changes: 1 addition & 1 deletion docs/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -2199,7 +2199,7 @@ INCLUDE_FILE_PATTERNS =
# recursively expanded use the := operator instead of the = operator.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.

PREDEFINED = DEPTHAI_OPENCV_SUPPORT
PREDEFINED = DEPTHAI_HAVE_OPENCV_SUPPORT

# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
# tag can be used to specify a list of macro names that should be expanded. The
Expand Down
16 changes: 10 additions & 6 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ option(DEPTHAI_TEST_EXAMPLES "Test examples - examples will be ran as a part of

# Dependencies
find_package(OpenCV REQUIRED)
find_package(Sanitizers)

# Create utility library
add_library(utility src/utility.cpp)
Expand All @@ -13,13 +14,16 @@ macro(dai_add_example example_name example_src)
add_executable("${example_name}" "${example_src}")
target_link_libraries("${example_name}" PRIVATE utility depthai::opencv ${OpenCV_LIBS})

# Add sanitizers for example
add_sanitizers(${example_name})

# Add to clangformat target
target_clangformat_setup(${example_name} "")

# parse the rest of the arguments
set(arguments ${ARGV})
list(REMOVE_AT arguments 0 1)

# If 'DEPTHAI_TEST_EXAMPLES' is ON, then examples will be part of the test suite
if(DEPTHAI_TEST_EXAMPLES)
add_test(NAME ${example_name} COMMAND ${CMAKE_COMMAND}
Expand All @@ -28,16 +32,13 @@ macro(dai_add_example example_name example_src)
)

# Sets a regex catching any logged warnings, errors or critical (coming either from device or host)
set_tests_properties (${example_name} PROPERTIES FAIL_REGULAR_EXPRESSION "\\[warning\\];\\[error\\];\\[critical\\]")

# Add sanitizers for tests as well
add_sanitizers(${example_name})
set_tests_properties (${example_name} PROPERTIES FAIL_REGULAR_EXPRESSION "\\[warning\\];\\[error\\];\\[critical\\]")

# Add ubsan halt on error
set_tests_properties(${example_name} PROPERTIES ENVIRONMENT "UBSAN_OPTIONS=halt_on_error=1")

endif()
endmacro()
endmacro()

# Create a custom target which runs all examples for 10 seconds max, and check if they executed without errors

Expand Down Expand Up @@ -130,6 +131,9 @@ dai_add_example(device_queue_event src/device_queue_event_example.cpp)
# OpenCV support example
dai_add_example(opencv_support src/opencv_support_example.cpp)

# RGB-depth alignment example
dai_add_example(rgb_depth_aligned src/rgb_depth_aligned_example.cpp)

# Device side decoding example for mobilenet-ssd
dai_add_example(mobilenet_device_side_decoding src/mobilenet_device_side_decoding_example.cpp)
target_compile_definitions(mobilenet_device_side_decoding PRIVATE BLOB_PATH="${mobilenet_blob}")
Expand Down
4 changes: 1 addition & 3 deletions examples/src/camera_mobilenet_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@ int main(int argc, char** argv) {
// Create pipeline
dai::Pipeline p = createNNPipeline(nnPath);

// Connect to device with above created pipeline
// Connect and start the pipeline
dai::Device d(p);
// Start the pipeline
d.startPipeline();

cv::Mat frame;
auto preview = d.getOutputQueue("preview");
Expand Down
1 change: 0 additions & 1 deletion examples/src/camera_mobilenet_sync_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ int main(int argc, char** argv) {

// Connect to device and start pipeline
dai::Device device(pipeline);
device.startPipeline();

// Create input & output queues
auto previewQueue = device.getOutputQueue("preview");
Expand Down
Loading

0 comments on commit 9cfcfa7

Please sign in to comment.