xref: /qemu/qga/meson.build (revision 78f314cf)
1if not have_ga
2  if get_option('guest_agent_msi').enabled()
3    error('Guest agent MSI requested, but the guest agent is not being built')
4  endif
5  have_qga_vss = false
6  subdir_done()
7endif
8
9have_qga_vss = get_option('qga_vss') \
10  .require(targetos == 'windows',
11           error_message: 'VSS support requires Windows') \
12  .require(link_language == 'cpp',
13           error_message: 'VSS support requires a C++ compiler') \
14  .require(have_vss, error_message: '''VSS support requires VSS headers.
15    If your Visual Studio installation doesn't have the VSS headers,
16    Please download and install Microsoft VSS SDK:
17    http://www.microsoft.com/en-us/download/details.aspx?id=23490
18    On POSIX-systems, MinGW should provide headers in >=10.0 releases.
19    you can extract the SDK headers by:
20    $ scripts/extract-vsssdk-headers setup.exe
21    The headers are extracted in the directory 'inc/win2003'.
22    Then run configure with: --extra-cxxflags="-isystem /path/to/vss/inc/win2003"''') \
23  .require(midl.found() or widl.found(),
24           error_message: 'VSS support requires midl or widl') \
25  .require(not get_option('prefer_static'),
26           error_message: 'VSS support requires dynamic linking with GLib') \
27  .allowed()
28
29all_qga = []
30
31qga_qapi_outputs = [
32  'qga-qapi-commands.c',
33  'qga-qapi-commands.h',
34  'qga-qapi-emit-events.c',
35  'qga-qapi-emit-events.h',
36  'qga-qapi-events.c',
37  'qga-qapi-events.h',
38  'qga-qapi-init-commands.c',
39  'qga-qapi-init-commands.h',
40  'qga-qapi-introspect.c',
41  'qga-qapi-introspect.h',
42  'qga-qapi-types.c',
43  'qga-qapi-types.h',
44  'qga-qapi-visit.c',
45  'qga-qapi-visit.h',
46]
47
48# Problem: to generate trace events, we'd have to add the .trace-events
49# file to qapi_trace_events like we do in qapi/meson.build.  Since
50# qapi_trace_events is used by trace/meson.build, we'd have to move
51# subdir('qga') above subdir('trace') in the top-level meson.build.
52# Can't, because it would break the dependency of qga on qemuutil (which
53# depends on trace_ss).  Not worth solving now; simply suppress trace
54# event generation instead.
55qga_qapi_files = custom_target('QGA QAPI files',
56                               output: qga_qapi_outputs,
57                               input: 'qapi-schema.json',
58                               command: [ qapi_gen, '-o', 'qga', '-p', 'qga-', '@INPUT0@',
59                                          '--suppress-tracing' ],
60                               depend_files: qapi_gen_depends)
61
62qga_ss = ss.source_set()
63qga_ss.add(qga_qapi_files.to_list())
64qga_ss.add(files(
65  'commands.c',
66  'guest-agent-command-state.c',
67  'main.c',
68  'cutils.c',
69))
70qga_ss.add(when: 'CONFIG_POSIX', if_true: files(
71  'channel-posix.c',
72  'commands-posix.c',
73  'commands-posix-ssh.c',
74))
75qga_ss.add(when: 'CONFIG_LINUX', if_true: files(
76  'commands-linux.c',
77))
78qga_ss.add(when: 'CONFIG_BSD', if_true: files(
79  'commands-bsd.c',
80))
81qga_ss.add(when: 'CONFIG_WIN32', if_true: files(
82  'channel-win32.c',
83  'commands-win32.c',
84  'service-win32.c',
85  'vss-win32.c'
86))
87
88qga_ss = qga_ss.apply(config_host, strict: false)
89
90gen_tlb = []
91qga_libs = []
92if targetos == 'windows'
93  qga_libs += ['-lws2_32', '-lwinmm', '-lpowrprof', '-lwtsapi32', '-lwininet', '-liphlpapi', '-lnetapi32',
94               '-lsetupapi', '-lcfgmgr32']
95  if have_qga_vss
96    qga_libs += ['-lole32', '-loleaut32', '-lshlwapi', '-lstdc++', '-Wl,--enable-stdcall-fixup']
97    subdir('vss-win32')
98  endif
99endif
100
101qga_objs = []
102if targetos == 'windows'
103  windmc = find_program('windmc', required: true)
104  windres = find_program('windres', required: true)
105
106  msgrc = custom_target('messages-win32.rc',
107                        input: 'messages-win32.mc',
108                        output: ['messages-win32.rc', 'MSG00409.bin', 'messages-win32.h'],
109                        command: [windmc, '-h', '@OUTDIR@', '-r', '@OUTDIR@', '@INPUT@'])
110  msgobj = custom_target('messages-win32.o',
111                         input: msgrc[0],
112                         output: 'messages-win32.o',
113                         command: [windres, '-I', '@OUTDIR@', '-o', '@OUTPUT@', '@INPUT@'])
114
115  qga_objs = [msgobj]
116endif
117
118qga = executable('qemu-ga', qga_ss.sources() + qga_objs,
119                 link_args: qga_libs,
120                 dependencies: [qemuutil, libudev],
121                 install: true)
122all_qga += qga
123
124if targetos == 'windows'
125  qemu_ga_msi_arch = {
126    'x86': ['-D', 'Arch=32'],
127    'x86_64': ['-a', 'x64', '-D', 'Arch=64']
128  }
129  wixl = not_found
130  if cpu in qemu_ga_msi_arch
131    wixl = find_program('wixl', required: get_option('guest_agent_msi'))
132  elif get_option('guest_agent_msi').enabled()
133    error('CPU not supported for building guest agent installation package')
134  endif
135
136  if wixl.found()
137    deps = [gen_tlb, qga]
138    qemu_ga_msi_vss = []
139    if have_qga_vss
140      qemu_ga_msi_vss = ['-D', 'InstallVss']
141      deps += qga_vss
142    endif
143    if glib.version() < '2.73.2'
144      libpcre = 'libpcre1'
145    else
146      libpcre = 'libpcre2'
147    endif
148    qga_msi = custom_target('QGA MSI',
149                            input: files('installer/qemu-ga.wxs'),
150                            output: 'qemu-ga-@0@.msi'.format(host_arch),
151                            depends: deps,
152                            command: [
153                              wixl, '-o', '@OUTPUT0@', '@INPUT0@',
154                              qemu_ga_msi_arch[cpu],
155                              qemu_ga_msi_vss,
156                              '-D', 'BUILD_DIR=' + meson.project_build_root(),
157                              '-D', 'BIN_DIR=' + glib_pc.get_variable('bindir'),
158                              '-D', 'QEMU_GA_VERSION=' + config_host['QEMU_GA_VERSION'],
159                              '-D', 'QEMU_GA_MANUFACTURER=' + config_host['QEMU_GA_MANUFACTURER'],
160                              '-D', 'QEMU_GA_DISTRO=' + config_host['QEMU_GA_DISTRO'],
161                              '-D', 'LIBPCRE=' + libpcre,
162                            ])
163    all_qga += [qga_msi]
164    alias_target('msi', qga_msi)
165  endif
166else
167  if get_option('guest_agent_msi').enabled()
168    error('MSI guest agent package is available only for MinGW Windows cross-compilation')
169  endif
170  install_emptydir(get_option('localstatedir') / 'run')
171endif
172
173alias_target('qemu-ga', all_qga)
174
175test_env = environment()
176test_env.set('G_TEST_SRCDIR', meson.current_source_dir())
177test_env.set('G_TEST_BUILDDIR', meson.current_build_dir())
178
179# disable qga-ssh-test for now. glib's G_TEST_OPTION_ISOLATE_DIRS triggers
180# the leak detector in build-oss-fuzz Gitlab CI test. we should re-enable
181# this when an alternative is implemented or when the underlying glib
182# issue is identified/fix
183#if 'CONFIG_POSIX' in config_host
184if false
185  srcs = [files('commands-posix-ssh.c')]
186  i = 0
187  foreach output: qga_qapi_outputs
188    if output.startswith('qga-qapi-types') or output.startswith('qga-qapi-visit')
189      srcs += qga_qapi_files[i]
190    endif
191    i = i + 1
192  endforeach
193  qga_ssh_test = executable('qga-ssh-test', srcs,
194                            dependencies: [qemuutil],
195                            c_args: ['-DQGA_BUILD_UNIT_TEST'])
196
197  test('qga-ssh-test',
198       qga_ssh_test,
199       env: test_env,
200       suite: ['unit', 'qga'])
201endif
202