From 645671d36f5cf0fa411d98a637f4edbc3d896c57 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 18 Jan 2023 11:33:40 -0500 Subject: Help: Document configure log behavior in try_compile and try_run --- Help/command/try_compile.rst | 5 +++++ Help/command/try_run.rst | 5 +++++ Help/manual/cmake-configure-log.7.rst | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/Help/command/try_compile.rst b/Help/command/try_compile.rst index 8f6a4eb..21b063f 100644 --- a/Help/command/try_compile.rst +++ b/Help/command/try_compile.rst @@ -42,6 +42,11 @@ below for the meaning of other options. Previously this was only done by the :ref:`source file ` signature. +.. versionadded:: 3.26 + This command records a + :ref:`configure-log try_compile event ` + if the ``NO_LOG`` option is not specified. + This command also supports an alternate signature which was present in older versions of CMake: diff --git a/Help/command/try_run.rst b/Help/command/try_run.rst index ef8ec96..7566264 100644 --- a/Help/command/try_run.rst +++ b/Help/command/try_run.rst @@ -50,6 +50,11 @@ the test project is constructed to build the source file. One or more source files must be provided. Additionally, one of ``SOURCES`` and/or ``SOURCE_FROM_*`` must precede other keywords. +.. versionadded:: 3.26 + This command records a + :ref:`configure-log try_run event ` + if the ``NO_LOG`` option is not specified. + This command also supports an alternate signature which was present in older versions of CMake: diff --git a/Help/manual/cmake-configure-log.7.rst b/Help/manual/cmake-configure-log.7.rst index 2620124..768ef7e 100644 --- a/Help/manual/cmake-configure-log.7.rst +++ b/Help/manual/cmake-configure-log.7.rst @@ -131,6 +131,8 @@ The keys common to all events are: Additional mapping keys are specific to each (versioned) event kind, described below. +.. _`try_compile configure-log event`: + Event Kind ``try_compile`` -------------------------- @@ -204,6 +206,8 @@ The keys specific to ``try_compile-v1`` mappings are: An integer specifying the build tool exit code from trying to build the test project. +.. _`try_run configure-log event`: + Event Kind ``try_run`` ---------------------- -- cgit v0.12 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