静默自定义命令取决于CMAKE_VERBOSE_MAKEFILE [英] Silence custom command depending on CMAKE_VERBOSE_MAKEFILE

查看:1087
本文介绍了静默自定义命令取决于CMAKE_VERBOSE_MAKEFILE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在CMake脚本中有一个自定义命令,该命令会产生大量输出。我想利用CMAKE_VERBOSE_MAKEFILE的优势,因此我可以决定是否要查看此输出。

I've a custom command in my CMake script which generates a lot of output. I'd like to take advantage of CMAKE_VERBOSE_MAKEFILE so I can decide if I want to see this output or not.

是否有一种通用的方法?

Is there a common way for doing this?

我看到的一种方法是根据此CMake的标志将输出重定向到 / dev / null ,但是Windows和Windows呢?其他操作系统?

The one way I see is to redirect output to /dev/null depending on this CMake's flag, but what about Windows and other OSes?

有便携式或推荐的方式吗? C / C ++编译命令的默认规则如何?

Is there a portable or recommended way? What about default rules for C/C++ compiling commands?

推荐答案

从技术上来讲, CMAKE_VERBOSE_MAKEFILE 的存在是为了隐藏和显示命令行,而不是命令输出。

Technically speaking, CMAKE_VERBOSE_MAKEFILE exists for the purpose of hiding and showing command lines, not command output.

如果必须这样做,我将使用自定义变量。

If I had to do this, I would use a custom variable.

但是在主要主题上,这是应该怎么做:

But on the main topic, here is how you should do:

if (COMMAND_VERBOSE)
  execute_process(COMMAND "mycustom_command")
else (COMMAND_VERBOSE)
  execute_process(COMMAND "mycustom_command" OUTPUT_QUIET)
endif (COMMAND_VERBOSE)

这是最便携的方法。

还有一个 ERROR_QUIET 标志,但是禁用错误消息不是一个好主意,否则用户将看不到命令​​失败的原因。

There is also an ERROR_QUIET flag, however it is a bad idea to disable error messages, else the user would be unable to see why the command failed if it failed.

如果使用的是 add_custom_command add_custom_target ,则不存在这样的标志。
您必须提供手动重定向到 / dev / null (Unix)或 NUL (Windows)。

If you are using add_custom_command or add_custom_target instead, such a flag does not exist. You'll have to provide a manual redirection to /dev/null (Unix), or NUL (Windows).

这篇关于静默自定义命令取决于CMAKE_VERBOSE_MAKEFILE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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