如何使 CMake 退出非 0 以响应警告 "Manually-specified variables were not used by the project"?

How to make CMake exit non-0 in response to warning "Manually-specified variables were not used by the project"?

有没有办法让 CMake 以非 0 退出代码退出以响应警告 "Manually-specified variables were not used by the project"?

我喜欢严格的编程,将最大警告和警告视为错误,但存在此 CMake 警告,如果在某些构建管道中未及早发现,可能会导致意外失败,可能修复 -Werror=dev 不会触发非 0 CMake 退出代码并且 --no-warn-unused-cli 与我正在寻找的相反。

作为 CMake 似乎不支持此功能的解决方法,我用 Text Finder plugin 装饰我的 C++ Jenkins 作业,如果在构建输出中找到该字符串,则检查 "CMake Warning" 是否使构建失败。

我检查了代码,你不能把这个 Warning 变成错误。如果你查看 cmake::RunCheckForUnusedVariables() 它会发出一个

  • 警告
    • CMake Warning ...

而不是

  • AUTHOR_WARNING
    • CMake Warning (dev) ...

因此您无法通过命令行选项将正常警告提升为错误。

在这些情况下,命令行调用总是 return 0

要么更改 CMake 的源代码,要么重写 CMake 脚本代码中未使用的变量检查。