meson.build 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. project(
  2. 'openMSX', 'cpp',
  3. version : '0.15.0',
  4. license : 'GPL2',
  5. default_options : ['warning_level=3', 'cpp_std=c++17'],
  6. meson_version: '>=0.50.0'
  7. )
  8. subdir('src')
  9. # Compile Flags
  10. # =============
  11. compiler = meson.get_compiler('cpp')
  12. if compiler.get_argument_syntax() == 'gcc'
  13. # We support GCC and Clang.
  14. # Additional warnings:
  15. add_project_arguments('-Wundef', language : 'cpp')
  16. add_project_arguments('-Wshadow', language : 'cpp')
  17. add_project_arguments('-Wunused-macros', language : 'cpp')
  18. add_project_arguments('-Wdouble-promotion', language : 'cpp')
  19. add_project_arguments('-Wmissing-declarations', language : 'cpp')
  20. add_project_arguments('-Wold-style-cast', language : 'cpp')
  21. add_project_arguments('-Wzero-as-null-pointer-constant', language : 'cpp')
  22. # Disable warnings that cause too many false positives:
  23. add_project_arguments('-Wno-pedantic', language : 'cpp')
  24. add_project_arguments('-Wno-invalid-offsetof', language : 'cpp')
  25. # Hardware descriptions can contain constants that are not used in the code
  26. # but still useful as documentation.
  27. # The flag exists for both GCC and Clang, but GCC doesn't enable it via -Wall.
  28. # We'll disable it for both, just in case GCC auto-enables it in the future.
  29. add_project_arguments('-Wno-unused-const-variable', language : 'cpp')
  30. endif
  31. # Dependencies
  32. # ============
  33. dep_sdl2 = dependency('SDL2')
  34. dep_sdl2_ttf = dependency('SDL2_ttf')
  35. dep_png = dependency('libpng')
  36. dep_tcl = dependency('tcl', version : '>=8.6.0')
  37. dep_threads = dependency('threads')
  38. dep_gl = dependency('GL', required : get_option('glrenderer'))
  39. dep_glew = dependency('glew', required : get_option('glrenderer'))
  40. dep_ogg = dependency('ogg', required : get_option('laserdisc'))
  41. dep_theora = dependency('theoradec', required : get_option('laserdisc'))
  42. dep_vorbis = dependency('vorbis', required : get_option('laserdisc'))
  43. if host_machine.system() == 'linux'
  44. dep_alsa = dependency('alsa', required : get_option('alsamidi'))
  45. else
  46. dep_alsa = dependency('', required : false)
  47. endif
  48. # Components
  49. # ==========
  50. components = {
  51. 'CORE':
  52. true,
  53. 'GL':
  54. not get_option('glrenderer').disabled()
  55. and dep_gl.found() and dep_glew.found(),
  56. 'LASERDISC':
  57. not get_option('laserdisc').disabled()
  58. and dep_ogg.found() and dep_theora.found() and dep_vorbis.found(),
  59. 'ALSAMIDI':
  60. not get_option('alsamidi').disabled()
  61. and dep_alsa.found(),
  62. }
  63. # TODO: Subset the sources.
  64. conf_components = configuration_data()
  65. enabled_components = []
  66. foreach name, enabled : components
  67. conf_components.set10('COMPONENT_' + name, enabled)
  68. if enabled
  69. enabled_components += name
  70. endif
  71. endforeach
  72. conf_components.set(
  73. 'BUILD_COMPONENTS', '"' + ' '.join(enabled_components) + '"'
  74. )
  75. hdr_components = configure_file(
  76. output : 'components.hh',
  77. configuration : conf_components
  78. )
  79. # System Functions
  80. # ================
  81. conf_systemfuncs = configuration_data()
  82. conf_systemfuncs.set10(
  83. 'HAVE_FTRUNCATE',
  84. compiler.has_function('ftruncate', prefix : '#include <unistd.h>')
  85. )
  86. if host_machine.system() in ['darwin', 'openbsd']
  87. mmap_prefix = '\n'.join([
  88. '#include <sys/types.h>',
  89. '#include <sys/mman.h>'
  90. ])
  91. else
  92. mmap_prefix = '#include <sys/mman.h>'
  93. endif
  94. conf_systemfuncs.set10(
  95. 'HAVE_MMAP',
  96. compiler.has_function('mmap', prefix : mmap_prefix)
  97. )
  98. conf_systemfuncs.set10(
  99. 'HAVE_NFTW',
  100. compiler.has_function('nftw', prefix : '#include <ftw.h>')
  101. )
  102. conf_systemfuncs.set10(
  103. 'HAVE_POSIX_MEMALIGN',
  104. compiler.has_function('posix_memalign', prefix : '#include <stdlib.h>')
  105. )
  106. hdr_systemfuncs = configure_file(
  107. output : 'systemfuncs.hh',
  108. configuration : conf_systemfuncs
  109. )
  110. # Other Generated Headers
  111. # =======================
  112. prog_python = import('python').find_installation('python3')
  113. hdr_version = custom_target(
  114. 'version header',
  115. output : 'Version.ii',
  116. input : 'build/version2code.py',
  117. command : [prog_python, '@INPUT@', '@OUTPUT@'],
  118. build_always_stale : true,
  119. )
  120. abs_datadir = get_option('prefix') / get_option('datadir') / 'openmsx'
  121. hdr_config = custom_target(
  122. 'build info header',
  123. output : 'build-info.hh',
  124. input : 'build/buildinfo2code.py',
  125. command : [
  126. prog_python, '@INPUT@', '@OUTPUT@',
  127. host_machine.system(),
  128. host_machine.cpu_family(), # TODO: is cpu() more suitable?
  129. 'devel', # OPENMSX_FLAVOUR
  130. abs_datadir
  131. ],
  132. )
  133. # Targets
  134. # =======
  135. main_exec = executable(
  136. 'openmsx',
  137. main_sources, sources,
  138. hdr_version, hdr_config, hdr_components, hdr_systemfuncs,
  139. install : true,
  140. implicit_include_directories : false,
  141. include_directories: incdirs,
  142. dependencies : [
  143. dep_alsa, dep_gl, dep_glew, dep_ogg, dep_png, dep_sdl2, dep_sdl2_ttf,
  144. dep_tcl, dep_theora, dep_threads, dep_vorbis
  145. ],
  146. )
  147. objects = main_exec.extract_objects(sources)
  148. test_exec = executable(
  149. 'unittest',
  150. test_sources,
  151. hdr_version, hdr_config, hdr_components, hdr_systemfuncs,
  152. objects : objects,
  153. build_by_default : false,
  154. install : false,
  155. implicit_include_directories : false,
  156. include_directories: [incdirs, 'Contrib/catch2'],
  157. dependencies : [
  158. dep_alsa, dep_gl, dep_glew, dep_ogg, dep_png, dep_sdl2, dep_sdl2_ttf,
  159. dep_tcl, dep_theora, dep_threads, dep_vorbis
  160. ],
  161. )
  162. test('combined unit test', test_exec)