meson.build 7.2 KB

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