在编译我们库的时候,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</

最低0.47元/天 解锁文章
732

被折叠的 条评论
为什么被折叠?



