diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2021-09-17 15:03:55 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2021-09-18 07:37:32 +0200 |
commit | 90e7d6db1bb44de3629ec2b70df26fbafe4294fa (patch) | |
tree | dbfe7984c22769fcef9065f72470d1405414da3a | |
parent | a3412c37b260f9663ca85020a93d1a54d76b408f (diff) |
CMake: Add option in qt6_wrap_cpp to output a metatypes json file
At the moment only the Qt internal qt_manual_moc function allows
manually running moc and generating a metatypes json file.
There is no such functionality available in the public qt6_wrap_cpp
and qt6_generate_moc functions.
Change qt6_wrap_cpp to accept a new internal option called
__QT_INTERNAL_OUTPUT_MOC_JSON_FILES to allow creating and retrieving
the associated json file with metatypes information.
This is needed to fix qtremoteobjects CMake API which needs to run moc
manually and process the metatypes json file.
The option is internal because we don't want to introduce new API in
6.2.0.
Pick-to: dev 6.2
Task-number: QTBUG-95832
Change-Id: Ic8dd27fc960c3f8dea8c101dfc028db45494953d
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Jani Heikkinen <jani.heikkinen@qt.io>
-rw-r--r-- | src/corelib/Qt6CoreMacros.cmake | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake index e4ecb4d459..be2d6a20fb 100644 --- a/src/corelib/Qt6CoreMacros.cmake +++ b/src/corelib/Qt6CoreMacros.cmake @@ -104,7 +104,8 @@ macro(_qt_internal_get_moc_flags _moc_flags) endmacro() # helper macro to set up a moc rule -function(_qt_internal_create_moc_command infile outfile moc_flags moc_options moc_target moc_depends) +function(_qt_internal_create_moc_command infile outfile moc_flags moc_options + moc_target moc_depends out_json_file) # Pass the parameters in a file. Set the working directory to # be that containing the parameters file and reference it by # just the file name. This is necessary because the moc tool on @@ -117,6 +118,11 @@ function(_qt_internal_create_moc_command infile outfile moc_flags moc_options mo endif() set (_moc_parameters_file ${outfile}_parameters) set (_moc_parameters ${moc_flags} ${moc_options} -o "${outfile}" "${infile}") + if(out_json_file) + list(APPEND _moc_parameters --output-json) + set(extra_output_files "${outfile}.json") + set(${out_json_file} "${extra_output_files}" PARENT_SCOPE) + endif() string (REPLACE ";" "\n" _moc_parameters "${_moc_parameters}") if(moc_target) @@ -139,7 +145,7 @@ function(_qt_internal_create_moc_command infile outfile moc_flags moc_options mo endif() set(_moc_extra_parameters_file @${_moc_parameters_file}) - add_custom_command(OUTPUT ${outfile} + add_custom_command(OUTPUT ${outfile} ${extra_output_files} COMMAND ${QT_CMAKE_EXPORT_NAMESPACE}::moc ${_moc_extra_parameters_file} DEPENDS ${infile} ${moc_depends} ${_moc_working_dir} @@ -160,7 +166,10 @@ function(qt6_generate_moc infile outfile ) if ("x${ARGV2}" STREQUAL "xTARGET") set(moc_target ${ARGV3}) endif() - _qt_internal_create_moc_command(${abs_infile} ${_outfile} "${moc_flags}" "" "${moc_target}" "") + _qt_internal_create_moc_command(${abs_infile} ${_outfile} "${moc_flags}" "" "${moc_target}" + "" # moc_depends + "" # out_json_file + ) endfunction() if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS) @@ -181,7 +190,10 @@ function(qt6_wrap_cpp outfiles ) _qt_internal_get_moc_flags(moc_flags) set(options) - set(oneValueArgs TARGET) + set(oneValueArgs + TARGET + __QT_INTERNAL_OUTPUT_MOC_JSON_FILES + ) set(multiValueArgs OPTIONS DEPENDS) cmake_parse_arguments(_WRAP_CPP "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) @@ -191,14 +203,31 @@ function(qt6_wrap_cpp outfiles ) set(moc_target ${_WRAP_CPP_TARGET}) set(moc_depends ${_WRAP_CPP_DEPENDS}) + set(metatypes_json_list "") + foreach(it ${moc_files}) get_filename_component(it ${it} ABSOLUTE) _qt_internal_make_output_file(${it} moc_ cpp outfile) + + set(out_json_file_var "") + if(_WRAP_CPP___QT_INTERNAL_OUTPUT_MOC_JSON_FILES) + set(out_json_file_var "out_json_file") + endif() + _qt_internal_create_moc_command( - ${it} ${outfile} "${moc_flags}" "${moc_options}" "${moc_target}" "${moc_depends}") + ${it} ${outfile} "${moc_flags}" "${moc_options}" "${moc_target}" "${moc_depends}" + "${out_json_file_var}") list(APPEND ${outfiles} ${outfile}) + if(_WRAP_CPP___QT_INTERNAL_OUTPUT_MOC_JSON_FILES) + list(APPEND metatypes_json_list "${${out_json_file_var}}") + endif() endforeach() set(${outfiles} ${${outfiles}} PARENT_SCOPE) + + if(metatypes_json_list) + set(${_WRAP_CPP___QT_INTERNAL_OUTPUT_MOC_JSON_FILES} + "${metatypes_json_list}" PARENT_SCOPE) + endif() endfunction() # This will override the CMake upstream command, because that one is for Qt 3. |