meson.build 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. project('cppgir',
  2. ['c', 'cpp'],
  3. meson_version : '>= 0.61',
  4. version : '2.0.0',
  5. default_options : [
  6. 'warning_level=2',
  7. 'cpp_std=c++17'
  8. ]
  9. )
  10. message('meson system only considers generator and includes',
  11. '\n\tsee CMake build for full build including examples')
  12. compiler = meson.get_compiler('cpp')
  13. foreach arg : ['-Wnon-virtual-dtor']
  14. if compiler.has_argument(arg)
  15. add_project_arguments(arg, language: 'cpp')
  16. endif
  17. endforeach
  18. # generator binary
  19. # dependencies
  20. boost_dep = dependency('boost', version : '>=1.58', required : true)
  21. # fmtlib
  22. fmtlib_dep = compiler.find_library('fmt', has_headers : ['fmt/format.h'])
  23. # check C++20 format
  24. has_format = compiler.compiles(files('cmake/cpp20_format.cpp'),
  25. args : ['-std=c++20'],
  26. name : 'std::format check'
  27. )
  28. # check and decide on which fmt to use
  29. use_fmtlib = 'none'
  30. build_fmt = get_option('build_fmt')
  31. if build_fmt == 'auto'
  32. if fmtlib_dep.found()
  33. use_fmtlib = '1'
  34. elif has_format
  35. use_fmtlib = '0'
  36. endif
  37. elif build_fmt == 'fmtlib' and fmtlib_dep.found()
  38. use_fmtlib = '1'
  39. elif build_fmt == 'stdformat' and has_format
  40. use_fmtlib = '0'
  41. endif
  42. if use_fmtlib == 'none'
  43. error('no format library found')
  44. endif
  45. # required ignore file
  46. fs = import('fs')
  47. gi_ignore_file_dir = 'data'
  48. gi_ignore_file = 'cppgir.ignore'
  49. cppgir_ignore = fs.read('data/cppgir.ignore')
  50. if host_machine.system() == 'windows'
  51. gi_ignore_file_platform = 'cppgir_win.ignore'
  52. cppgir_win_ignore = fs.read('data/cppgir_win.ignore')
  53. cppgir_unix_ignore = ''
  54. else
  55. gi_ignore_file_platform = 'cppgir_unix.ignore'
  56. cppgir_unix_ignore = fs.read('data/cppgir_unix.ignore')
  57. cppgir_win_ignore = ''
  58. endif
  59. gi_install_full_datadir = \
  60. '@0@/@1@'.format(get_option('prefix'), get_option('datadir'))
  61. gi_ignore_file_install_dir = \
  62. '@0@/@1@'.format(gi_install_full_datadir, meson.project_name())
  63. cppgir_sources = [
  64. 'tools/cppgir.cpp',
  65. 'tools/genbase.cpp', 'tools/genbase.hpp',
  66. 'tools/genns.cpp', 'tools/genns.hpp',
  67. 'tools/genutils.cpp', 'tools/genutils.hpp',
  68. 'tools/function.cpp', 'tools/function.hpp',
  69. 'tools/repository.cpp', 'tools/repository.hpp',
  70. 'tools/common.hpp'
  71. ]
  72. cppgir_deps = [boost_dep]
  73. cppgir_overrides = []
  74. cppgir_args = []
  75. # adjust to options and situation
  76. if use_fmtlib.to_int() > 0
  77. cppgir_deps += [fmtlib_dep]
  78. else
  79. cppgir_overrides = ['cpp_std=c++20']
  80. endif
  81. if get_option('build_embed_ignore')
  82. # generate embedded ignore data
  83. conf_data = configuration_data()
  84. conf_data.set('CPPGIR_IGNORE', cppgir_ignore)
  85. conf_data.set('CPPGIR_UNIX_IGNORE', cppgir_unix_ignore)
  86. conf_data.set('CPPGIR_WIN_IGNORE', cppgir_win_ignore)
  87. configure_file(configuration : conf_data,
  88. input : 'tools/ignore.hpp.in', output : 'ignore.hpp')
  89. else
  90. install_data(gi_ignore_file_dir / gi_ignore_file,
  91. gi_ignore_file_dir / gi_ignore_file_platform,
  92. install_dir : gi_ignore_file_install_dir)
  93. cppgir_args += \
  94. [f'-DDEFAULT_IGNORE_FILE=@gi_ignore_file_install_dir@/@gi_ignore_file@:@gi_ignore_file_install_dir@/@gi_ignore_file_platform@']
  95. endif
  96. # gir search path
  97. if host_machine.system() != 'windows'
  98. # add fixed fallback search places
  99. gi_default_girpath = '/usr/@0@:/usr/local/@0@'.format(get_option('datadir'))
  100. cppgir_args += [
  101. f'-DDEFAULT_GIRPATH=@gi_default_girpath@',
  102. f'-DGI_DATA_DIR=@gi_install_full_datadir@/gir-1.0',
  103. '-DGI_DEF_DIR=/usr/share/gir-1.0'
  104. ]
  105. gir_dir = get_option('gir_dir')
  106. if gir_dir != ''
  107. cppgir_args += [f'-DGI_GIR_DIR=@gir_dir@']
  108. endif
  109. endif
  110. if get_option('link_stdfs')
  111. # some older gcc might sometimes (?) need this, even in c++17 mode
  112. # see issue #80
  113. fs_dep = compiler.find_library('stdc++fs')
  114. cppgir_deps += [fs_dep]
  115. endif
  116. cppgir = executable('cppgir',
  117. cppgir_sources,
  118. cpp_args : cppgir_args,
  119. dependencies : cppgir_deps,
  120. install : true,
  121. override_options : cppgir_overrides
  122. )
  123. meson.override_find_program('cppgir', cppgir)
  124. # gi headers
  125. expected_code = '''#include <expected>
  126. auto f() -> std::expected<int, int> { return 2; }
  127. '''
  128. has_expected = compiler.compiles(expected_code, name : 'std::expected check')
  129. pkgconfig = import('pkgconfig')
  130. pkgconfig.generate(name: 'cppgir',
  131. version : meson.project_version(),
  132. subdirs : ['cppgir', 'cppgir' / 'gi', 'cppgir' / 'override'],
  133. description : 'GObject Introspection C++ wrapper generator.'
  134. )
  135. install_subdir('gi', install_dir : 'include' / 'cppgir')
  136. install_subdir('override', install_dir : 'include' / 'cppgir')
  137. inc = include_directories('.', 'gi', 'override')
  138. if not has_expected
  139. expected_lite_include = 'expected-lite' / 'include'
  140. if not fs.exists(expected_lite_include / 'nonstd' / 'expected.hpp')
  141. error('missing submodule expected-lite')
  142. endif
  143. # Add an include option and copy the directory is all we have to do.
  144. # cppgir will automatically switch to `nonstd/expected.hpp` if it exists.
  145. inc = [inc] + include_directories(expected_lite_include)
  146. install_subdir(expected_lite_include / 'nonstd',
  147. install_dir : 'include' / 'cppgir' / 'gi')
  148. endif
  149. cppgir_dep = declare_dependency(include_directories: inc)
  150. meson.override_dependency('cppgir', cppgir_dep)