cmake 配置arm-linux-gcc 交叉编译环境

1.cmake 官网教程 https://cmake.org/cmake/help/v3.2/manual/cmake-toolchains.7.html?highlight=cmake_c_compiler#cross-compiling-for-linux

2.Cross Compiling

If cmake(1) is invoked with the command line parameter-DCMAKE_TOOLCHAIN_FILE=path/to/file, the file will be loaded early to setvalues for the compilers.The CMAKE_CROSSCOMPILING variable is set to true when CMake iscross-compiling.

Cross Compiling for Linux

A typical cross-compiling toolchain for Linux has content suchas:

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)

set(CMAKE_SYSROOT /home/devel/rasp-pi-rootfs)
set(CMAKE_STAGING_PREFIX /home/devel/stage)

set(tools /home/devel/gcc-4.7-linaro-rpi-gnueabihf)
set(CMAKE_C_COMPILER ${tools}/bin/arm-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER ${tools}/bin/arm-linux-gnueabihf-g++)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

The CMAKE_SYSTEM_NAME is the CMake-identifier of the target platformto build for.

The CMAKE_SYSTEM_PROCESSOR is the CMake-identifier of the target architectureto build for.

The CMAKE_SYSROOT is optional, and may be specified if a sysrootis available.

The CMAKE_STAGING_PREFIX is also optional. It may be used to specifya path on the host to install to. The CMAKE_INSTALL_PREFIX is alwaysthe runtime installation location, even when cross-compiling.

The CMAKE_<LANG>_COMPILER variables may be set to full paths, or tonames of compilers to search for in standard locations. In cases where CMake doesnot have enough information to extract information from the compiler, theCMakeForceCompiler module can be used to bypass some of the checks.

CMake find_* commands will look in the sysroot, and the CMAKE_FIND_ROOT_PATHentries by default in all cases, as well as looking in the host system root prefix.Although this can be controlled on a case-by-case basis, when cross-compiling, itcan be useful to exclude looking in either the host or the target for particularartifacts. Generally, includes, libraries and packages should be found in thetarget system prefixes, whereas executables which must be run as part of the buildshould be found only on the host and not on the target. This is the purpose ofthe CMAKE_FIND_ROOT_PATH_MODE_* variables.


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值