Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions examples/c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
# 3.10 is the version shipped with Ubuntu 18.04, which is the base of NVIDIA JetPack 4.6.
cmake_minimum_required(VERSION 3.10)
project(scanbotsdk_c_example C)
set(CMAKE_C_STANDARD 99)

# Find or download Scanbot SDK
if(NOT SCANBOTSDK_VERSION)
message(FATAL_ERROR "SCANBOTSDK_VERSION is not set.")
set(SCANBOTSDK_VERSION "9.0.0")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we merge the PR only after v9 release is published?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we're not in a hurry to merge

endif()
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
set(SCANBOTSDK_DIR "${CMAKE_CURRENT_BINARY_DIR}/scanbotsdk")
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
find_package(ScanbotSDK REQUIRED)

file(GLOB_RECURSE SOURCE_FILES CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/*.c)
file(GLOB_RECURSE SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.c")
add_executable(scanbotsdk_example ${SOURCE_FILES})
target_include_directories(scanbotsdk_example PRIVATE include)
target_link_libraries(scanbotsdk_example PRIVATE scanbotsdk)
target_link_libraries(scanbotsdk_example PRIVATE ScanbotSDK::ScanbotSDK)

if(WIN32)
add_custom_command(TARGET scanbotsdk_example POST_BUILD
Comment thread
kyrylo-volkov-apryse marked this conversation as resolved.
COMMAND "${CMAKE_COMMAND}" -E copy_if_different
"$<TARGET_FILE:ScanbotSDK::ScanbotSDK>"
"$<TARGET_FILE_DIR:scanbotsdk_example>"
)
endif()

55 changes: 42 additions & 13 deletions examples/c/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

> Scanbot SDK requires Jetpack 6.1, CUDA 12.6 and TensorRT 10.3 to run with GPU acceleration.

* Install a C compiler, CMake and wget:
* Install a C compiler and CMake:

```bash
sudo apt install -y cmake build-essential wget
sudo apt install -y cmake build-essential
```

* Optionally, install CUDA and TensorRT for GPU acceleration. Make sure that you're running a supported Jetpack version.
Expand All @@ -29,29 +29,58 @@ sudo jetson_clocks --restore

* You're now ready to run the examples.

----

### Raspberry Pi OS, Ubuntu, Debian

* Install a C compiler, CMake and wget:
* Install a C compiler and CMake:

```bash
sudo apt install -y cmake build-essential wget
sudo apt install -y cmake build-essential
```

* You're now ready to build the examples.

### Windows

Requirements:

* Visual Studio C++ Build Tools
* CMake 3.10+
* Recommended: ninja

## Building the Examples

In order to build all examples, run the following commands:

```bash
mkdir build
cd build
# Replace `<SCANBOTSDK_VERSION>` with the actual version number of the SDK you want to install.
cmake -DSCANBOTSDK_VERSION=<SCANBOTSDK_VERSION> ..
make
```
* With ninja (recommended):
```bash
mkdir build
cd build
# Replace `<SCANBOTSDK_VERSION>` with the actual version number of the SDK you want to install.
cmake -GNinja -DSCANBOTSDK_VERSION=<SCANBOTSDK_VERSION> ..
ninja
```

* With make:

```bash
mkdir build
cd build
# Replace `<SCANBOTSDK_VERSION>` with the actual version number of the SDK you want to install.
cmake -DSCANBOTSDK_VERSION=<SCANBOTSDK_VERSION> ..
make
```

* With MS Visual Studio (Windows-only):

```powershell
mkdir build
cd build
# Replace `<SCANBOTSDK_VERSION>` with the actual version number of the SDK you want to install.
cmake "-DSCANBOTSDK_VERSION=<SCANBOTSDK_VERSION>" ..
msbuild scanbotsdk_c_example.sln
# scanbotsdk_example.exe will be created under Debug\
```


## Usage
The example supports four modes: **scan**, **analyze**, **classify**, and **parse**.
Expand Down
17 changes: 17 additions & 0 deletions examples/c/cmake/Download.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Download.cmake
if(NOT URL OR NOT DEST)
message(FATAL_ERROR "Both URL and DEST variables must be defined.")
endif()

file(DOWNLOAD "${URL}" "${DEST}"
STATUS status
TLS_VERIFY ON
)

list(GET status 0 status_code)
list(GET status 1 status_string)

if(NOT status_code EQUAL 0)
file(REMOVE "${DEST}")
message(FATAL_ERROR "Download failed (${status_code}): ${status_string}")
endif()
114 changes: 87 additions & 27 deletions examples/c/cmake/FindScanbotSDK.cmake
Original file line number Diff line number Diff line change
@@ -1,47 +1,107 @@
include(ExternalProject)
include(FindPackageHandleStandardArgs)

if(NOT SCANBOTSDK_DIR)
message(FATAL_ERROR "SCANBOTSDK_DIR not set")
if(TARGET ScanbotSDK::ScanbotSDK)
return()
endif()

if (NOT EXISTS ${SCANBOTSDK_DIR})
if(NOT DEFINED SCANBOTSDK_VERSION)
message(FATAL_ERROR "SCANBOTSDK_VERSION is not set.")
endif()

if(NOT DEFINED SCANBOTSDK_DIR)
set(SCANBOTSDK_DIR "${CMAKE_CURRENT_BINARY_DIR}")
endif()

if(NOT EXISTS "${SCANBOTSDK_DIR}/scanbotsdk")
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(SCANBOTSDK_TARGET "windows-x86")
else()
set(SCANBOTSDK_TARGET "windows-x64")
endif()
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
if(CMAKE_SYSTEM_PROCESSOR MATCHES ".*arm.*" OR CMAKE_SYSTEM_PROCESSOR MATCHES ".*aarch64.*")
set(SCANBOTSDK_TARGET "linux-aarch64")
else()
set(SCANBOTSDK_TARGET "linux-x86_64")
endif()
else()
message(FATAL_ERROR "System ${CMAKE_SYSTEM_NAME} not supported")
endif()

find_program(WGET_PATH wget REQUIRED)
set(_archive "${SCANBOTSDK_DIR}/scanbotsdk-${SCANBOTSDK_VERSION}-${SCANBOTSDK_TARGET}.tar.gz")
Comment thread
kyrylo-volkov-apryse marked this conversation as resolved.
set(_url "https://github.com/doo/scanbot-sdk-example-linux/releases/download/standalone-sdk%2Fv${SCANBOTSDK_VERSION}/scanbotsdk-${SCANBOTSDK_VERSION}-${SCANBOTSDK_TARGET}.tar.gz")

message(STATUS "Downloading ScanbotSDK ${SCANBOTSDK_VERSION} to ${SCANBOTSDK_DIR}")
file(MAKE_DIRECTORY "${SCANBOTSDK_DIR}")

if ("${CMAKE_HOST_SYSTEM_PROCESSOR}" MATCHES ".*arm.*" OR "${CMAKE_HOST_SYSTEM_PROCESSOR}" MATCHES ".*aarch64.*")
set(SCANBOTSDK_ARCHITECTURE "aarch64")
else ()
set(SCANBOTSDK_ARCHITECTURE "x86_64")
endif ()
string(TOLOWER "${CMAKE_HOST_SYSTEM_NAME}-${SCANBOTSDK_ARCHITECTURE}" PLATFORM_ID)
set(URL "https://github.com/doo/scanbot-sdk-example-linux/releases/download/standalone-sdk%2Fv${SCANBOTSDK_VERSION}/scanbotsdk-${SCANBOTSDK_VERSION}-linux-${SCANBOTSDK_ARCHITECTURE}.tar.gz")
execute_process(
COMMAND ${WGET_PATH} "${URL}"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMAND "${CMAKE_COMMAND}"
"-DURL=${_url}"
"-DDEST=${_archive}"
-P "${CMAKE_CURRENT_LIST_DIR}/Download.cmake"
RESULT_VARIABLE _rc
)
if(NOT _rc EQUAL 0)
file(REMOVE "${_archive}")
message(FATAL_ERROR "Failed to download Scanbot SDK from ${_url}")
endif()

execute_process(
COMMAND tar -xf scanbotsdk-${SCANBOTSDK_VERSION}-${PLATFORM_ID}.tar.gz
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMAND "${CMAKE_COMMAND}" -E tar -xf "${_archive}"
WORKING_DIRECTORY "${SCANBOTSDK_DIR}"
RESULT_VARIABLE _rc
)
if(NOT _rc EQUAL 0)
file(REMOVE "${_archive}")
file(REMOVE_RECURSE "${SCANBOTSDK_DIR}/scanbotsdk")
message(FATAL_ERROR "Failed to extract Scanbot SDK archive ${_archive}")
endif()

file(REMOVE "${_archive}")
endif()

find_library(ScanbotSDK_LIBS
NAMES libscanbotsdk.so
HINTS ${SCANBOTSDK_DIR}/lib/
)
NAMES scanbotsdk
PATHS "${SCANBOTSDK_DIR}/scanbotsdk/lib"
NO_DEFAULT_PATH
)

find_path(ScanbotSDK_INCLUDE_DIRS
NAMES ScanbotSDK.h
HINTS ${SCANBOTSDK_DIR}/include/)
PATHS "${SCANBOTSDK_DIR}/scanbotsdk/include"
NO_DEFAULT_PATH
)

set(SCANBOTSDK_REQUIRED_VARS ScanbotSDK_LIBS ScanbotSDK_INCLUDE_DIRS)

if(WIN32)
find_file(ScanbotSDK_DLL
NAMES scanbotsdk.dll
PATHS "${SCANBOTSDK_DIR}/scanbotsdk/lib"
NO_DEFAULT_PATH
)
list(APPEND SCANBOTSDK_REQUIRED_VARS ScanbotSDK_DLL)
endif()

find_package_handle_standard_args(ScanbotSDK
REQUIRED_VARS ScanbotSDK_LIBS ScanbotSDK_INCLUDE_DIRS)
REQUIRED_VARS ${SCANBOTSDK_REQUIRED_VARS}
VERSION_VAR SCANBOTSDK_VERSION
)

message(STATUS "Scanbot SDK third-party licenses are located at: ${SCANBOTSDK_DIR}/scanbotsdk/licenses/Libraries.txt")

add_library(scanbotsdk SHARED IMPORTED)
set_target_properties(scanbotsdk PROPERTIES
IMPORTED_LOCATION "${ScanbotSDK_LIBS}"
INTERFACE_INCLUDE_DIRECTORIES "${ScanbotSDK_INCLUDE_DIRS}"
)
add_library(ScanbotSDK::ScanbotSDK SHARED IMPORTED)
set_target_properties(ScanbotSDK::ScanbotSDK PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${ScanbotSDK_INCLUDE_DIRS}"
)

if(WIN32)
set_target_properties(ScanbotSDK::ScanbotSDK PROPERTIES
IMPORTED_LOCATION "${ScanbotSDK_DLL}"
IMPORTED_IMPLIB "${ScanbotSDK_LIBS}"
)
else()
set_target_properties(ScanbotSDK::ScanbotSDK PROPERTIES
IMPORTED_LOCATION "${ScanbotSDK_LIBS}"
)
endif()
Loading
Loading