cmake指定交叉编译

Posted alix-1988

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cmake指定交叉编译相关的知识,希望对你有一定的参考价值。

新建文件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

以上是关于cmake指定交叉编译的主要内容,如果未能解决你的问题,请参考以下文章

cmake交叉编译参数toolchain

cmake交叉编译的使用

使用 cmake 进行交叉编译

CMake交叉编译目标rpath

Cmake交叉编译标志

make/cmake:海思himix200交叉编译zlib