Integration of generation of Qt Meta-Object code using the Meta-Object Compiler (moc) in GN build system.
This repo contains a GN defintion file (qt_generator.gni
)and the generation python script (qt_moc_generator.py
).
- GN meta-build system (more information)
- Qt Meta-Object Compiler (info)
Import the .gni file in the BUILD.gn
where you need to generate Qt meta-object sources.
import("//project-root/{dir}/qt_generator.gni")
Create a built source_set, for example:
qt_moc_generator("qt_sources") {
qt_moc_generator_path = rebase_path("qt/qt_moc_generator.py", ".")
sources = [
"src/qt_header1.h",
"src/qt_header2.h",
]
include_dirs = [
"/usr/include/qt5",
"/usr/include/qt5/QtCore",
]
moc_out_dir = "qt/generated_moc"
}
Then in your target library or executable, add the generated as part of the dependencies,
executable("awesome_exec") {
sources = [
"src/source1.cc",
"src/source2.cc",
"src/source3.cc",
"src/main.cc"
]
deps = [
"//third_party/deps1",
"//third_party/deps2",
":qt_sources"
]
cflags = [
"-Wno-error"
]
libs = [
"Qt5Core",
]
}
Afterwards, simply run gn gen <folder>
and build, the scripts will automatically generate the required meta-object sources and object files and include in your project/library.