--- a/ui/qt/qt.gni +++ b/ui/qt/qt.gni @@ -12,9 +12,21 @@ declare_args() { use_qt = is_linux && !is_castos && !is_msan } +declare_args() { + if(!use_sysroot && use_qt) { + moc_qt5_path = "" + } +} + declare_args() { use_qt6 = use_qt && use_sysroot } +declare_args() { + if(!use_sysroot && use_qt6) { + moc_qt6_path = "" + } +} + # use_qt6 => use_qt assert(!use_qt6 || use_qt) --- a/ui/qt/BUILD.gn +++ b/ui/qt/BUILD.gn @@ -41,16 +41,19 @@ source_set("qt_interface") { sources = [ "qt_interface.cc" ] } -if (!use_sysroot) { - action("generate_moc") { - script = "moc_wrapper.py" - inputs = [ "//ui/qt/qt_shim.h" ] - outputs = [ "$root_gen_dir/qt_shim_moc.cc" ] - args = rebase_path(inputs + outputs, root_build_dir) +template("qt_shim") { + if (!use_sysroot) { + action("generate_moc" + invoker.qt_version) { + script = "moc_wrapper.py" + inputs = [ "//ui/qt/qt_shim.h" ] + outputs = [ "$root_gen_dir/qt" + invoker.qt_version + "/qt_shim_moc.cc" ] + args = rebase_path(inputs + outputs, root_build_dir) + if (invoker.moc_qt_path != "") { + args += [ "--path", invoker.moc_qt_path ] + } + } } -} -template("qt_shim") { pkg_config("qt" + invoker.qt_version + "_config") { packages = [ "Qt" + invoker.qt_version + "Core", @@ -90,17 +93,23 @@ template("qt_shim") { # avoid a build-time dependency on `moc` when using the sysroot. sources += [ "qt" + invoker.qt_version + "_shim_moc.cc" ] } else { - sources += get_target_outputs(":generate_moc") - deps += [ ":generate_moc" ] + sources += get_target_outputs(":generate_moc" + invoker.qt_version) + deps += [ ":generate_moc" + invoker.qt_version ] } } } qt_shim("qt5_shim") { qt_version = "5" + if (!use_sysroot) { + moc_qt_path = "$moc_qt5_path" + } } if (use_qt6) { qt_shim("qt6_shim") { qt_version = "6" + if (!use_sysroot) { + moc_qt_path = "$moc_qt6_path" + } } } --- a/ui/qt/moc_wrapper.py +++ b/ui/qt/moc_wrapper.py @@ -3,8 +3,21 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +import argparse import subprocess -import sys +parser = argparse.ArgumentParser() +parser.add_argument( + 'input', type=str, help='Input header file.') +parser.add_argument( + 'output', type=str, help='Output file.') +parser.add_argument( + '--path', required=False, type=str, default=None, + help='Path to moc binary.') -subprocess.check_call(["moc", sys.argv[1], "-o", sys.argv[2]]) +args = parser.parse_args() + +if args.path is None: + subprocess.check_call(["moc", args.input, "-o", args.output]) +else: + subprocess.check_call([args.path + "/moc", args.input, "-o", args.output])