项目中存在在x86的linux系统上编译arm版本代码的需求,这个时候就涉及到交叉编译了,下面记录下项目中别的人cmake配置,方便后续学习
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(CMAKE_CROSSCOMPILING TRUE)
set(CPACK_SYSTEM_NAME aarch64)SET(CMAKE_SYSROOT $ENV{HOME}/cross_xxx)
SET(CMAKE_C_COMPILER /usr/bin/aarch64-linux-gnu-gcc)
SET(CMAKE_CXX_COMPILER /usr/bin/aarch64-linux-gnu-g++)
# cuda
set(ENV{CUDA_TOOLKIT_ROOT} /usr/local/cuda-11.4/)
set(CUDA_NVCC_EXECUTABLE /usr/local/cuda-11.4/bin/nvcc) #host nvcc path
set(CMAKE_CUDA_HOST_COMPILER ${CMAKE_CXX_COMPILER})
SET(CMAKE_FIND_ROOT_PATH /usr/aarch64-linux-gnu /usr/lib/aarch64-linux-gnu ${CMAKE_SYSROOT}/Qt-6.3.0)
# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# Only look for libraries, headers and packages in the sysroot, don't look on the build machine.
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)# qt host
SET(HOST_QT_BIN_PATH "/opt/Qt/6.3.1/gcc_64/libexec")
SET(QT_MOC_EXECUTABLE ${HOST_QT_BIN_PATH}/moc)
SET(QT_RCC_EXECUTABLE ${HOST_QT_BIN_PATH}/rcc)
SET(QT_UIC_EXECUTABLE ${HOST_QT_BIN_PATH}/uic)
SET(QT_QMLIMPORTSCANNER_EXECUTABLE ${HOST_QT_BIN_PATH}/qmlimportscanner)SET(PLATFORM_TYPE "PLATFORM_LIGHT_8G" CACHE STRING INTERNAL FORCE)
include_directories(${CMAKE_SYSROOT}/usr/include/opencv4 ${CMAKE_SYSROOT}/usr/include/aarch64-linux-gnu)
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -Wl,-rpath-link,${CMAKE_SYSROOT}/libtorch")
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -Wl,-rpath-link,$ENV{CUDA_TOOLKIT_ROOT}/targets/aarch64-linux/lib")