meson.build 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. project(
  2. 'gamemode',
  3. 'c',
  4. default_options : ['c_std=c11', 'warning_level=3'],
  5. version: '1.7',
  6. license: 'BSD',
  7. )
  8. am_cflags = [
  9. '-fstack-protector',
  10. '-Wstrict-prototypes',
  11. '-Wundef',
  12. '-fno-common',
  13. '-Werror-implicit-function-declaration',
  14. '-Wformat-security',
  15. '-Werror=format-security',
  16. '-Wconversion',
  17. '-Wunreachable-code',
  18. ]
  19. # Add our main flags
  20. add_global_arguments(am_cflags, language: 'c')
  21. cc = meson.get_compiler('c')
  22. # additional compiler warnings, if supported
  23. test_args = [
  24. '-Waggregate-return',
  25. '-Wunused',
  26. '-Warray-bounds',
  27. '-Wcast-align',
  28. '-Wclobbered',
  29. '-Wempty-body',
  30. '-Wformat=2',
  31. '-Wformat-nonliteral',
  32. '-Wformat-signedness',
  33. '-Wignored-qualifiers',
  34. '-Wimplicit-function-declaration',
  35. '-Winit-self',
  36. '-Wmissing-format-attribute',
  37. '-Wmissing-include-dirs',
  38. '-Wmissing-noreturn',
  39. '-Wmissing-parameter-type',
  40. '-Wnested-externs',
  41. '-Wno-discarded-qualifiers',
  42. '-Wno-missing-field-initializers',
  43. '-Wno-suggest-attribute=format',
  44. '-Wno-unused-parameter',
  45. '-Wold-style-definition',
  46. '-Woverride-init',
  47. '-Wpointer-arith',
  48. '-Wredundant-decls',
  49. '-Wreturn-type',
  50. '-Wshadow',
  51. '-Wsign-compare',
  52. '-Wstrict-aliasing=3',
  53. '-Wstrict-prototypes',
  54. '-Wstringop-overflow',
  55. '-Wstringop-truncation',
  56. '-Wtype-limits',
  57. '-Wundef',
  58. '-Wuninitialized',
  59. '-Wunused-but-set-variable',
  60. '-Wwrite-strings',
  61. ]
  62. foreach arg: test_args
  63. if cc.has_argument(arg)
  64. add_global_arguments(arg, language : 'c')
  65. endif
  66. endforeach
  67. path_prefix = get_option('prefix')
  68. path_bindir = join_paths(path_prefix, get_option('bindir'))
  69. path_datadir = join_paths(path_prefix, get_option('datadir'))
  70. path_includedir = join_paths(path_prefix, get_option('includedir'))
  71. path_libdir = join_paths(path_prefix, get_option('libdir'))
  72. path_libexecdir = join_paths(path_prefix, get_option('libexecdir'))
  73. path_mandir = join_paths(path_prefix, get_option('mandir'))
  74. path_metainfo = join_paths(path_datadir, 'metainfo')
  75. path_sysconfdir = join_paths(path_datadir, 'gamemode')
  76. # Find systemd / elogind via pkgconfig
  77. sd_bus_provider = get_option('with-sd-bus-provider')
  78. sd_bus_args = []
  79. sd_bus_dep = []
  80. if sd_bus_provider == 'systemd'
  81. sd_bus_dep = dependency('libsystemd')
  82. elif sd_bus_provider == 'elogind'
  83. sd_bus_args += ['-DUSE_ELOGIND']
  84. sd_bus_dep = dependency('libelogind')
  85. endif
  86. # For the client, libdbus is used
  87. dep_dbus = dependency('dbus-1')
  88. # Allow meson to figure out how the compiler sets up threading
  89. dep_threads = dependency('threads')
  90. # On non glibc systems this might be a stub, i.e. for musl
  91. libdl = cc.find_library('dl', required: false)
  92. with_privileged_group = get_option('with-privileged-group')
  93. # Determine the location for the systemd unit
  94. if sd_bus_provider == 'systemd'
  95. with_systemd_unit = get_option('with-systemd-user-unit')
  96. if with_systemd_unit
  97. path_systemd_unit_dir = get_option('with-systemd-user-unit-dir')
  98. if path_systemd_unit_dir == ''
  99. message('Asking pkg-config for systemd\'s \'systemduserunitdir\' directory')
  100. pkgconfig_systemd = dependency('systemd')
  101. path_systemd_unit_dir = pkgconfig_systemd.get_pkgconfig_variable('systemduserunitdir')
  102. endif
  103. endif
  104. if with_privileged_group != ''
  105. with_systemd_group = get_option('with-systemd-group')
  106. if with_systemd_group
  107. path_systemd_group_dir = get_option('with-systemd-group-dir')
  108. if path_systemd_group_dir == ''
  109. message('Asking pkg-config for systemd\'s \'sysusersdir\' directory')
  110. pkgconfig_systemd = dependency('systemd')
  111. path_systemd_group_dir = pkgconfig_systemd.get_pkgconfig_variable('sysusersdir')
  112. endif
  113. endif
  114. else
  115. with_systemd_group = false
  116. endif
  117. endif
  118. if with_privileged_group != ''
  119. with_pam_renicing = get_option('with-pam-renicing')
  120. if with_pam_renicing
  121. path_pam_limits_dir = get_option('with-pam-limits-dir')
  122. endif
  123. else
  124. with_pam_renicing = false
  125. endif
  126. # Set the dbus path as appropriate.
  127. path_dbus_service_dir = get_option('with-dbus-service-dir')
  128. if path_dbus_service_dir == ''
  129. path_dbus_service_dir = join_paths(path_datadir, 'dbus-1', 'services')
  130. endif
  131. path_polkit_dir = join_paths(path_datadir, 'polkit-1')
  132. path_polkit_action_dir = join_paths(path_polkit_dir, 'actions')
  133. path_polkit_rule_dir = join_paths(path_polkit_dir, 'rules.d')
  134. with_examples = get_option('with-examples')
  135. with_util = get_option('with-util')
  136. # Provide a config.h
  137. pidfd_open = cc.has_function('pidfd_open', args: '-D_GNU_SOURCE')
  138. cdata = configuration_data()
  139. cdata.set_quoted('LIBEXECDIR', path_libexecdir)
  140. cdata.set_quoted('SYSCONFDIR', path_sysconfdir)
  141. cdata.set_quoted('GAMEMODE_VERSION', meson.project_version())
  142. cdata.set10('HAVE_FN_PIDFD_OPEN', pidfd_open)
  143. config_h = configure_file(
  144. configuration: cdata,
  145. output: 'build-config.h',
  146. )
  147. config_h_dir = include_directories('.')
  148. # common lib is always required
  149. subdir('common')
  150. # Library is always required
  151. subdir('lib')
  152. # Utilities are always required except when having both 64 and 32 bit versions
  153. # of libgamemode installed
  154. if with_util == true
  155. subdir('util')
  156. endif
  157. # The daemon can be disabled if necessary, allowing multilib builds of the
  158. # main library
  159. if sd_bus_provider != 'no-daemon'
  160. # inih currently only needed by the daemon
  161. inih_dependency = dependency(
  162. 'inih',
  163. fallback : ['inih', 'inih_dep']
  164. )
  165. subdir('daemon')
  166. # All installed data is currently daemon specific
  167. subdir('data')
  168. endif
  169. # Optionally allow building of examples
  170. if with_examples == true
  171. subdir('example')
  172. endif
  173. report = [
  174. ' Build configuration:',
  175. ' ====================',
  176. '',
  177. ' prefix: @0@'.format(path_prefix),
  178. ' bindir: @0@'.format(path_bindir),
  179. ' datadir: @0@'.format(path_datadir),
  180. ' libdir: @0@'.format(path_libdir),
  181. ' libexecdir: @0@'.format(path_libexecdir),
  182. ' includedir: @0@'.format(path_includedir),
  183. ]
  184. if with_pam_renicing
  185. report += [
  186. ' PAM limits.d directory: @0@'.format(path_pam_limits_dir),
  187. ]
  188. endif
  189. if sd_bus_provider == 'systemd'
  190. if with_systemd_unit
  191. report += [
  192. ' systemd user unit directory: @0@'.format(path_systemd_unit_dir),
  193. ]
  194. endif
  195. if with_systemd_group
  196. report += [
  197. ' systemd group directory: @0@'.format(path_systemd_group_dir),
  198. ]
  199. endif
  200. endif
  201. report += [
  202. ' D-BUS service directory: @0@'.format(path_dbus_service_dir),
  203. ]
  204. report += [
  205. ' PolKit Action Directory: @0@'.format(path_polkit_action_dir),
  206. '',
  207. ' Options:',
  208. ' ========',
  209. '',
  210. ' sd-bus provier: @0@'.format(sd_bus_provider),
  211. ' examples: @0@'.format(with_examples),
  212. ' util: @0@'.format(with_util),
  213. ]
  214. # Output some stuff to validate the build config
  215. message('\n\n\n' + '\n'.join(report) + '\n\n')