CMake: Enable building Qt and user projects without support for aotstats

You can now use the QT_QML_GENERATE_AOTSTATS CMake variable to control
whether aotstats get generated in Qt or in users projects.

[ChangeLog][Qml] It is now possible to control whether QML Compiler
statistics (aotstats) get generated by setting the
QT_QML_GENERATE_AOTSTATS CMake variable to ON or OFF. The default value
is ON.

Fixes: QTBUG-131002
Task-number: QTBUG-128323
Pick-to: 6.9 6.8
Change-Id: Ibfd55b22d3d284218053bbf67f654c63a7507bae
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Olivier De Cannière 2025-02-03 13:22:28 +01:00
parent 316e8f4626
commit a0bde44fef
3 changed files with 49 additions and 13 deletions

View File

@ -903,6 +903,15 @@ Check https://doc.qt.io/qt-6/qt-cmake-policy-qtp0001.html for policy details."
# special (and is not a real resource file)
set_property(TARGET ${target} APPEND PROPERTY _qt_qml_meta_qrc_files "${dir_map_qrc}")
set(do_qml_aotstats OFF)
if(NOT DEFINED QT_QML_GENERATE_AOTSTATS OR QT_QML_GENERATE_AOTSTATS)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.19)
set(do_qml_aotstats ON)
else()
message(WARNING "aotstats is not supported on CMake versions < 3.19")
endif()
endif()
set(cache_target)
qt6_target_qml_sources(${target}
__QT_INTERNAL_FORCE_DEFER_QMLDIR
@ -1082,7 +1091,7 @@ Check https://doc.qt.io/qt-6/qt-cmake-policy-qtp0001.html for policy details."
endif()
endif()
if("${CMAKE_VERSION}" VERSION_GREATER_EQUAL "3.19.0")
if(do_qml_aotstats)
set_property(GLOBAL APPEND PROPERTY _qt_qml_aotstats_module_targets ${target})
set_target_properties(${target} PROPERTIES
QT_QML_MODULE_RCC_QMLCACHE_PATH "${CMAKE_CURRENT_BINARY_DIR}/.rcc/qmlcache"
@ -1094,13 +1103,6 @@ Check https://doc.qt.io/qt-6/qt-cmake-policy-qtp0001.html for policy details."
cmake_language(EVAL CODE "cmake_language(DEFER DIRECTORY \"${CMAKE_BINARY_DIR}\" "
"CALL _qt_internal_deferred_aotstats_setup)")
endif()
else()
if(NOT TARGET all_aotstats)
add_custom_target(
all_aotstats
${CMAKE_COMMAND} -E echo "aotstats is not supported on CMake versions < 3.19"
)
endif()
endif()
endfunction()
@ -3025,11 +3027,17 @@ function(qt6_target_qml_sources target)
"$<${have_direct_calls}:--direct-calls>"
"$<${have_arguments}:${arguments}>"
${qrc_resource_args}
)
if(do_qml_aotstats)
# The --only-bytecode argument is mutually exclusive with aotstats and can
# be added after qt_add_qml_module. Conditionally add aotstats flags via genex.
"$<$<NOT:$<IN_LIST:--only-bytecode,${arguments}>>:--dump-aot-stats>"
"$<$<NOT:$<IN_LIST:--only-bytecode,${arguments}>>:--module-id=${uri}(${target})>"
)
set(aotstats_args
"$<$<NOT:$<IN_LIST:--only-bytecode,${arguments}>>:--dump-aot-stats>"
"$<$<NOT:$<IN_LIST:--only-bytecode,${arguments}>>:--module-id=${uri}(${target})>"
)
list(APPEND cachegen_args ${aotstats_args})
endif()
# For direct evaluation in if() below
get_target_property(cachegen_prop ${target} QT_QMLCACHEGEN_EXECUTABLE)
@ -3345,7 +3353,7 @@ function(qt6_target_qml_sources target)
endif()
set(aotstats_file "")
if("${qml_file_src}" MATCHES ".+\\.qml")
if(do_qml_aotstats AND "${qml_file_src}" MATCHES ".+\\.qml")
set(aotstats_file "${compiled_file}.aotstats")
list(APPEND aotstats_files ${aotstats_file})
endif()
@ -3398,7 +3406,7 @@ function(qt6_target_qml_sources target)
endif()
endforeach()
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.19)
if(do_qml_aotstats)
set_property(TARGET ${target} APPEND PROPERTY
QT_QML_MODULE_AOTSTATS_FILES ${aotstats_files})
endif()

View File

@ -109,3 +109,27 @@ qt_add_qml_module(MyModule
*/
/*!
\page cmake-variable-qt-qml-generate-aotstats.html
\ingroup cmake-variables-qtqml
\title QT_QML_GENERATE_AOTSTATS
\brief Controls whether QML Compiler statistics collection is enabled.
\cmakevariablesince 6.8.3
When a QML project is configured using \l{qt_add_qml_modules}, by default,
\l{QML script compiler#Obtaining statistics about the compilation of functions and bindings}{statistics}
from the compilation of QML code will be collected. You can explicitly opt in
or out of this by setting the \c{QT_QML_GENERATE_AOTSTATS} variable. It can be
set project-wide by passing
\badcode
-DQT_QML_GENERATE_AOTSTATS=OFF
\endcode
to the CMake executable, or by setting it directly in the corresponding
CMakeLists.txt file before the first call to \l{qt_add_qml_module}.
\badcode
set(QT_QML_GENERATE_AOTSTATS OFF)
\endcode
*/

View File

@ -129,6 +129,10 @@ quick overview of how well a project is being compiled.
To show statistics, invoke the \e{all_aotstats} cmake target.
The collection of compilation statistics is enabled by default. In order to
disable it, set the \l{QT_QML_GENERATE_AOTSTATS} CMake variable to OFF before
the first call to \l{qt_add_qml_module}.
\note These statistics are only available for modules registered through the
\l{qt_add_qml_module} cmake API