message: Add CONFIGURE_LOG mode to record a message in the configure log

Provide a replacement for `file(APPEND .../CMake{Output,Error}.log)`
that records messages in the configure log.

Issue: #23200
This commit is contained in:
Brad King
2023-01-16 14:32:36 -05:00
parent 645671d36f
commit a78cba5197
13 changed files with 164 additions and 1 deletions

View File

@@ -14,6 +14,8 @@ Synopsis
`Reporting checks`_
message(<checkState> "message text" ...)
`Configure Log`_
message(CONFIGURE_LOG <text>...)
General messages
^^^^^^^^^^^^^^^^
@@ -194,6 +196,54 @@ Output from the above would appear something like the following::
-- Finding partB - not found
-- Finding my things - missing components: B
Configure Log
^^^^^^^^^^^^^
.. versionadded:: 3.26
.. code-block:: cmake
message(CONFIGURE_LOG <text>...)
Record a :ref:`configure-log message event <message configure-log event>`
with the specified ``<text>``. By convention, if the text contains more
than one line, the first line should be a summary of the event.
This mode is intended to record the details of a system inspection check
or other one-time operation guarded by a cache entry, but that is not
performed using :command:`try_compile` or :command:`try_run`, which
automatically log their details. Projects should avoid calling it every
time CMake runs. For example:
.. code-block:: cmake
if (NOT DEFINED MY_CHECK_RESULT)
# Print check summary in configure output.
message(CHECK_START "My Check")
# ... perform system inspection, e.g., with execute_process ...
# Cache the result so we do not run the check again.
set(MY_CHECK_RESULT "${MY_CHECK_RESULT}" CACHE INTERNAL "My Check")
# Record the check details in the cmake-configure-log.
message(CONFIGURE_LOG
"My Check Result: ${MY_CHECK_RESULT}\n"
"${details}"
)
# Print check result in configure output.
if(MY_CHECK_RESULT)
message(CHECK_PASS "passed")
else()
message(CHECK_FAIL "failed")
endif()
endif()
If no project is currently being configured, such as in
:ref:`cmake -P <Script Processing Mode>` script mode,
this command does nothing.
See Also
^^^^^^^^