CMake学习(五) —— 打印信息

2,372 阅读1分钟

为了可以显示编译信息,CMake设置了message语句,语法如下:

message([<mode>] "message to display" ...)

关于 mode 选项:

(none)         = Important information
STATUS         = Incidental information
WARNING        = CMake Warning, continue processing
AUTHOR_WARNING = CMake Warning (dev), continue processing
SEND_ERROR     = CMake Error, continue processing, but skip generation
FATAL_ERROR    = CMake Error, stop processing and generation
DEPRECATION    = CMake Deprecation Error or Warning if variable
                 CMAKE_ERROR_DEPRECATED or CMAKE_WARN_DEPRECATED
                 is enabled, respectively, else no message.

例如 CMake学习(四) 中的隐式变量test_4_BINARY_DIR 和 test_4_SOURCE_DIR 可以打印输出。

project(test_4)
message("test_4_BINARY_DIR = ${test_4_BINARY_DIR}")
message("test_4_SOURCE_DIR = ${test_4_SOURCE_DIR}")

结果为: please write description of the picture here please write description of the picture here please write description of the picture here please write description of the picture here

参考:
cmake.org/cmake/help/…
www.jianshu.com/p/a2102347d…