-
Notifications
You must be signed in to change notification settings - Fork 0
/
jetson-t210.toolchain.cmake
83 lines (68 loc) · 3.26 KB
/
jetson-t210.toolchain.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
# Specify the cross compilers
set(CMAKE_C_COMPILER "clang")
set(CMAKE_CUDA_COMPILER "clang++")
set(CMAKE_CXX_COMPILER "clang++")
set(TARGET_TRIPLE "aarch64-linux-gnu")
set(CMAKE_C_COMPILER_TARGET "${TARGET_TRIPLE}")
set(CMAKE_CUDA_COMPILER_TARGET "${TARGET_TRIPLE}")
set(CMAKE_CXX_COMPILER_TARGET "${TARGET_TRIPLE}")
# Set the sysroot path
set(CMAKE_SYSROOT "${CMAKE_CURRENT_LIST_DIR}/sysroot/jetson-t210")
if(NOT EXISTS ${CMAKE_SYSROOT})
message(
FATAL_ERROR
"CMAKE_SYSROOT does not exist: ${CMAKE_SYSROOT}\nPlease run ./scripts/extract-sysroot.sh --board-id t210")
endif()
set(SYSROOT_CUDA "${CMAKE_SYSROOT}/usr/local/cuda-10.2")
# Check if we are on a non-arm64 architecture
if(NOT CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "aarch64" AND NOT CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64")
# Path to the GCC toolchain for the target architecture
set(GCC_TOOLCHAIN
"${CMAKE_CURRENT_LIST_DIR}/sysroot/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu")
if(NOT EXISTS ${GCC_TOOLCHAIN})
message(
FATAL_ERROR
"GCC_TOOLCHAIN does not exist: ${GCC_TOOLCHAIN}\nPlease run ./scripts/extract-sysroot.sh --board-id t210")
endif()
endif()
# Path to the host (x86_64) vendored CUDA toolkit
if(APPLE)
set(CUDAToolkit_ROOT "${CMAKE_CURRENT_LIST_DIR}/nvidia/cuda-10.2_macos")
else()
set(CUDAToolkit_ROOT "${CMAKE_CURRENT_LIST_DIR}/nvidia/cuda-10.2_amd64")
endif()
if(NOT EXISTS ${CUDAToolkit_ROOT})
message(
FATAL_ERROR
"CUDAToolkit_ROOT does not exist: ${CUDAToolkit_ROOT}\nPlease run ./scripts/extract-cuda.sh --cuda 10.2")
endif()
set(CUDA_TOOLKIT_INCLUDE "${SYSROOT_CUDA}/include")
set(CUDA_CUDART "${SYSROOT_CUDA}/lib64/libcudart.so")
set(CUDA_CUDART_LIBRARY "${SYSROOT_CUDA}/lib64/libcudart.so")
set(CUDA_NVTX_LIBRARY "${SYSROOT_CUDA}/lib64/libnvToolsExt.so")
# CMake 3.22 is not using `CMAKE_EXE_LINKER_FLAGS` when compiling a CUDA test
# program, causing the linker to fail. This is a workaround
set(CMAKE_CUDA_FLAGS "-fuse-ld=lld")
# sm_53 is the compute capability of the Jetson Nano (t210)
set(CMAKE_CUDA_ARCHITECTURES "53")
set(CUDA_SEPARABLE_COMPILATION ON CACHE BOOL "Enable separable compilation for CUDA")
# Adjust the default behavior of the FIND_XXX() commands: search programs in the host environment
# only.
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# Search headers and libraries in the target environment only.
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
# Set the default linker flags to use the LLD linker and find the CUDA libraries
set(CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld -L${SYSROOT_CUDA}/lib64"
CACHE STRING "Linker flags")
# Prevent CMake from adding `-isystem ${CMAKE_SYSROOT}/usr/include` when compiling CUDA files, which
# messes up the include order for <cmath> and <math.h> and breaks compilation
set(CMAKE_CUDA_IMPLICIT_INCLUDE_DIRECTORIES ${CMAKE_CUDA_IMPLICIT_INCLUDE_DIRECTORIES}
${CMAKE_SYSROOT}/usr/include)
# Set compiler flags for color diagnostics
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fansi-escape-codes -fcolor-diagnostics")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fansi-escape-codes -fcolor-diagnostics")