Print¶
Log a message by wrapping the CMake message() command to extend its functionalities .It requires CMake 3.20 or newer.
Synopsis¶
Print Formated Message print([<mode>] "message with format text" <argument>...) Print Path List print([<mode>] PATHS <file_list>... [INDENT]) Print String List print([<mode>] STRINGS <string_list>... [INDENT])
Module Variables¶
- PRINT_BASE_DIR¶
Specifies the base directory used to compute relative paths in the
print(formated_messages)
commands. Its default value is CMAKE_SOURCE_DIR.
Usage¶
- print([<mode>] "message with format text" <argument>...)¶
Record the specified message text in the log, optionally specifying a message mode. This command is inspired by the message() command from CMake and the C printf() function.
If specified, the optional
<mode>
keyword must be one of the standard message modes accepted by the message() command, such asSTATUS
,WARNING
,ERROR
, etc.The
"text to print"
may contain one or more custom conversion directives enclosed in@
characters. These directives will be replaced using the provided arguments, in the order they are given. Text without directives is equivalent to a call to message() command.Each directive takes the form
@specifier@
, wherespecifier
is one of the following:@ap@
Converts the corresponding argument into an absolute path to an existing file or directory.
@rp@
Converts the corresponding argument into a path relative to the value of the
PRINT_BASE_DIR
variable. The file or the directory must exist on the disk.
Example usage:
# Case 1: Without mode set(PRINT_BASE_DIR "${CMAKE_SOURCE_DIR}") set(my_path "src/main.cpp") print("Absolute: @ap@, Relative: @rp@" "${my_path}" "${my_path}") # output is: # Absolute: /full/path/to/src/main.cpp, Relative: src/main.cpp # Case 2: With status mode set(PRINT_BASE_DIR "${CMAKE_SOURCE_DIR}") set(my_path "src/main.cpp") print(STATUS "Absolute: @ap@, Relative: @rp@" "${my_path}" "${my_path}") # output is: # -- Absolute: /full/path/to/src/main.cpp, Relative: src/main.cpp
- print([<mode>] PATHS <file_list>... [INDENT])¶
Record in the log each file from the specified
<file_list>
after converting them to paths relative to the value of thePRINT_BASE_DIR
variable. This command is inspired by the message() command from CMake.The optional
<mode>
argument determines the message type and may be any of the standard message modes supported by the message() command, such asSTATUS
,WARNING
,ERROR
, etc.If the
INDENT
option is specified, the output message is indented by two spaces. This affects the indentation level of the printed message using the internal CMAKE_MESSAGE_INDENT stack.Example usage:
set(PRINT_BASE_DIR "${CMAKE_SOURCE_DIR}") set(my_files "${CMAKE_SOURCE_DIR}/src/main.cpp" "${CMAKE_SOURCE_DIR}/include/lib.hpp") print(STATUS PATHS ${my_files} INDENT) # output is: # src/main.cpp ; include/lib.hpp
- print([<mode>] STRINGS <string_list>... [INDENT])¶
Record in the log each string from the given
<string_list>
. This command is inspired by the message() command from CMake.If specified, the optional
<mode>
keyword must be one of the standard message modes accepted by the message() command, such asSTATUS
,WARNING
,ERROR
, etc.If the
INDENT
option is specified, the output message is indented by two spaces. This affects the indentation level of the printed message using the internal CMAKE_MESSAGE_INDENT stack.Example usage:
set(my_list "one" "two" "three") print(STATUS STRINGS ${my_list} INDENT) # output is: # one ; two ; three