diff options
author | Leander Beernaert <leander.beernaert@qt.io> | 2020-02-03 16:52:18 +0100 |
---|---|---|
committer | Leander Beernaert <leander.beernaert@qt.io> | 2020-02-05 15:18:03 +0000 |
commit | 20bb59ca61e6e40e04092771d8f1116dc011f9bc (patch) | |
tree | 6d707b75a91257a4a747f0f30092454bcfeab7ca /src | |
parent | ac38fa11823f4cf020a9481c9de3d61caa8fccdc (diff) |
Allow manually specification of moc.json files for metatype generation
qt6_generate_meta_types_json_file() has been extended to allow the
generated moc_....cpp.json files to be manually specified. This now
enabled the metatype generation to be used without resorting to AUTOMOC.
Additionally, Core_qobject declaration order has been temporarily moved
as it otherwise does not produce the correct metatypes dependency file
for Core. This will be fixed in a follow up patch.
Change-Id: I3266ab3073db478458a0c1dbc8b9fbab16622a64
Reviewed-by: Qt CMake Build Bot
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/CMakeLists.txt | 21 | ||||
-rw-r--r-- | src/corelib/Qt6CoreMacros.cmake | 136 |
2 files changed, 108 insertions, 49 deletions
diff --git a/src/corelib/CMakeLists.txt b/src/corelib/CMakeLists.txt index ca53e47ac3..1ec6eb5029 100644 --- a/src/corelib/CMakeLists.txt +++ b/src/corelib/CMakeLists.txt @@ -26,6 +26,10 @@ file(RELATIVE_PATH QT_INVERSE_CONFIG_INSTALL_DIR ${_clean_prefix} ${CMAKE_INSTAL ## Core Module: ##################################################################### +# special case begin +add_library(Core_qobject OBJECT) +# special case end + qt_add_module(Core GENERATE_METATYPES QMAKE_MODULE_CONFIG moc resources @@ -112,7 +116,7 @@ qt_add_module(Core kernel/qmetatype.cpp kernel/qmetatype.h kernel/qmetatype_p.h kernel/qmetatypeswitcher_p.h kernel/qmimedata.cpp kernel/qmimedata.h - # kernel/qobject.cpp kernel/qobject.h kernel/qobject_p.h # special case + # kernel/qobject.cpp kernel/qobject.h kernel/qobject_p.h # special case kernel/qobject_impl.h kernel/qobjectcleanuphandler.cpp kernel/qobjectcleanuphandler.h kernel/qobjectdefs.h @@ -260,6 +264,7 @@ qt_add_module(Core QtHarfBuzz # special case Threads::Threads # special case WrapDoubleConversion::WrapDoubleConversion # special case + Core_qobject PUBLIC_LIBRARIES # special case: Qt::Platform # special case: # special case begin @@ -284,8 +289,8 @@ qt_generate_qconfig_cpp() # Handle QObject: Automoc does not work for this as it would # require to spill internals into users: -add_library(Core_qobject OBJECT) -qt_manual_moc(qobject_moc_files kernel/qobject.h global/qnamespace.h) +set_target_properties(Core_qobject PROPERTIES AUTOMOC OFF) +qt_manual_moc(qobject_moc_files OUTPUT_MOC_JSON_FILES core_qobject_metatypes_json_list kernel/qobject.h global/qnamespace.h) set_source_files_properties(${qobject_moc_files} PROPERTIES HEADER_FILE_ONLY ON) target_sources(Core_qobject PRIVATE global/qnamespace.h @@ -299,6 +304,16 @@ target_include_directories(Core_qobject PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/ker target_link_libraries(Core_qobject PRIVATE Qt::Platform Qt::GlobalConfig) target_link_libraries(Core PRIVATE Core_qobject) +set(core_qobject_metatypes_json_args) +if (NOT QT_WILL_INSTALL) + set(core_qobject_metatypes_json_args INSTALL_DIR "${QT_BUILD_DIR}/${INSTALL_LIBDIR}/metatypes") +endif() + +qt6_generate_meta_types_json_file(Core_qobject + MANUAL_MOC_JSON_FILES ${core_qobject_metatypes_json_list} + ${core_qobject_metatypes_json_args} +) + if(NOT BUILD_SHARED_LIBS) install( TARGETS Core_qobject diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake index 21910078ea..1810fdeb65 100644 --- a/src/corelib/Qt6CoreMacros.cmake +++ b/src/corelib/Qt6CoreMacros.cmake @@ -691,14 +691,23 @@ function(qt6_generate_meta_types_dep_file target dep_file dep_file_install) endfunction() # -# Generate Qt metatypes.json for a target +# Generate Qt metatypes.json for a target. By default we check whether AUTOMOC +# has been enabled and we extract the information from that target. Should you +# not wish to use automoc you need to pass in all the generated json files via the +# MANUAL_MOC_JSON_FILES parameter. The latter can be obtained by running moc with +# the --output-json parameter. # Params: # INSTALL_DIR: Location where to install the metatypes file (Optional) # COPY_OVER_INSTALL: When present will install the file via a post build step # copy rather than using install function(qt6_generate_meta_types_json_file target) - cmake_parse_arguments(arg "COPY_OVER_INSTALL" "INSTALL_DIR" "" ${ARGN}) + get_target_property(existing_meta_types_file ${target} INTERFACE_QT_META_TYPES_BUILD_FILE) + if (existing_meta_types_file) + return() + endif() + + cmake_parse_arguments(arg "COPY_OVER_INSTALL" "INSTALL_DIR" "MANUAL_MOC_JSON_FILES" ${ARGN}) if (NOT QT_BUILDING_QT) if (NOT arg_INSTALL_DIR) @@ -716,57 +725,80 @@ function(qt6_generate_meta_types_json_file target) endif() endif() - # Tell automoc to output json files - set_property(TARGET "${target}" APPEND PROPERTY - AUTOMOC_MOC_OPTIONS "--output-json" - ) - 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") + if (target_type STREQUAL "INTERFACE_LIBRARY") + message(FATAL_ERROR "Meta types generation does not work on interface libraries") return() endif() - get_target_property(existing_meta_types_file ${target} INTERFACE_QT_META_TYPES_BUILD_FILE) - if (existing_meta_types_file) + if (CMAKE_VERSION VERSION_LESS "3.16.0") + message(FATAL_ERROR "Meta types generation requires CMake >= 3.16") return() endif() get_target_property(target_binary_dir ${target} BINARY_DIR) + set(type_list_file "${target_binary_dir}/meta_types/${target}_json_file_list.txt") + set(type_list_file_manual "${target_binary_dir}/meta_types/${target}_json_file_list_manual.txt") + + get_target_property(uses_automoc ${target} AUTOMOC) + set(automoc_args) + set(automoc_dependencies) + #Handle automoc generated data + if (uses_automoc) + # Tell automoc to output json files) + set_property(TARGET "${target}" APPEND PROPERTY + AUTOMOC_MOC_OPTIONS "--output-json" + ) - if(CMAKE_BUILD_TYPE) - set(cmake_autogen_cache_file - "${target_binary_dir}/CMakeFiles/${target}_autogen.dir/ParseCache.txt") - set(mutli_config_args - --cmake-autogen-include-dir-path "${target_binary_dir}/${target}_autogen/include" + if(CMAKE_BUILD_TYPE) + set(cmake_autogen_cache_file + "${target_binary_dir}/CMakeFiles/${target}_autogen.dir/ParseCache.txt") + set(mutli_config_args + --cmake-autogen-include-dir-path "${target_binary_dir}/${target}_autogen/include" + ) + else() + set(cmake_autogen_cache_file + "${target_binary_dir}/CMakeFiles/${target}_autogen.dir/ParseCache_$<CONFIG>.txt") + set(mutli_config_args + --cmake-autogen-include-dir-path "${target_binary_dir}/${target}_autogen/include_$<CONFIG>" + "--cmake-multi-config") + endif() + + set(cmake_autogen_info_file + "${target_binary_dir}/CMakeFiles/${target}_autogen.dir/AutogenInfo.json") + + add_custom_target(${target}_automoc_json_extraction + DEPENDS ${QT_CMAKE_EXPORT_NAMESPACE}::cmake_automoc_parser + 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}" + ${mutli_config_args} + COMMENT "Running Automoc file extraction" + COMMAND_EXPAND_LISTS ) - else() - set(cmake_autogen_cache_file - "${target_binary_dir}/CMakeFiles/${target}_autogen.dir/ParseCache_$<CONFIG>.txt") - set(mutli_config_args - --cmake-autogen-include-dir-path "${target_binary_dir}/${target}_autogen/include_$<CONFIG>" - "--cmake-multi-config") - endif() - - 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 - DEPENDS ${QT_CMAKE_EXPORT_NAMESPACE}::cmake_automoc_parser - 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}" - ${mutli_config_args} - COMMENT "Running Automoc file extraction" - COMMAND_EXPAND_LISTS - ) + add_dependencies(${target}_automoc_json_extraction ${target}_autogen) + set(automoc_args "@${type_list_file}") + set(automoc_dependencies "${type_list_file}") + endif() + + set(manual_args) + set(manual_dependencies) + if(arg_MANUAL_MOC_JSON_FILES) + list(REMOVE_DUPLICATES arg_MANUAL_MOC_JSON_FILES) + file(GENERATE + OUTPUT ${type_list_file_manual} + CONTENT "$<JOIN:$<GENEX_EVAL:${arg_MANUAL_MOC_JSON_FILES}>,\n>" + ) + list(APPEND manual_dependencies ${arg_MANUAL_MOC_JSON_FILES} ${type_list_file_manual}) + set(manual_args "@${type_list_file_manual}") + endif() - add_dependencies(${target}_automoc_json_extraction ${target}_autogen) + if (NOT manual_args AND NOT automoc_args) + message(FATAL_ERROR "Metatype generation requires either the use of AUTOMOC or a manual list of generated json files") + endif() if (CMAKE_BUILD_TYPE) string(TOLOWER ${target}_${CMAKE_BUILD_TYPE} target_lowercase) @@ -781,10 +813,10 @@ function(qt6_generate_meta_types_json_file target) set(metatypes_dep_file "${target_binary_dir}/meta_types/${metatypes_dep_file_name}") add_custom_command(OUTPUT ${metatypes_file} - DEPENDS ${type_list_file} ${QT_CMAKE_EXPORT_NAMESPACE}::moc + DEPENDS ${QT_CMAKE_EXPORT_NAMESPACE}::moc ${automoc_dependencies} ${manual_dependencies} COMMAND ${QT_CMAKE_EXPORT_NAMESPACE}::moc -o ${metatypes_file} - --collect-json "@${type_list_file}" + --collect-json ${automoc_args} ${manual_args} COMMENT "Runing automoc with --collect-json" ) @@ -808,14 +840,26 @@ function(qt6_generate_meta_types_json_file target) ) if (arg_COPY_OVER_INSTALL) - add_custom_command(TARGET ${target} POST_BUILD + get_target_property(target_type ${target} TYPE) + set(command_args COMMAND ${CMAKE_COMMAND} -E copy_if_different "${metatypes_file}" "${arg_INSTALL_DIR}/${metatypes_file_name}" COMMAND ${CMAKE_COMMAND} -E copy_if_different "${metatypes_dep_file}.install" "${arg_INSTALL_DIR}/${metatypes_dep_file_name}" - ) + ) + if (target_type STREQUAL "OBJECT_LIBRARY") + add_custom_target(${target}_metatypes_copy + DEPENDS "${metatypes_file}" "${metatypes_dep_file}" + ${command_args} + ) + add_dependencies(${target} ${target}_metatypes_copy) + else() + add_custom_command(TARGET ${target} POST_BUILD + ${command_args} + ) + endif() else() install(FILES "${metatypes_file}" DESTINATION "${arg_INSTALL_DIR}" |