Skip to content

Allow a function to be called when a target is "closed" / "finalized"

Upstream Qt issue https://bugreports.qt.io/browse/QTBUG-77377

Posting the description in here as well.

Such a feature would allow providing cleaner CMake API for users of Qt and CMake.

For example for pre-compiling QML files into some binary form, without this feature, you could have a hypothetical API as follows.

add_qml_module(Foo)
qml_target_sources(Foo a.qml)
if(APPLE)
  qml_target_sources(Foo b.qml)
endif()

more qml_target_source calls .....

qml_run_quick_compiler(Foo)

qml_run_quick_compiler needs to be called manually by a user after all qml_target_sources have been called.

With the proposed feature, we could have a cleaner API where the user does not have to call qml_run_quick_compiler explicitly, it would be called automatically by CMake.

add_qml_module(Foo)
qml_target_sources(Foo a.qml)
if(APPLE)
  qml_target_sources(Foo b.qml)
endif()

more qml_target_source calls .....

and inside add_qml_module you would have something like:

function(qml_run_quick_compiler target)
...
set_property(TARGET ${target} PROPERTY CALL_ON_TARGET_FINALIZE "qml_run_quick_compiler")
...
endfunction()

Thus the user can't accidentally forget to call qml_run_quick_compiler(), CMake would do it for them.

Of course we should find a nice design on how to specify that a function needs to be called, and how are parameters passed to it.

Edited by Brad King
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information