检查工具链文件中的CMake缓存变量 [英] Check CMake Cache Variable in Toolchain File
本文介绍了检查工具链文件中的CMake缓存变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法通过命令行设置配置变量。我无法从系统中确定它,因此我希望用户指定:
I'm having trouble setting a configuration variable via the command line. I can't determine it from the system, so I expect the user to specify:
cmake -DCMAKE_TOOLCHAIN_FILE=../android.toolchain -DANDROID_ABI:STRING="arm64" ..
我的 android内部.toolchain
,我有以下内容:
message(STATUS "Android ABI: ${ANDROID_ABI}")
if( "${ANDROID_ABI}" STREQUAL "" )
message(FATAL_ERROR "Please specifiy ABI at cmake call -DANDROID_ABI:STRING=armeabi or -DANDROID_ABI:STRING=arm64")
endif()
无论如何,即使在此行打印出正确的arm64,它在此行也会失败:
No matter what, it fails at this line EVEN THOUGH it prints out the correct arm64:
-- Android ABI: arm64
CMake Error at yaml-cpp/android.toolchain:45 (message):
Please specifiy ABI at cmake call -DANDROID_ABI:STRING=armeabi or -DANDROID_ABI:STRING=arm64
有人可以指示我我做错了什么吗?
Could anyone direct me to what I'm doing wrong?
我认为这与以下问题有关:
I think this has to do with:
- -D添加一个缓存变量而不是普通变量
- 这在工具链文件中。 。似乎忽略了缓存变量
有什么想法或建议吗?
推荐答案
我不假装完全了解幕后发生的事情,但这是一种对我有效的解决方法:
I don't pretend to fully understand what's going on behind the scenes, but here's a workaround that works for me:
# Problem: CMake runs toolchain files multiple times, but can't read cache variables on some runs.
# Workaround: On first run (in which cache variables are always accessible), set an intermediary environment variable.
if (FOO)
# Environment variables are always preserved.
set(ENV{_FOO} "${FOO}")
else ()
set(FOO "$ENV{_FOO}")
endif ()
这篇关于检查工具链文件中的CMake缓存变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文