diff options
author | Leander Beernaert <leander.beernaert@qt.io> | 2019-11-26 10:10:55 +0100 |
---|---|---|
committer | Leander Beernaert <leander.beernaert@qt.io> | 2019-12-04 10:48:06 +0000 |
commit | 0f220d473a6048c0f1267a96ed5cc18fa39ee61c (patch) | |
tree | 20b4c0bbaa908e86973466e5b2b8ae8e52dbbca7 /src/corelib/Qt6CoreMacros.cmake | |
parent | 9eea24ed601d0aa243269fac64c9a65c3750d1b0 (diff) |
Collect Json Metatypes from CMake's Automoc
This patch adds a new bootstrap tool which will read CMake's
AutoGenInfo.json and ParseCache.txt to determine what the current
list of json files is that needs to be passed to moc --collect-json
option.
Right now this is enabled for qt_add_module() with the option
GENERATE_METATYPES. pro2cmake has also been updated to detect qmake's
CONFIG += metatypes and to generate the above option for modules.
The implementation lives in Qt6CoreMacros so it can eventually be used
in the public facing apis.
The generated meta types file is saved under the target property
QT_MODULE_META_TYPES_FILE.
Change-Id: I03709c662be81dd0912d0068c23ee2507bfe4383
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'src/corelib/Qt6CoreMacros.cmake')
-rw-r--r-- | src/corelib/Qt6CoreMacros.cmake | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake index dbc9cdb163..3da011ecb1 100644 --- a/src/corelib/Qt6CoreMacros.cmake +++ b/src/corelib/Qt6CoreMacros.cmake @@ -530,3 +530,61 @@ function(qt6_import_plugins TARGET_NAME) endif() endforeach() endfunction() + + +function(qt6_generate_meta_types_json_file target) + + get_target_property(target_type ${target} TYPE) + if (target_type STREQUAL "INTERFACE_LIBRARY" OR CMAKE_VERSION VERSION_LESS "3.16.0") + # interface libraries not supported or cmake version is not high enough + message(WARNING "Meta types generation requires CMake >= 3.16") + return() + endif() + + get_target_property(existing_meta_types_file ${target} QT_MODULE_META_TYPES_FILE) + if (existing_meta_types_file) + return() + endif() + + get_target_property(target_binary_dir ${target} BINARY_DIR) + + set(cmake_autogen_cache_file + "${target_binary_dir}/CMakeFiles/${target}_autogen.dir/ParseCache.txt") + set(cmake_autogen_info_file + "${target_binary_dir}/CMakeFiles/${target}_autogen.dir/AutogenInfo.json") + set(type_list_file "${target_binary_dir}/meta_types/json_file_list.txt") + + add_custom_target(${target}_automoc_json_extraction + BYPRODUCTS ${type_list_file} + COMMAND + ${QT_CMAKE_EXPORT_NAMESPACE}::cmake_automoc_parser + --cmake-autogen-cache-file "${cmake_autogen_cache_file}" + --cmake-autogen-info-file "${cmake_autogen_info_file}" + --output-file-path "${type_list_file}" + --cmake-autogen-include-dir-path "${target_binary_dir}/${target}_autogen/include" + COMMENT "Running Automoc file extraction" + ) + + add_dependencies(${target}_automoc_json_extraction ${target}_autogen) + + if (CMAKE_BUILD_TYPE) + string(TOLOWER ${target}_${CMAKE_BUILD_TYPE} target_lowercase) + else() + message(FATAL_ERROR "add_custom_command's OUTPUT parameter does not support generator expressions, so we can't generate this file for multi-config generators") + endif() + set(metatypes_file "${target_binary_dir}/meta_types/qt6${target_lowercase}_metatypes.json") + add_custom_command(OUTPUT ${metatypes_file} + DEPENDS ${type_list_file} + COMMAND ${QT_CMAKE_EXPORT_NAMESPACE}::moc + -o ${metatypes_file} + --collect-json "@${type_list_file}" + COMMENT "Runing automoc with --collect-json" + ) + + target_sources(${target} PRIVATE ${metatypes_file}) + set_source_files_properties(${metatypes_file} PROPERTIES HEADER_FILE_ONLY TRUE) + + set_target_properties(${target} PROPERTIES + QT_MODULE_META_TYPES_FILE ${metatypes_file} + ) +endfunction() |