检查工具链文件中的 CMake 缓存变量 [英] Check CMake Cache Variable in Toolchain File

查看:21
本文介绍了检查工具链文件中的 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 中,我有以下内容:

Inside my android.toolchain, I have the following:

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?

我认为这与:

  • -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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆