meson.build 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. ))
  73. else
  74. qga_ss.add(files(
  75. 'channel-posix.c',
  76. 'commands-posix.c',
  77. 'commands-posix-ssh.c',
  78. ))
  79. if host_os == 'linux'
  80. qga_ss.add(files('commands-linux.c'))
  81. elif host_os in bsd_oses
  82. qga_ss.add(files('commands-bsd.c'))
  83. endif
  84. endif
  85. qga_ss = qga_ss.apply({})
  86. gen_tlb = []
  87. qga_libs = []
  88. if host_os == 'windows'
  89. qga_libs += ['-lws2_32', '-lwinmm', '-lpowrprof', '-lwtsapi32', '-lwininet', '-liphlpapi', '-lnetapi32',
  90. '-lsetupapi', '-lcfgmgr32']
  91. if have_qga_vss
  92. qga_libs += ['-lole32', '-loleaut32', '-lshlwapi', '-lstdc++', '-Wl,--enable-stdcall-fixup']
  93. subdir('vss-win32')
  94. endif
  95. endif
  96. qga_objs = []
  97. if host_os == 'windows'
  98. windmc = find_program('windmc', required: true)
  99. windres = find_program('windres', required: true)
  100. msgrc = custom_target('messages-win32.rc',
  101. input: 'messages-win32.mc',
  102. output: ['messages-win32.rc', 'MSG00409.bin', 'messages-win32.h'],
  103. command: [windmc, '-h', '@OUTDIR@', '-r', '@OUTDIR@', '@INPUT@'])
  104. msgobj = custom_target('messages-win32.o',
  105. input: msgrc[0],
  106. output: 'messages-win32.o',
  107. command: [windres, '-I', '@OUTDIR@', '-o', '@OUTPUT@', '@INPUT@'])
  108. qga_objs = [msgobj]
  109. endif
  110. qga = executable('qemu-ga', qga_ss.sources() + qga_objs,
  111. link_args: qga_libs,
  112. dependencies: [qemuutil, libudev],
  113. install: true)
  114. all_qga += qga
  115. if host_os == 'windows'
  116. qemu_ga_msi_arch = {
  117. 'x86': ['-D', 'Arch=32'],
  118. 'x86_64': ['-a', 'x64', '-D', 'Arch=64']
  119. }
  120. wixl = not_found
  121. if cpu in qemu_ga_msi_arch
  122. wixl = find_program('wixl', required: get_option('guest_agent_msi'))
  123. elif get_option('guest_agent_msi').enabled()
  124. error('CPU not supported for building guest agent installation package')
  125. endif
  126. if wixl.found()
  127. deps = [gen_tlb, qga]
  128. qemu_ga_msi_vss = []
  129. if have_qga_vss
  130. qemu_ga_msi_vss = ['-D', 'InstallVss']
  131. deps += qga_vss
  132. endif
  133. if glib.version().version_compare('<2.73.2')
  134. libpcre = 'libpcre1'
  135. else
  136. libpcre = 'libpcre2'
  137. endif
  138. qga_msi_version = get_option('qemu_ga_version') == '' \
  139. ? meson.project_version() \
  140. : get_option('qemu_ga_version')
  141. qga_msi = custom_target('QGA MSI',
  142. input: files('installer/qemu-ga.wxs'),
  143. output: 'qemu-ga-@0@.msi'.format(host_arch),
  144. depends: deps,
  145. command: [
  146. wixl, '-o', '@OUTPUT0@', '@INPUT0@',
  147. qemu_ga_msi_arch[cpu],
  148. qemu_ga_msi_vss,
  149. '-D', 'BUILD_DIR=' + meson.project_build_root(),
  150. '-D', 'BIN_DIR=' + glib_pc.get_variable('bindir'),
  151. '-D', 'QEMU_GA_VERSION=' + qga_msi_version,
  152. '-D', 'QEMU_GA_MANUFACTURER=' + get_option('qemu_ga_manufacturer'),
  153. '-D', 'QEMU_GA_DISTRO=' + get_option('qemu_ga_distro'),
  154. '-D', 'LIBPCRE=' + libpcre,
  155. ])
  156. all_qga += [qga_msi]
  157. alias_target('msi', qga_msi)
  158. endif
  159. else
  160. if get_option('guest_agent_msi').enabled()
  161. error('MSI guest agent package is available only for MinGW Windows cross-compilation')
  162. endif
  163. install_emptydir(get_option('localstatedir') / 'run')
  164. endif
  165. alias_target('qemu-ga', all_qga)
  166. test_env = environment()
  167. test_env.set('G_TEST_SRCDIR', meson.current_source_dir())
  168. test_env.set('G_TEST_BUILDDIR', meson.current_build_dir())
  169. # disable qga-ssh-test with fuzzing: glib's G_TEST_OPTION_ISOLATE_DIRS triggers
  170. # the leak detector in build-oss-fuzz Gitlab CI test. we should re-enable
  171. # this when an alternative is implemented or when the underlying glib
  172. # issue is identified/fix
  173. if host_os != 'windows' and not get_option('fuzzing')
  174. srcs = [files('commands-common-ssh.c', 'commands-posix-ssh.c')]
  175. i = 0
  176. foreach output: qga_qapi_outputs
  177. if output.startswith('qga-qapi-types') or output.startswith('qga-qapi-visit')
  178. srcs += qga_qapi_files[i]
  179. endif
  180. i = i + 1
  181. endforeach
  182. qga_ssh_test = executable('qga-ssh-test', srcs,
  183. dependencies: [qemuutil],
  184. c_args: ['-DQGA_BUILD_UNIT_TEST'])
  185. test('qga-ssh-test',
  186. qga_ssh_test,
  187. env: test_env,
  188. suite: ['unit', 'qga'])
  189. endif