告诉cmake要安静

ale*_*ann 15 build cmake

有没有我可以在cmake中使用的变量使它像传递-q选项一样?这将是很好的,因为我有一个非常模块化的构建,使得cmakes输出变得混乱.我在c ++项目中使用它.

Fra*_*ser 11

我所知道的并没有变数.但是,您可以将以下hack添加到顶级CMakeLists.txt的开头(在project调用之前)以稍微控制输出:

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()
Run Code Online (Sandbox Code Playgroud)

这会覆盖CMake的内置message命令并抑制所有STATUS和非类型化的消息,从而使更重要的类型正确输出.

例如WARNING消息的输出将改变

CMake Warning at CMakeLists.txt:14 (message):
  This is a dummy warning message.
Run Code Online (Sandbox Code Playgroud)

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

请注意,生成警告消息的实际行列在调用堆栈中,而不是输出消息的第一行.

最后,这对指示配置尝试成功或失败的摘要输出没有影响.


Oli*_*ier 6

从cmake 3.1开始,设置CMAKE_INSTALL_MESSAGE也非常有用.例如,set(CMAKE_INSTALL_MESSAGE LAZY)将跳过-- Up-to-date:消息.

  • 还有设置(CMAKE_INSTALL_MESSAGE NEVER)。 (3认同)