OpenCV and GStreamer C++ Application cross-compile without NSight

Dear all,

I am currently developing a C/C++ application to be run on the Jetson TX2 board. The application uses gstreamer and OpenCV API to run some live video processing over camera streams.
Due to the quality procedures followed in our company, I have to integrate this application building process with our continuous integration server, therefore, I cannot build the application using NSight.
I am stuck in cross-compiling the application due to CUDA and CMake integration (CUDA is required by opencv4tegra). Let me summarize the steps I followed:

Now, I succesfully built a simple application using the following CMakeLists.txt and toolchain.cmake

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)

file(GLOB xxxAPP_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src/*)

#Find pkg-config
find_package(PkgConfig)

#Use Pkg-config to configure GStreamer
pkg_check_modules(GST REQUIRED gstreamer-1.0 gstreamer-video-1.0 gstreamer-app-1.0)

#Include header files
include_directories(${GST_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/)

add_executable(xxxAPP ${xxxAPP_SRC})
target_link_libraries( xxxAPP ${GST_LIBRARIES} pthread pcre)

toolchain.cmake

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)

set(CMAKE_SYSROOT /home/xxx/projects/nvidia_tx2/64_TX2/Linux_for_Tegra_tx2/rootfs)

set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

However, I am not able to add OpenCV linking to my application. If I modify CMakeLists.txt as follows:

cmake_minimum_required(VERSION 2.8)

file(GLOB xxxAPP_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src/*)

#Find pkg-config
find_package(PkgConfig)
find_package( OpenCV REQUIRED )

#Use Pkg-config to configure GStreamer
pkg_check_modules(GST REQUIRED gstreamer-1.0 gstreamer-video-1.0 gstreamer-app-1.0)

#Include header files
include_directories(${GST_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/)

add_executable(xxxAPP ${xxxAPP_SRC})
target_link_libraries( xxxAPP ${GST_LIBRARIES} pthread ${OpenCV_LIBS})

I get the following CMake Error:

cmake -DCMAKE_TOOLCHAIN_FILE:PATH="../toolchain.cmake"  ..
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/aarch64-linux-gnu-gcc
-- Check for working C compiler: /usr/bin/aarch64-linux-gnu-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/aarch64-linux-gnu-g++
-- Check for working CXX compiler: /usr/bin/aarch64-linux-gnu-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1") 
CMake Error at /usr/share/cmake-3.5/Modules/FindCUDA.cmake:617 (message):
  Specify CUDA_TOOLKIT_ROOT_DIR
Call Stack (most recent call first):
  /home/xxx/projects/nvidia_tx2/64_TX2/Linux_for_Tegra_tx2/rootfs/usr/share/OpenCV/OpenCVConfig.cmake:45 (find_package)
  /home/xxx/projects/nvidia_tx2/64_TX2/Linux_for_Tegra_tx2/rootfs/usr/share/OpenCV/OpenCVConfig.cmake:242 (find_host_package)
  CMakeLists.txt:8 (find_package)

Do you have any suggestion on how to deal with this issue? Do you have any guide/tutorial/howto to cross-compile an opencv application on the host without using nsight?

Thank you.

Best,
AP

Sorry for the late reply. In my mind, it would be better to specify what is the CUDA_TOOLKIT_ROOT_DIR in cmake now. Please add some debug message in OpenCVConfig.cmake.

Hi,

thank you for your reply. Finally I cross-compiled my code by avoiding find_package cmake instructions. Cross-compiling using pkg-config in cmake and OpenCVConfig.cmake is a pain.

Thank you!