codekingpro/portable-devtools
114k
1# Copyright 2025 NVIDIA Corporation. All rights reserved.
2#
3# Please refer to the NVIDIA end user license agreement (EULA) associated
4# with this source code for terms and conditions that govern your use of
5# this software. Any use, reproduction, disclosure, or distribution of
6# this software and related documentation outside the terms of the EULA
7# is strictly prohibited.
8
9# toolchain cmake file for arm64 cross-compilation on x86 ubuntu platform
10# Set the target system
11
12set(CMAKE_SYSTEM_NAME Linux)
13set(CMAKE_SYSTEM_PROCESSOR aarch64)
14
15# Specify the cross compiler
16set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
17set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
18
19# Set CUDA host compiler to use the cross-compiler
20set(CMAKE_CUDA_HOST_COMPILER ${CMAKE_CXX_COMPILER})
21
22# Require CMAKE_SYSROOT to be passed via -DCMAKE_SYSROOT=... command line
23if(NOT DEFINED CMAKE_SYSROOT OR CMAKE_SYSROOT STREQUAL "")
24 message(FATAL_ERROR
25 "CMAKE_SYSROOT is not set!\n"
26 "Please provide it via command line:\n"
27 " cmake -DCMAKE_SYSROOT=/path/to/sysroot \n"
28 " -DCMAKE_TOOLCHAIN_FILE=../aarch64-cc-toolchain.cmake \n"
29 " -DCMAKE_BUILD_TYPE=Release .."
30 )
31endif()
32message(STATUS "Cross-compile config with sysroot: ${CMAKE_SYSROOT}")
33
34set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) # Programs should run with host binaries
35set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) # Only look for libraries in the root path
36set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) # Only look for headers in the root path
37
38# CUDA target toolkit path for jetson
39set(CUDA_TARGET_TOOLKIT "${CMAKE_SYSROOT}/usr/local/cuda-13.0/targets/sbsa-linux")
40
41# Point CMake to target CUDA libraries
42list(APPEND CMAKE_LIBRARY_PATH
43 "${CUDA_TARGET_TOOLKIT}/lib"
44 "${CUDA_TARGET_TOOLKIT}/lib/stubs"
45)
46
47# Add CUDA include and library paths for cross-compilation
48set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -I${CUDA_TARGET_TOOLKIT}/include")
49set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xlinker=-L${CUDA_TARGET_TOOLKIT}/lib")
50set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xlinker=-L${CUDA_TARGET_TOOLKIT}/lib/stubs")
51
52 