From 5fcfacdb7f148ca81f43f9b1846483e61d26e7b2 Mon Sep 17 00:00:00 2001
From: Amir Masoud Abdol <amirmasoudabdol@icloud.com>
Date: Tue, 25 Oct 2022 16:48:21 +0200
Subject: [PATCH] Use CMAKE_MESSAGE_CONTEXT for Better CMake Output Messages

Each module now identifies its actions during the configuration by a
prefix, e.g., `[QtBase]`. In addition,

- I have slightly modified some of the `message()` commands to get
  a more coherent output.
- `syncqt.cpp` prints its output as WARNING if any

Change-Id: I3922d75a668d94f402068f4121751b7fcb6522b4
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
---
 cmake/QtBaseConfigureTests.cmake                    |  8 ++++++--
 cmake/QtBuildInternals/QtBuildInternalsConfig.cmake |  4 ++++
 cmake/QtSyncQtHelpers.cmake                         |  2 +-
 src/corelib/Qt6CTestMacros.cmake                    | 12 ++++++------
 4 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/cmake/QtBaseConfigureTests.cmake b/cmake/QtBaseConfigureTests.cmake
index 32db957447..d0c82e4098 100644
--- a/cmake/QtBaseConfigureTests.cmake
+++ b/cmake/QtBaseConfigureTests.cmake
@@ -12,10 +12,14 @@ function(qt_run_config_test_architecture)
     qt_get_platform_try_compile_vars(platform_try_compile_vars)
     list(APPEND flags ${platform_try_compile_vars})
 
-    list(TRANSFORM flags PREPEND "    " OUTPUT_VARIABLE flags_indented)
+    list(TRANSFORM flags PREPEND "            " OUTPUT_VARIABLE flags_indented)
     list(JOIN flags_indented "\n" flags_indented)
+
     message(STATUS
-            "Building architecture extraction project with the following CMake arguments:\n${flags_indented}")
+            "Building architecture extraction project with the following CMake arguments:")
+    list(POP_BACK CMAKE_MESSAGE_CONTEXT _context)
+    message(NOTICE ${flags_indented})
+    list(APPEND CMAKE_MESSAGE_CONTEXT ${_context})
 
     try_compile(
         _arch_result
diff --git a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake
index b2314b839b..8d22307587 100644
--- a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake
+++ b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake
@@ -382,6 +382,8 @@ macro(qt_internal_prepare_single_repo_target_set_build)
 endmacro()
 
 macro(qt_build_repo_begin)
+    list(APPEND CMAKE_MESSAGE_CONTEXT "${PROJECT_NAME}")
+
     qt_build_internals_set_up_private_api()
 
     # Prevent installation in non-prefix builds.
@@ -524,6 +526,8 @@ macro(qt_build_repo_end)
         set(QT_INTERNAL_SYNCED_MODULES ${synced_modules} CACHE INTERNAL
             "List of the synced modules. Prevents running syncqt.cpp after the first configuring.")
     endif()
+
+    list(POP_BACK CMAKE_MESSAGE_CONTEXT)
 endmacro()
 
 macro(qt_build_repo)
diff --git a/cmake/QtSyncQtHelpers.cmake b/cmake/QtSyncQtHelpers.cmake
index 8b8fea8932..82c855f7a6 100644
--- a/cmake/QtSyncQtHelpers.cmake
+++ b/cmake/QtSyncQtHelpers.cmake
@@ -436,7 +436,7 @@ function(qt_internal_target_sync_headers target module_headers module_headers_ge
                 "syncqt.cpp failed for module ${module}:\n${syncqt_output}")
         endif()
         if(syncqt_output)
-            message("${syncqt_output}")
+            message(WARNING "${syncqt_output}")
         endif()
         set_property(GLOBAL APPEND PROPERTY _qt_synced_modules ${module})
     endif()
diff --git a/src/corelib/Qt6CTestMacros.cmake b/src/corelib/Qt6CTestMacros.cmake
index c2cb883ee7..9406d02223 100644
--- a/src/corelib/Qt6CTestMacros.cmake
+++ b/src/corelib/Qt6CTestMacros.cmake
@@ -11,13 +11,13 @@
 #
 # We mean it.
 
-message("CMAKE_VERSION: ${CMAKE_VERSION}")
-message("CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
-message("CMAKE_MODULES_UNDER_TEST: ${CMAKE_MODULES_UNDER_TEST}")
+message(STATUS "CMAKE_VERSION: ${CMAKE_VERSION}")
+message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
+message(STATUS "CMAKE_MODULES_UNDER_TEST: ${CMAKE_MODULES_UNDER_TEST}")
 foreach(_mod ${CMAKE_MODULES_UNDER_TEST})
-    message("CMAKE_${_mod}_MODULE_MAJOR_VERSION: ${CMAKE_${_mod}_MODULE_MAJOR_VERSION}")
-    message("CMAKE_${_mod}_MODULE_MINOR_VERSION: ${CMAKE_${_mod}_MODULE_MINOR_VERSION}")
-    message("CMAKE_${_mod}_MODULE_PATCH_VERSION: ${CMAKE_${_mod}_MODULE_PATCH_VERSION}")
+    message(STATUS "CMAKE_${_mod}_MODULE_MAJOR_VERSION: ${CMAKE_${_mod}_MODULE_MAJOR_VERSION}")
+    message(STATUS "CMAKE_${_mod}_MODULE_MINOR_VERSION: ${CMAKE_${_mod}_MODULE_MINOR_VERSION}")
+    message(STATUS "CMAKE_${_mod}_MODULE_PATCH_VERSION: ${CMAKE_${_mod}_MODULE_PATCH_VERSION}")
 endforeach()
 
 # Generate a shell script wrapper that calls ninja with -v parameter.