为什么我会警告“CMAKE_TOOLCHAIN_FILE"项目没有使用变量? [英] Why am I warned that the "CMAKE_TOOLCHAIN_FILE" variable is not used by the project?

查看:19
本文介绍了为什么我会警告“CMAKE_TOOLCHAIN_FILE"项目没有使用变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我构建一些第三方代码时,我看到来自 CMake 的以下警告:

When I build some third-party code, I am seeing the following warning from CMake:

CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_TOOLCHAIN_FILE

是什么导致了这个警告?我检查了配置文件,但找不到定义此变量的任何地方.

What is causing this warning? I checked the configuration files, but could not find anywhere where this variable is defined.

我应该关注这个警告吗?如何修复它以使警告消失?

Should I be concerned about this warning? How can I fix it so that the warning goes away?

推荐答案

这是 CMake 在您为其提供一个未使用的命令行选项时生成的标准警告.例如,当 CMakeLists.txt 文件实际上没有使用 FOO 变量时,将 -DFOO=bar 传递给 cmake.

This is the standard warning that CMake generates when you're giving it a command line option that it's not using. For example, passing -DFOO=bar to cmake when the CMakeLists.txt file doesn't actually use the FOO variable.

现在,这是一个特殊情况:CMAKE_TOOLCHAIN_FILE 由 CMake 在第一次配置您的构建时使用,但是,因为您无法更改已配置构建的工具链,这个变量每隔一次就会被忽略;因此警告.

Now, this is a bit of a special case: CMAKE_TOOLCHAIN_FILE is used by CMake the first time it configures your build, but, since you can't change the toolchain for an already-configured build, this variable is ignored every other time; hence the warning.

作为 在评论中注明的答案,您可以放心地忽略该警告.Brad King 于 2011 年 2 月 7 日在 CMake 邮件列表中解释:

As Answeror noted in a comment, you can safely ignore the warning. Brad King explained on the CMake mailing list on February 7, 2011:

我只能通过在构建树上运行 CMake 来实现这一点存在.变量 *does* 在新树中的 *first* 运行中使用.它*不会*稍后使用,因为您不需要将其指定为再生.CMake 已经记录了加载文件的规则CMakeFiles/CMakeSystem.cmake 并且不支持更改工具链现有构建树.

I can only get this to happen by running CMake on a build tree that already exists. The variable *does* get used on the *first* run in a fresh tree. It does *not* get used later because you don't need to specify it to regenerate. CMake has already recorded a rule to load the file in CMakeFiles/CMakeSystem.cmake and does not support changing the toolchain of an existing build tree.

IOW,这是警告的合法实例.

IOW, this is a legitimate instance of the warning.

如果这个警告真的让你感到困扰,你有几个选择来抑制它:

If this warning really bothers you, you have a couple of options for suppressing it:

  • 您可以在运行 cmake 时传递 --no-warn-unused-cli 选项.

不过,这有点生硬,因为它会抑制来自命令行中指定的未使用变量的所有警告.这可能会隐藏一些合法的警告.

This is a bit of a blunt instrument, though, because it suppresses all warnings from unused variables specified on the command line. That may hide some legitimate warnings.

您可以在第二次调用之前删除第一次调用 CMake 生成的临时文件.如js 的评论中所述.,需要删除CMakeCache.txt文件和CMakeFiles文件夹.例如,通过执行:

You can remove the temporary files generated by the first invocation of CMake before invoking it a second time. As mentioned in a comment by js., you need to delete the CMakeCache.txt file and the CMakeFiles folder. For example, by executing:

 rm -rf CMakeCache.txt CMakeFiles/

但是,作为 jav 注释,这有点没有意义.除非您实际更改工具链,否则没有理由删除这些生成的文件.虽然它确实使警告消失,但它只是通过强制重新生成文件来实现的,这浪费了时间以获得最小的收益.

But, as javs notes, this is a bit pointless. There's no reason to delete these generated files unless you are actually changing the toolchain. Although it does make the warning go away, it does so merely by forcing the files to be re-generated, which wastes time for minimal gain.

Roland Sarrazin 的回答提供了第三种选择(也许是最好的选择).这涉及通过在状态消息中输出变量来简单地使用变量.这样,它就不会被使用,所以不会触发警告.您甚至可能会发现该消息对于调试与工具链配置相关的问题很有用.

A third option (and perhaps the best) is given by Roland Sarrazin's answer. This involves simply using the variable by outputting it in a status message. This way, it is not unused, so the warning is not triggered. You may even find the message to be useful for debugging problems related to the toolchain configuration.

这篇关于为什么我会警告“CMAKE_TOOLCHAIN_FILE"项目没有使用变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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