cmake指定交叉编译

北城余情 提交于 2021-02-14 16:19:32

新建文件arm.cmake,内容如下

#指定嵌入式系统的编译输出目录
set(SYSROOT_PATH "/home/suka/out/system")

#指定交叉编译器路径
set(TOOLSCHAIN_PATH "/home/suka/toolschain/")
set(TOOLCHAIN_HOST "${TOOLSCHAIN_PATH}usr/bin/arm-linux")

#message("${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE}")
message(STATUS "Using sysroot path: ${SYSROOT_PATH}")


set(TOOLCHAIN_CC "${TOOLCHAIN_HOST}-gcc")
set(TOOLCHAIN_CXX "${TOOLCHAIN_HOST}-g++")

#告诉cmake是进行交叉编译
set(CMAKE_CROSSCOMPILING TRUE)

# Define name of the target system
set(CMAKE_SYSTEM_NAME "Linux")
# Define the compiler
set(CMAKE_C_COMPILER ${TOOLCHAIN_CC})
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_CXX})

#库和同头文件查找的路径。
set(CMAKE_FIND_ROOT_PATH "${SYSROOT_PATH}" "${CMAKE_PREFIX_PATH}" "${TOOLSCHAIN_PATH}")

# search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

启动使用cmake -DCMAKE_TOOLCHAIN_FILE=arm.cmake -DCMAKE_INSTALL_PREFIX:FILEPATH=/usr/local

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!