xref: /openbmc/qemu/qga/meson.build (revision d5a8f0b200c41fe405f48c5d672c1338beab8d4c)
120cf5cb4SPaolo Bonziniif not have_ga
220cf5cb4SPaolo Bonzini  if get_option('guest_agent_msi').enabled()
320cf5cb4SPaolo Bonzini    error('Guest agent MSI requested, but the guest agent is not being built')
420cf5cb4SPaolo Bonzini  endif
58821a389SMarc-André Lureau  have_qga_vss = false
620cf5cb4SPaolo Bonzini  subdir_done()
720cf5cb4SPaolo Bonziniendif
820cf5cb4SPaolo Bonzini
98821a389SMarc-André Lureauhave_qga_vss = get_option('qga_vss') \
10d0cda6f4SPaolo Bonzini  .require(host_os == 'windows',
118821a389SMarc-André Lureau           error_message: 'VSS support requires Windows') \
12785abf0dSThomas Huth  .require('cpp' in all_languages,
138821a389SMarc-André Lureau           error_message: 'VSS support requires a C++ compiler') \
148821a389SMarc-André Lureau  .require(have_vss, error_message: '''VSS support requires VSS headers.
158821a389SMarc-André Lureau    If your Visual Studio installation doesn't have the VSS headers,
168821a389SMarc-André Lureau    Please download and install Microsoft VSS SDK:
178821a389SMarc-André Lureau    http://www.microsoft.com/en-us/download/details.aspx?id=23490
18b770f6ceSMarc-André Lureau    On POSIX-systems, MinGW should provide headers in >=10.0 releases.
198821a389SMarc-André Lureau    you can extract the SDK headers by:
208821a389SMarc-André Lureau    $ scripts/extract-vsssdk-headers setup.exe
218821a389SMarc-André Lureau    The headers are extracted in the directory 'inc/win2003'.
228821a389SMarc-André Lureau    Then run configure with: --extra-cxxflags="-isystem /path/to/vss/inc/win2003"''') \
2323011f44SMarc-André Lureau  .require(midl.found() or widl.found(),
2423011f44SMarc-André Lureau           error_message: 'VSS support requires midl or widl') \
25a0cbd2e8SPaolo Bonzini  .require(not get_option('prefer_static'),
26e23460ceSMarc-André Lureau           error_message: 'VSS support requires dynamic linking with GLib') \
278821a389SMarc-André Lureau  .allowed()
288821a389SMarc-André Lureau
2987263685SPaolo Bonziniall_qga = []
3087263685SPaolo Bonzini
31f15bff25SPaolo Bonziniqga_qapi_outputs = [
32f15bff25SPaolo Bonzini  'qga-qapi-commands.c',
33f15bff25SPaolo Bonzini  'qga-qapi-commands.h',
34f15bff25SPaolo Bonzini  'qga-qapi-emit-events.c',
35f15bff25SPaolo Bonzini  'qga-qapi-emit-events.h',
36f15bff25SPaolo Bonzini  'qga-qapi-events.c',
37f15bff25SPaolo Bonzini  'qga-qapi-events.h',
38f15bff25SPaolo Bonzini  'qga-qapi-init-commands.c',
39f15bff25SPaolo Bonzini  'qga-qapi-init-commands.h',
40f15bff25SPaolo Bonzini  'qga-qapi-introspect.c',
41f15bff25SPaolo Bonzini  'qga-qapi-introspect.h',
42f15bff25SPaolo Bonzini  'qga-qapi-types.c',
43f15bff25SPaolo Bonzini  'qga-qapi-types.h',
44f15bff25SPaolo Bonzini  'qga-qapi-visit.c',
45f15bff25SPaolo Bonzini  'qga-qapi-visit.h',
46f15bff25SPaolo Bonzini]
47f15bff25SPaolo Bonzini
48378dfa48SVladimir Sementsov-Ogievskiy# Problem: to generate trace events, we'd have to add the .trace-events
49378dfa48SVladimir Sementsov-Ogievskiy# file to qapi_trace_events like we do in qapi/meson.build.  Since
50378dfa48SVladimir Sementsov-Ogievskiy# qapi_trace_events is used by trace/meson.build, we'd have to move
51378dfa48SVladimir Sementsov-Ogievskiy# subdir('qga') above subdir('trace') in the top-level meson.build.
52378dfa48SVladimir Sementsov-Ogievskiy# Can't, because it would break the dependency of qga on qemuutil (which
53378dfa48SVladimir Sementsov-Ogievskiy# depends on trace_ss).  Not worth solving now; simply suppress trace
54378dfa48SVladimir Sementsov-Ogievskiy# event generation instead.
55f15bff25SPaolo Bonziniqga_qapi_files = custom_target('QGA QAPI files',
56db16115fSPeter Maydell                               output: qga_qapi_outputs,
57f15bff25SPaolo Bonzini                               input: 'qapi-schema.json',
58761a1a48SVladimir Sementsov-Ogievskiy                               command: [ qapi_gen, '-o', 'qga', '-p', 'qga-', '@INPUT0@',
59761a1a48SVladimir Sementsov-Ogievskiy                                          '--suppress-tracing' ],
60f15bff25SPaolo Bonzini                               depend_files: qapi_gen_depends)
61acfdaac5SPaolo Bonzini
62f15bff25SPaolo Bonziniqga_ss = ss.source_set()
632a127f96SMarc-André Lureauqga_ss.add(qga_qapi_files.to_list())
64f15bff25SPaolo Bonziniqga_ss.add(files(
65f15bff25SPaolo Bonzini  'commands.c',
66f15bff25SPaolo Bonzini  'guest-agent-command-state.c',
67f15bff25SPaolo Bonzini  'main.c',
680edbfbe3SMarc-André Lureau  'cutils.c',
691cc99327Saidaleuc  'commands-common-ssh.c'
70f15bff25SPaolo Bonzini))
71d0cda6f4SPaolo Bonziniif host_os == 'windows'
72dc495494SPaolo Bonzini  qga_ss.add(files(
73dc495494SPaolo Bonzini    'channel-win32.c',
74dc495494SPaolo Bonzini    'commands-win32.c',
75dc495494SPaolo Bonzini    'service-win32.c',
76*6b9296baSaidaleuc    'vss-win32.c',
77*6b9296baSaidaleuc    'commands-windows-ssh.c'
78dc495494SPaolo Bonzini  ))
79dc495494SPaolo Bonzinielse
80dc495494SPaolo Bonzini  qga_ss.add(files(
81f15bff25SPaolo Bonzini    'channel-posix.c',
828d769ec7SMarc-André Lureau    'commands-posix.c',
838d769ec7SMarc-André Lureau    'commands-posix-ssh.c',
848d769ec7SMarc-André Lureau  ))
85d0cda6f4SPaolo Bonzini  if host_os == 'linux'
8653e8868dSPaolo Bonzini    qga_ss.add(files('commands-linux.c'))
87d0cda6f4SPaolo Bonzini  elif host_os in bsd_oses
8853e8868dSPaolo Bonzini    qga_ss.add(files('commands-bsd.c'))
8953e8868dSPaolo Bonzini  endif
90dc495494SPaolo Bonziniendif
91f15bff25SPaolo Bonzini
921220f581SPaolo Bonziniqga_ss = qga_ss.apply({})
93f15bff25SPaolo Bonzini
94328ec32dSMarc-André Lureaugen_tlb = []
9587263685SPaolo Bonziniqga_libs = []
96d0cda6f4SPaolo Bonziniif host_os == 'windows'
973015321dSMarc-André Lureau  qga_libs += ['-lws2_32', '-lwinmm', '-lpowrprof', '-lwtsapi32', '-lwininet', '-liphlpapi', '-lnetapi32',
98*6b9296baSaidaleuc               '-lsetupapi', '-lcfgmgr32', '-luserenv']
998821a389SMarc-André Lureau  if have_qga_vss
10087263685SPaolo Bonzini    qga_libs += ['-lole32', '-loleaut32', '-lshlwapi', '-lstdc++', '-Wl,--enable-stdcall-fixup']
10187263685SPaolo Bonzini    subdir('vss-win32')
10287263685SPaolo Bonzini  endif
103328ec32dSMarc-André Lureauendif
104328ec32dSMarc-André Lureau
105f9f0e617SAndrey Drobyshevqga_objs = []
106d0cda6f4SPaolo Bonziniif host_os == 'windows'
107f9f0e617SAndrey Drobyshev  windmc = find_program('windmc', required: true)
108f9f0e617SAndrey Drobyshev  windres = find_program('windres', required: true)
109f9f0e617SAndrey Drobyshev
110f9f0e617SAndrey Drobyshev  msgrc = custom_target('messages-win32.rc',
111f9f0e617SAndrey Drobyshev                        input: 'messages-win32.mc',
112f9f0e617SAndrey Drobyshev                        output: ['messages-win32.rc', 'MSG00409.bin', 'messages-win32.h'],
113f9f0e617SAndrey Drobyshev                        command: [windmc, '-h', '@OUTDIR@', '-r', '@OUTDIR@', '@INPUT@'])
114f9f0e617SAndrey Drobyshev  msgobj = custom_target('messages-win32.o',
115f9f0e617SAndrey Drobyshev                         input: msgrc[0],
116f9f0e617SAndrey Drobyshev                         output: 'messages-win32.o',
117f9f0e617SAndrey Drobyshev                         command: [windres, '-I', '@OUTDIR@', '-o', '@OUTPUT@', '@INPUT@'])
118f9f0e617SAndrey Drobyshev
119f9f0e617SAndrey Drobyshev  qga_objs = [msgobj]
120f9f0e617SAndrey Drobyshevendif
121f9f0e617SAndrey Drobyshev
122f9f0e617SAndrey Drobyshevqga = executable('qemu-ga', qga_ss.sources() + qga_objs,
12387263685SPaolo Bonzini                 link_args: qga_libs,
12487263685SPaolo Bonzini                 dependencies: [qemuutil, libudev],
12587263685SPaolo Bonzini                 install: true)
12687263685SPaolo Bonziniall_qga += qga
12787263685SPaolo Bonzini
128d0cda6f4SPaolo Bonziniif host_os == 'windows'
129b846ab7cSPaolo Bonzini  qemu_ga_msi_arch = {
130b846ab7cSPaolo Bonzini    'x86': ['-D', 'Arch=32'],
131b846ab7cSPaolo Bonzini    'x86_64': ['-a', 'x64', '-D', 'Arch=64']
132b846ab7cSPaolo Bonzini  }
133b846ab7cSPaolo Bonzini  wixl = not_found
134b846ab7cSPaolo Bonzini  if cpu in qemu_ga_msi_arch
135b846ab7cSPaolo Bonzini    wixl = find_program('wixl', required: get_option('guest_agent_msi'))
136b846ab7cSPaolo Bonzini  elif get_option('guest_agent_msi').enabled()
137b846ab7cSPaolo Bonzini    error('CPU not supported for building guest agent installation package')
138b846ab7cSPaolo Bonzini  endif
139b846ab7cSPaolo Bonzini
140328ec32dSMarc-André Lureau  if wixl.found()
141328ec32dSMarc-André Lureau    deps = [gen_tlb, qga]
142b846ab7cSPaolo Bonzini    qemu_ga_msi_vss = []
1438821a389SMarc-André Lureau    if have_qga_vss
144b846ab7cSPaolo Bonzini      qemu_ga_msi_vss = ['-D', 'InstallVss']
145328ec32dSMarc-André Lureau      deps += qga_vss
146328ec32dSMarc-André Lureau    endif
1477b47b13eSPaolo Bonzini    if glib.version().version_compare('<2.73.2')
1489ca180bcSAndrey Drobyshev      libpcre = 'libpcre1'
1499ca180bcSAndrey Drobyshev    else
1509ca180bcSAndrey Drobyshev      libpcre = 'libpcre2'
1519ca180bcSAndrey Drobyshev    endif
152e20d68aaSPaolo Bonzini    qga_msi_version = get_option('qemu_ga_version') == '' \
1537e5b1979SMarc-André Lureau      ? meson.project_version() \
154e20d68aaSPaolo Bonzini      : get_option('qemu_ga_version')
155328ec32dSMarc-André Lureau    qga_msi = custom_target('QGA MSI',
156328ec32dSMarc-André Lureau                            input: files('installer/qemu-ga.wxs'),
1576bee0960SMarc-André Lureau                            output: 'qemu-ga-@0@.msi'.format(host_arch),
158328ec32dSMarc-André Lureau                            depends: deps,
159328ec32dSMarc-André Lureau                            command: [
160328ec32dSMarc-André Lureau                              wixl, '-o', '@OUTPUT0@', '@INPUT0@',
161b846ab7cSPaolo Bonzini                              qemu_ga_msi_arch[cpu],
162b846ab7cSPaolo Bonzini                              qemu_ga_msi_vss,
163ca5765c8SPaolo Bonzini                              '-D', 'BUILD_DIR=' + meson.project_build_root(),
16491a2e688SPaolo Bonzini                              '-D', 'BIN_DIR=' + glib_pc.get_variable('bindir'),
165e20d68aaSPaolo Bonzini                              '-D', 'QEMU_GA_VERSION=' + qga_msi_version,
166e20d68aaSPaolo Bonzini                              '-D', 'QEMU_GA_MANUFACTURER=' + get_option('qemu_ga_manufacturer'),
167e20d68aaSPaolo Bonzini                              '-D', 'QEMU_GA_DISTRO=' + get_option('qemu_ga_distro'),
1689ca180bcSAndrey Drobyshev                              '-D', 'LIBPCRE=' + libpcre,
169328ec32dSMarc-André Lureau                            ])
170588a19faSPaolo Bonzini    all_qga += [qga_msi]
171328ec32dSMarc-André Lureau    alias_target('msi', qga_msi)
1727272fc72SMarc-André Lureau  endif
1738ab1aabcSMarc-André Lureauelse
174b846ab7cSPaolo Bonzini  if get_option('guest_agent_msi').enabled()
175b846ab7cSPaolo Bonzini    error('MSI guest agent package is available only for MinGW Windows cross-compilation')
176b846ab7cSPaolo Bonzini  endif
1778a29c205SPaolo Bonzini  install_emptydir(get_option('localstatedir') / 'run')
1787272fc72SMarc-André Lureauendif
179588a19faSPaolo Bonzini
180588a19faSPaolo Bonzinialias_target('qemu-ga', all_qga)
1818d769ec7SMarc-André Lureau
1828d769ec7SMarc-André Lureautest_env = environment()
1838d769ec7SMarc-André Lureautest_env.set('G_TEST_SRCDIR', meson.current_source_dir())
1848d769ec7SMarc-André Lureautest_env.set('G_TEST_BUILDDIR', meson.current_build_dir())
1858d769ec7SMarc-André Lureau
18626813f7fSThomas Huth# disable qga-ssh-test with fuzzing: glib's G_TEST_OPTION_ISOLATE_DIRS triggers
1878d769ec7SMarc-André Lureau# the leak detector in build-oss-fuzz Gitlab CI test. we should re-enable
1888d769ec7SMarc-André Lureau# this when an alternative is implemented or when the underlying glib
1898d769ec7SMarc-André Lureau# issue is identified/fix
19026813f7fSThomas Huthif host_os != 'windows' and not get_option('fuzzing')
1911cc99327Saidaleuc  srcs = [files('commands-common-ssh.c', 'commands-posix-ssh.c')]
192cad97c08SMarc-André Lureau  i = 0
193cad97c08SMarc-André Lureau  foreach output: qga_qapi_outputs
194cad97c08SMarc-André Lureau    if output.startswith('qga-qapi-types') or output.startswith('qga-qapi-visit')
195cad97c08SMarc-André Lureau      srcs += qga_qapi_files[i]
196cad97c08SMarc-André Lureau    endif
197cad97c08SMarc-André Lureau    i = i + 1
198cad97c08SMarc-André Lureau  endforeach
199cad97c08SMarc-André Lureau  qga_ssh_test = executable('qga-ssh-test', srcs,
2008d769ec7SMarc-André Lureau                            dependencies: [qemuutil],
2018d769ec7SMarc-André Lureau                            c_args: ['-DQGA_BUILD_UNIT_TEST'])
2028d769ec7SMarc-André Lureau
2038d769ec7SMarc-André Lureau  test('qga-ssh-test',
2048d769ec7SMarc-André Lureau       qga_ssh_test,
2058d769ec7SMarc-André Lureau       env: test_env,
2068d769ec7SMarc-André Lureau       suite: ['unit', 'qga'])
2078d769ec7SMarc-André Lureauendif
208