cmake的toolchain自定义变量失效问题


在编译我们库的时候,cmake执行到toolchain.cmake的时候,一些自定义变量是空的,但是看参数我是已经传递进去了

简介

toolchain

toolchain的用途官网解释的很清楚[1],主要是为了交叉编译

  • Cross-compiling

Cross-compiling a piece of software means that the software is built on one system, but is intended to run on a different system.

分析

测试用例

官网代码拿过来整一个简单的测试用例[2]

MESSAGE("------------------------------------------1" ${
   
   ANDROID_NDK})
if( NOT ANDROID_NDK )
  MESSAGE("111")
else()
  MESSAGE("222")
endif()
# the name of the target operating system
set(CMAKE_SYSTEM_NAME Linux)

# which C and C++ compiler to use
set(CMAKE_C_COMPILER /home/alex/eldk-mips/usr/bin/mips_4KC-gcc)
set(CMAKE_CXX_COMPILER
    /home/alex/eldk-mips/usr/bin/mips_4KC-g++)

# location of the target environment
set(CMAKE_FIND_ROOT_PATH /home/alex/eldk-mips/mips_4KC
                          /home/alex/eldk-mips-extra-install )

# adjust the default behavior of the FIND_XXX() commands:
# search for headers and libraries in the target environment,
# search for programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
MESSAGE("------------------------------------------2")

执行cmake命令,把自定义变量ANDROID_NDK传递过去

cmake -DANDROID_NDK=externals/android-ndk-r10e -DCMAKE_TOOLCHAIN_FILE=..\linux.toolchain.cmake ..

输出结果:

F:\study\compile\cmake\cmake_toolchain\build>cmake -DANDROID_NDK=externals/android-ndk-r10e -DCMAKE_TOOLCHAIN_FILE=..\linux.toolchain.cmake ..
-- Building for: Visual Studio 17 2022</
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值