From a78cba51978fbc805993604767c1902a249482ff Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 16 Jan 2023 14:32:36 -0500 Subject: 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 --- Help/command/message.rst | 50 ++++++++++++++++++++++ Help/manual/cmake-configure-log.7.rst | 32 ++++++++++++++ Help/release/dev/configure-log.rst | 3 ++ Source/cmFileAPIConfigureLog.cxx | 1 + Source/cmMessageCommand.cxx | 28 ++++++++++++ Tests/RunCMake/FileAPI/configureLog-v1-check.py | 2 +- Tests/RunCMake/message/ConfigureLog-config.txt | 30 +++++++++++++ Tests/RunCMake/message/ConfigureLog-stdout.txt | 4 ++ Tests/RunCMake/message/ConfigureLog.cmake | 7 +++ .../RunCMake/message/ConfigureLogScript-config.txt | 1 + .../RunCMake/message/ConfigureLogScript-stdout.txt | 4 ++ Tests/RunCMake/message/ConfigureLogScript.cmake | 1 + Tests/RunCMake/message/RunCMakeTest.cmake | 2 + 13 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 Tests/RunCMake/message/ConfigureLog-config.txt create mode 100644 Tests/RunCMake/message/ConfigureLog-stdout.txt create mode 100644 Tests/RunCMake/message/ConfigureLog.cmake create mode 100644 Tests/RunCMake/message/ConfigureLogScript-config.txt create mode 100644 Tests/RunCMake/message/ConfigureLogScript-stdout.txt create mode 100644 Tests/RunCMake/message/ConfigureLogScript.cmake diff --git a/Help/command/message.rst b/Help/command/message.rst index 9ac4277..e8a4ea0 100644 --- a/Help/command/message.rst +++ b/Help/command/message.rst @@ -14,6 +14,8 @@ Synopsis `Reporting checks`_ message( "message text" ...) + `Configure Log`_ + message(CONFIGURE_LOG ...) 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 ...) + +Record a :ref:`configure-log message event ` +with the specified ````. 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