Cannot Compile - CUDA 11.4 + CMAKE 3.16

Hi there forum,

I have a project that has been working for quite a while and we recently decided to port it over to run on a Jetson Orin Nano/NX card (currently specifically Nano but will move over to NX at some point as well, but most likely not AGX).

For this we decided on compiling everything (our main application + all it’s required libraries that we wrote) in the docker provided by NVIDIA.

I pulled the docker and made a few changes (like adding some libraries like opencv and programs) to it and saved it.
This entire endeavour was split into 2 parts:

  1. Get the application to compile in the docker and then move it over to the actual card and run it there
  2. Add a new part to the code (a wrapper around a new library that requires CUDA) and again, compile everything in the docker and then move over to the card.

The first part has turned out well, we are able to compile everything required in the docker and then move to the card and run it there.
The second part is not working.

Technical info:
Docker version: nvcr.io/nvidia/jetpack-linux-aarch64-crosscompile-x86:5.1.2
Card Jetpack version: 5.1.2
CUDA version: 11.4
OpenCV version: 4.5.4 + 4.8.0 (I’ve tried both)
cuda-cross-aarch64 and cuda-cross-aarch64-11-4 are both installed
CMAKE version 3.16

In the CMakeLists.txt file we use to compile our CUDA-dependant library, we add CUDA as a language:
project(Handler VERSION 0.0.1 LANGUAGES CXX CUDA)

The actual problem is this:
When trying to configure the cmake project, it fails with the following error:
– The CXX compiler identification is GNU 9.3.0
– The CUDA compiler identification is NVIDIA 11.4.315
– Check for working CXX compiler: /l4t/toolchain/bin/aarch64-linux-g++
– Check for working CXX compiler: /l4t/toolchain/bin/aarch64-linux-g++ – works
– Detecting CXX compiler ABI info
– Detecting CXX compiler ABI info - done
– Detecting CXX compile features
– Detecting CXX compile features - done
– Check for working CUDA compiler: /usr/local/cuda/bin/nvcc
– Check for working CUDA compiler: /usr/local/cuda/bin/nvcc – works
– Detecting CUDA compiler ABI info
– Detecting CUDA compiler ABI info - done
CMake Error at /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146 (message):
Could NOT find CUDA (missing: CUDA_INCLUDE_DIRS) (found suitable exact
version “11.4”)
Call Stack (most recent call first):
/usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:393 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.16/Modules/FindCUDA.cmake:1104 (find_package_handle_standard_args)
/l4t/toolchain/aarch64-buildroot-linux-gnu/sysroot/usr/lib/cmake/opencv4/OpenCVConfig.cmake:86 (find_package)
/l4t/toolchain/aarch64-buildroot-linux-gnu/sysroot/usr/lib/cmake/opencv4/OpenCVConfig.cmake:108 (find_host_package)
CMakeLists.txt:49 (find_package)

It seems as though both the g++ cross compiler and the nvcc compiler are found and recognized properly, however it does not find the CUDA_INCLUDE_DIRS.
It also said this for the TOOLKIT_ROOT_DIR, CUDART_LIB and CUDA_COMPILER at the beginning but when I set the in the CMAKE file, those errors were supposedly solved:

set(CMAKE_CUDA_COMPILER /usr/local/cuda/bin/nvcc)
set(CUDA_TOOLKIT_ROOT_DIR /usr/local/cuda)
set(CUDA_NVCC_FLAGS “–compiler-bindir /usr/bin/aarch64-linux-gnu-g++”) // this flag was added to make sure it cross compiles
set(CUDA_CUDART_LIBRARY /usr/local/cuda/lib64/libcudart.so)

I’ve also tried setting the variable during the call to CMAKE with the -DCUDA_INCLUDE_DIRS=…/path flag but got the same error.

Any help would be greatly appreciated.

Thanks