Silence custom command depending on CMAKE_VERBOSE_MAKEFILE

前端 未结 2 949
猫巷女王i
猫巷女王i 2021-01-21 15:21

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

2条回答
  •  逝去的感伤
    2021-01-21 15:45

    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)
    

    This is the most portable way to do so.

    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.

    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).

提交回复
热议问题