alexmherrmann
alexmherrmann

Reputation: 1073

tell cmake to be quiet

Is there a variable I can use in cmake to make it act like it was passed the -q option? It would be nice because I have a very modular build that gets messy with cmakes output. I am using it in a c++ project.

Upvotes: 22

Views: 16392

Answers (4)

heiner
heiner

Reputation: 718

For the installation part of CMake, which tends to print one line per file (a la -- Up-to-date: /some/destination/path and -- Installing: /some/destination/path), you can do

set(CMAKE_INSTALL_MESSAGE LAZY)  # Don't tell us about up-to-date files.

which doesn't print for already present files (if you run install repeatedly, as you might during development), or even

set(CMAKE_INSTALL_MESSAGE NEVER)  # Install silently.

This option has been present since CMake 3.1.

Upvotes: 2

mcandre
mcandre

Reputation: 24682

set(CMAKE_MESSAGE_LOG_LEVEL "WARNING")

https://cmake.org/cmake/help/latest/variable/CMAKE_MESSAGE_LOG_LEVEL.html

Upvotes: 2

Olivier
Olivier

Reputation: 1199

As of cmake 3.1, setting CMAKE_INSTALL_MESSAGE is also very useful. For example, set(CMAKE_INSTALL_MESSAGE LAZY) will skip the -- Up-to-date: messages.

Upvotes: 13

Fraser
Fraser

Reputation: 78508

There's no variable that I know of. However, you can add the following hack to the start of your top-level CMakeLists.txt (before the project call) to control the output somewhat:

function(message)
  list(GET ARGV 0 MessageType)
  if(MessageType STREQUAL FATAL_ERROR OR
     MessageType STREQUAL SEND_ERROR OR
     MessageType STREQUAL WARNING OR
     MessageType STREQUAL AUTHOR_WARNING)
    list(REMOVE_AT ARGV 0)
    _message(${MessageType} "${ARGV}")
  endif()
endfunction()

This overrides CMake's built-in message command and suppresses all STATUS and untyped messages, leaving the more important types to output correctly.

The output of e.g. a WARNING message will change from

CMake Warning at CMakeLists.txt:14 (message):
  This is a dummy warning message.

to

CMake Warning at CMakeLists.txt:8 (_message):
  This is a dummy warning message.
Call Stack (most recent call first):
  CMakeLists.txt:14 (message)

Note that the actual line where the warning message was generated is listed in the call stack rather than being the first line of the output message.

Finally, this has no effect on the summary output which indicates success or failure of the configure attempt.

Upvotes: 12

Related Questions