首页 > 其他分享 >Cmake打印信息

Cmake打印信息

时间:2024-05-09 10:45:28浏览次数:13  
标签:CMAKE 打印信息 CHECK Cmake CONTEXT CMake MESSAGE message

message

Log a message.

Synopsis

General messages
  message([<mode>] "message text" ...)

Reporting checks
  message(<checkState> "message text" ...)

General messages

message([<mode>] "message text" ...)

Record the specified message text in the log. If more than one message string is given, they are concatenated into a single message with no separator between the strings.

The optional <mode> keyword determines the type of message, which influences the way the message is handled:

FATAL_ERROR

CMake Error, stop processing and generation.

SEND_ERROR

CMake Error, continue processing, but skip generation.

WARNING

CMake Warning, continue processing.

AUTHOR_WARNING

CMake Warning (dev), continue processing.

DEPRECATION

CMake Deprecation Error or Warning if variable CMAKE_ERROR_DEPRECATED or CMAKE_WARN_DEPRECATED is enabled, respectively, else no message.

(none) or NOTICE

Important message printed to stderr to attract user’s attention.

STATUS

The main interesting messages that project users might be interested in. Ideally these should be concise, no more than a single line, but still informative.

VERBOSE

Detailed informational messages intended for project users. These messages should provide additional details that won’t be of interest in most cases, but which may be useful to those building the project when they want deeper insight into what’s happening.

DEBUG

Detailed informational messages intended for developers working on the project itself as opposed to users who just want to build it. These messages will not typically be of interest to other users building the project and will often be closely related to internal implementation details.

TRACE

Fine-grained messages with very low-level implementation details. Messages using this log level would normally only be temporary and would expect to be removed before releasing the project, packaging up the files, etc.

The CMake command-line tool displays STATUS to TRACE messages on stdout with the message preceded by two hyphens and a space. All other message types are sent to stderr and are not prefixed with hyphens. The CMake GUI displays all messages in its log area. The curses interface shows STATUS to TRACE messages one at a time on a status line and other messages in an interactive pop-up box. The --log-level command-line option to each of these tools can be used to control which messages will be shown. To make a log level persist between CMake runs, the CMAKE_MESSAGE_LOG_LEVEL variable can be set instead. Note that the command line option takes precedence over the cache variable.

Messages of log levels NOTICE and below will have each line preceded by the content of the CMAKE_MESSAGE_INDENT variable (converted to a single string by concatenating its list items). For STATUS to TRACE messages, this indenting content will be inserted after the hyphens.

Messages of log levels NOTICE and below can also have each line preceded with context of the form [some.context.example]. The content between the square brackets is obtained by converting the CMAKE_MESSAGE_CONTEXT list variable to a dot-separated string. The message context will always appear before any indenting content but after any automatically added leading hyphens. By default, message context is not shown, it has to be explicitly enabled by giving the cmake --log-context command-line option or by setting the CMAKE_MESSAGE_CONTEXT_SHOW variable to true. See the CMAKE_MESSAGE_CONTEXT documentation for usage examples.

CMake Warning and Error message text displays using a simple markup language. Non-indented text is formatted in line-wrapped paragraphs delimited by newlines. Indented text is considered pre-formatted.

 

CMAKE_MESSAGE_CONTEXT

New in version 3.17.

When enabled by the cmake --log-context command line option or the CMAKE_MESSAGE_CONTEXT_SHOW variable, the message() command converts the CMAKE_MESSAGE_CONTEXT list into a dot-separated string surrounded by square brackets and prepends it to each line for messages of log levels NOTICE and below.

For logging contexts to work effectively, projects should generally APPEND and POP_BACK an item to the current value of CMAKE_MESSAGE_CONTEXT rather than replace it. Projects should not assume the message context at the top of the source tree is empty, as there are scenarios where the context might have already been set (e.g. hierarchical projects).

Warning

 Valid context names are restricted to anything that could be used as a CMake variable name. All names that begin with an underscore or the string cmake_ are also reserved for use by CMake and should not be used by projects.  

当cmake ——log-context命令行选项或CMAKE_MESSAGE_CONTEXT_SHOW变量启用时,message()命令将CMAKE_MESSAGE_CONTEXT列表转换为一个用方括号包围的点分隔字符串,并将其添加到日志级别NOTICE及以下的消息的每行。

为了使日志记录上下文有效地工作,项目通常应该在CMAKE_MESSAGE_CONTEXT的当前值上附加和POP_BACK一个项,而不是替换它。项目不应该假设源树顶部的消息上下文是空的,因为在某些情况下上下文可能已经设置好了(例如分层项目)。

警告:有效的上下文名称仅限于可以用作CMake变量名的任何内容。所有以下划线或字符串cmake_开头的名称也保留给CMake使用,不应该被项目使用。

Example:

function(bar)
  list(APPEND CMAKE_MESSAGE_CONTEXT "bar")
  message(VERBOSE "bar VERBOSE message")
endfunction()

function(baz)
  list(APPEND CMAKE_MESSAGE_CONTEXT "baz")
  message(DEBUG "baz DEBUG message")
endfunction()

function(foo)
  list(APPEND CMAKE_MESSAGE_CONTEXT "foo")
  bar()
  message(TRACE "foo TRACE message")
  baz()
endfunction()

list(APPEND CMAKE_MESSAGE_CONTEXT "top")

message(VERBOSE "Before `foo`")
foo()
message(VERBOSE "After `foo`")

list(POP_BACK CMAKE_MESSAGE_CONTEXT)

Which results in the following output:

-- [top] Before `foo`
-- [top.foo.bar] bar VERBOSE message
-- [top.foo] foo TRACE message
-- [top.foo.baz] baz DEBUG message
-- [top] After `foo`


 

 

Reporting checks

A common pattern in CMake output is a message indicating the start of some sort of check, followed by another message reporting the result of that check. For example:

message(STATUS "Looking for someheader.h")
#... do the checks, set checkSuccess with the result
if(checkSuccess)
  message(STATUS "Looking for someheader.h - found")
else()
  message(STATUS "Looking for someheader.h - not found")
endif()

This can be more robustly and conveniently expressed using the CHECK_... keyword form of the message() command:

message(<checkState> "message" ...)

where <checkState> must be one of the following:

CHECK_START

Record a concise message about the check about to be performed.

CHECK_PASS

Record a successful result for a check.

CHECK_FAIL

Record an unsuccessful result for a check.

When recording a check result, the command repeats the message from the most recently started check for which no result has yet been reported, then some separator characters and then the message text provided after the CHECK_PASS or CHECK_FAIL keyword. Check messages are always reported at STATUS log level.

Checks may be nested and every CHECK_START should have exactly one matching CHECK_PASS or CHECK_FAIL. The CMAKE_MESSAGE_INDENT variable can also be used to add indenting to nested checks if desired. For example:

message(CHECK_START "Finding my things")
list(APPEND CMAKE_MESSAGE_INDENT "  ")
unset(missingComponents)

message(CHECK_START "Finding partA")
# ... do check, assume we find A
message(CHECK_PASS "found")

message(CHECK_START "Finding partB")
# ... do check, assume we don't find B
list(APPEND missingComponents B)
message(CHECK_FAIL "not found")

list(POP_BACK CMAKE_MESSAGE_INDENT)
if(missingComponents)
  message(CHECK_FAIL "missing components: ${missingComponents}")
else()
  message(CHECK_PASS "all components found")
endif()

Output from the above would appear something like the following:

-- Finding my things
--   Finding partA
--   Finding partA - found
--   Finding partB
--   Finding partB - not found
-- Finding my things - missing components: B



#######################################################################################################################
#######################################################################################################################
#######################################################################################################################

概要
常规消息
message([<mode>] “消息文本” …)

报告检查
message(<checkState> “消息文本” …)
常规消息
message([<mode>] “消息文本” …)
将指定的消息文本记录在日志中。如果给出了多个消息字符串,则它们将连接成单个消息,字符串之间没有分隔符。

可选的<mode>关键字确定消息的类型,这影响消息的处理方式:

FATAL_ERROR
CMake错误,停止处理和生成。

SEND_ERROR
CMake错误,继续处理,但跳过生成。

WARNING
CMake警告,继续处理。

AUTHOR_WARNING
CMake警告(开发者),继续处理。

DEPRECATION
如果启用了变量CMAKE_ERROR_DEPRECATED或CMAKE_WARN_DEPRECATED,则为CMake废弃错误或警告,否则无消息。

(none) 或 NOTICE
重要消息打印到stderr以吸引用户的注意。

STATUS
项目用户可能感兴趣的主要消息。理想情况下,这些应该简洁,不超过一行,但仍然信息丰富。

VERBOSE
面向项目用户的详细信息消息。这些消息应该提供额外的细节,大多数情况下不会引起兴趣,但对于那些想要深入了解正在发生的事情的构建项目的人可能是有用的。

DEBUG
面向项目本身的开发人员的详细信息消息,而不是仅仅想要构建项目的用户。这些消息通常不会引起其他构建项目的用户的兴趣,并且通常与内部实现细节密切相关。

TRACE
具有非常低级别实现细节的细粒度消息。使用此日志级别的消息通常仅是临时的,并且期望在发布项目、打包文件等之前被删除。

CMake命令行工具会将STATUS到TRACE消息显示在stdout上,并在消息之前添加两个连字符和一个空格。所有其他消息类型都会发送到stderr,并且不会添加连字符。CMake GUI在其日志区域显示所有消息。curses接口在状态行上逐个显示STATUS到TRACE消息,其他消息在交互式弹出框中显示。每个工具的–log-level命令行选项可用于控制将显示哪些消息。要使日志级别在CMake运行之间持久化,可以设置CMAKE_MESSAGE_LOG_LEVEL变量。请注意,命令行选项优先于缓存变量。

消息级别为NOTICE及以下的消息将使每行都以CMAKE_MESSAGE_INDENT变量的内容(通过将其列表项连接为单个字符串)为前缀。对于STATUS到TRACE消息,这个缩进内容将在连字符之后插入。

消息级别为NOTICE及以下的消息也可以以形如[some.context.example]的上下文为前缀。方括号之间的内容通过将CMAKE_MESSAGE_CONTEXT列表变量转换为点分隔的字符串获得。消息上下文将始终出现在任何缩进内容之前,但在任何自动添加的前导连字符之后。默认情况下,消息上下文不会显示,必须通过给出cmake --log-context命令行选项或将CMAKE_MESSAGE_CONTEXT_SHOW变量设置为true来显式启用。有关用法示例,请参阅CMAKE_MESSAGE_CONTEXT文档。

CMake警告和错误消息文本使用简单的标记语言进行格式化。非缩进文本以换行符分隔的段落格式化。缩进的文本被视为预格式化的。



标签:CMAKE,打印信息,CHECK,Cmake,CONTEXT,CMake,MESSAGE,message
From: https://www.cnblogs.com/blj28/p/18181603

相关文章

  • windows下源码编译CMake项目
    Cmake项目1、安装路径和源码安装包下载地址:https://cmake.org/download/源码地址https://github.com/Kitware/CMake2、编译源码下载后会有一个CMake-master的文件夹在里面新建一个build目录打开cmake-gui可执行文件出现cmake的界面,设置source路径为刚刚的CMake-......
  • [Cmake Qt]找不到文件ui_xx.h的问题?有关Qt工程的问题,看这篇文章就行了。
    前言最近在开发一个组件,但是这个东西是以dll的形式发布的界面库,所以在开发的时候就需要上层调用。如果你是很懂CMake的话,ui_xx.h的文件目录在$下然后除了有关这个ui_xx.h,还有一些别的可以简单聊聊的一、父子工程组织,或者说依赖关系在使用CMake进行开发的时候,一般可以有......
  • 一个CMake的例子
    首先编写4个文件:1、CMakeLists.txt内容:cmake_minimum_required(VERSION3.15)project(Demo)include_directories(${PROJECT_BINARY_DIR}/headers)aux_source_directory(${PROJECT_BINARY_DIR}/sourcesSRC_DIR)add_library(dynamic_librarySHARED${SRC_DIR})add_libr......
  • CMake中里的find_package与find_library有什么区别?
    在CMake中,find_package和find_library都是用来找到和链接库的方法,但它们的用法和适用场景略有不同。find_package主要用于寻找具有CMake配置文件的库,这些库通常遵循CMake的规范,提供了用于导入目标、库路径、头文件路径等的配置文件。这使得使用find_package更加简洁,只需指定需......
  • 【cmake】find_package设置查找路径
     1.find_package的作用与实例用来查找第三方依赖包的.cmake文件,并根据.cmake文件生成依赖包的头文件目录和库文件路径等;CMakeLists.txt实例find_package(ProtobufREQUIRED)include_directories(${PROTOBUF_INCLUDE_DIR})add_executable(mainsrc/main.cpp)target......
  • CMakeLists.txt --- install使用
    例:cmake_minimum_required(VERSION3.9)project(test)set(CMAKE_BUILD_TYPEDebug)add_library(hahatest.cpp)install(TARGEThahaDESTINATION/home/linxisuo/project/test)install(DIRECTORY${CMAKE_SOURCE_DIR}/testDESTINATION/home/linxisuo)说明:1.安装......
  • CMakeListx.txt --- include_directories和target_include_directories命令
    1. include_directories语法include_directories([AFTER|BEFORE][SYSTEM]dir1[dir2...])作用将指定目录添加到编译器的头文件搜索路径之下,指定的目录被解释成当前源码路径的相对路径。参数默认情况下,include_directories命令会将目录添加到列表最后,可以通过命令设置......
  • CMakeLists.txt --- 导入接口库(预编译库)
    以接口库的方式导入预编译库cmake_minimum_required(VERSION3.9)project(test)set(CMAKE_BUILD_TYPEDebug)set(CMAKE_C_FLAGS"$ENV{CFLAGS}-O2-Wall-pthread")set(CMAKE_CXX_FLAGS"$ENV{CFLAGS}-O2-Wall-pthread-std=c++11-std=gnu++11")#设置mo......
  • CMake极速入门
    引言还在手写晦涩难懂的Makefile文件吗?现如今,主流的c++项目都采取CMake作为项目构建工具,CMake可以跨平台运行,而且语法相对Makefile而言直观很多,是时候将Makefile扫进垃圾堆了。Hello,World!首先先以单个源文件项目为讲解,新建一个main.cpp文件:#include<iostream>usingnames......
  • cmake find_package
    if(CMAKE_VERSIONVERSION_LESS3.10)  message(FATAL_ERROR"CMake3.10isrequiredbyFindffmpeg.cmake")endif()set(ffmpeg_VERSION6.1)set(HEADS_PATH${PROJECT_SOURCE_DIR}/external/ffmpeg/prebuild/include)set(LIB_PATH${PROJECT_SOURCE_DIR}......