forked from davidc604/qt_moc_generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qt_generator.gni
137 lines (116 loc) · 3.46 KB
/
qt_generator.gni
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#
# qt_generator.gni
# GN include file
#
# Copyright (c) David Chen, 2017
#
# Example usage in GN:
#
# qt_moc_generator("moc_library") {
#
# qt_moc_generator_script = rebase_path("qt/qt_moc_generator.py", ".")
#
# sources = [
# "src/qt_header1.h",
# "src/qt_header2.h",
# ]
# include_dirs = [
# "/usr/include/qt5",
# ]
# moc_out_dir = "qt/moc"
# }
#
import("//webrtc.gni")
template("qt_moc_generator") {
assert(defined(invoker.qt_moc_generator_script), "Need correct path to qt_moc_generator.py")
assert(defined(invoker.moc_sources), "Need sources for gt_moc_generator")
moc_sources = invoker.moc_sources
if (defined(invoker.moc_in_dir)) {
moc_in_dir = invoker.moc_in_dir
foreach(moc_source, moc_sources) {
if (get_path_info(proto_source, "dir") != moc_in_dir) {
has_nested_dirs = true
}
}
} else {
moc_in_dir = get_path_info(moc_sources[0], "dir")
# Sanity check, |moc_in_dir| should be defined to allow sub-directories.
foreach(moc_source, moc_sources) {
assert(get_path_info(moc_source, "dir") == moc_in_dir,
"Please define |moc_sources| to allow nested directories.")
}
}
# Avoid absolute path because of the assumption that |moc_in_dir| is
# relative to the directory of current BUILD.gn file.
moc_in_dir = rebase_path(moc_in_dir, ".")
if (defined(invoker.moc_out_dir)) {
moc_out_dir = invoker.moc_out_dir
} else {
# Absolute path to the directory of current BUILD.gn file excluding "//".
moc_out_dir = rebase_path(".", "//")
if (moc_in_dir != ".") {
moc_out_dir += "/$moc_in_dir"
}
}
# we generate "{name}.moc.cc" from the header files
cc_out_dir = "$target_gen_dir/" + moc_out_dir #root_gen_dir/
rel_cc_out_dir = rebase_path(cc_out_dir, root_build_dir)
headers = rebase_path(moc_sources, moc_in_dir)
mocgens = []
# List output files.
foreach(header, headers) {
header_dir = get_path_info(header, "dir")
header_name = get_path_info(header, "name")
header_path = header_dir + "/" + header_name
mocgens += [
"$cc_out_dir/$header_path.moc.cc",
]
}
# Make sure to include all the include paths to MOC
inc_dirs_args = []
foreach(incdir, invoker.include_dirs) {
inc_dirs_args += [ "--include-path", incdir ]
}
action_name = "${target_name}_gen"
source_set_name = target_name
# Generate moc cc sources.
action(action_name) {
visibility = [ ":$source_set_name" ]
script = invoker.qt_moc_generator_script
sources = moc_sources
outputs = get_path_info(mocgens, "abspath")
args = headers
args += [
"--header-in-dir",
rebase_path(moc_in_dir),
"--cc-out-dir",
rel_cc_out_dir,
]
args += inc_dirs_args
}
# Build generated moc sources as source_set.
target(invoker.target_type, target_name) {
forward_variables_from(invoker, "*")
sources = get_target_outputs(":$action_name")
if (defined(invoker.cflags)) {
cflags += invoker.cflags
}
if (defined(invoker.ldflags)) {
cflags += invoker.ldflags
}
if (defined(invoker.include_dirs)) {
include_dirs += invoker.include_dirs
}
if (defined(invoker.includes)) {
include_dirs += invoker.includes
}
deps = [
":$action_name",
]
# This will link any libraries in the deps (the use of invoker.deps in the
# action won't link it).
if (defined(invoker.deps)) {
deps += invoker.deps
}
}
}