Debian Codegraph @

meson.build

raw
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
11 message('meson system only considers generator and includes',
12 '\n\tsee CMake build for full build including examples')
13
14 compiler = meson.get_compiler('cpp')
15
16 foreach arg : ['-Wnon-virtual-dtor']
17 if compiler.has_argument(arg)
18 add_project_arguments(arg, language: 'cpp')
19 endif
20 endforeach
21
22 # generator binary
23
24 # dependencies
25 boost_dep = dependency('boost', version : '>=1.58', required : true)
26
27 # fmtlib
28 fmtlib_dep = dependency('fmt', required : false)
29 if not fmtlib_dep.found()
30 # fallback for old version without pkg-config
31 fmtlib_dep = compiler.find_library('fmt', has_headers : ['fmt/format.h'], required : false)
32 endif
33 # check C++20 format
34 has_format = compiler.compiles(files('cmake/cpp20_format.cpp'),
35 args : ['-std=c++20'],
36 name : 'std::format check'
37 )
38
39 # check and decide on which fmt to use
40 use_fmtlib = 'none'
41 build_fmt = get_option('build_fmt')
42 if build_fmt == 'auto'
43 if fmtlib_dep.found()
44 use_fmtlib = '1'
45 elif has_format
46 use_fmtlib = '0'
47 endif
48 elif build_fmt == 'fmtlib' and fmtlib_dep.found()
49 use_fmtlib = '1'
50 elif build_fmt == 'stdformat' and has_format
51 use_fmtlib = '0'
52 endif
53 if use_fmtlib == 'none'
54 error('no format library found')
55 endif
56
57 # required ignore file
58 fs = import('fs')
59
60 gi_ignore_file_dir = 'data'
61 gi_ignore_file = 'cppgir.ignore'
62 cppgir_ignore = fs.read('data/cppgir.ignore')
63 if host_machine.system() == 'windows'
64 gi_ignore_file_platform = 'cppgir_win.ignore'
65 cppgir_win_ignore = fs.read('data/cppgir_win.ignore')
66 cppgir_unix_ignore = ''
67 else
68 gi_ignore_file_platform = 'cppgir_unix.ignore'
69 cppgir_unix_ignore = fs.read('data/cppgir_unix.ignore')
70 cppgir_win_ignore = ''
71 endif
72 gi_install_full_datadir = \
73 '@0@/@1@'.format(get_option('prefix'), get_option('datadir'))
74 gi_ignore_file_install_dir = \
75 '@0@/@1@'.format(gi_install_full_datadir, meson.project_name())
76
77 cppgir_sources = [
78 'tools/cppgir.cpp',
79 'tools/genbase.cpp', 'tools/genbase.hpp',
80 'tools/genns.cpp', 'tools/genns.hpp',
81 'tools/genutils.cpp', 'tools/genutils.hpp',
82 'tools/function.cpp', 'tools/function.hpp',
83 'tools/repository.cpp', 'tools/repository.hpp',
84 'tools/common.hpp'
85 ]
86
87 cppgir_deps = [boost_dep]
88 cppgir_overrides = []
89 cppgir_args = []
90
91 # adjust to options and situation
92 if use_fmtlib.to_int() > 0
93 cppgir_deps += [fmtlib_dep]
94 else
95 cppgir_overrides = ['cpp_std=c++20']
96 endif
97
98 if get_option('build_embed_ignore')
99 # generate embedded ignore data
100 conf_data = configuration_data()
101 conf_data.set('CPPGIR_IGNORE', cppgir_ignore)
102 conf_data.set('CPPGIR_UNIX_IGNORE', cppgir_unix_ignore)
103 conf_data.set('CPPGIR_WIN_IGNORE', cppgir_win_ignore)
104 configure_file(configuration : conf_data,
105 input : 'tools/ignore.hpp.in', output : 'ignore.hpp')
106 else
107 install_data(gi_ignore_file_dir / gi_ignore_file,
108 gi_ignore_file_dir / gi_ignore_file_platform,
109 install_dir : gi_ignore_file_install_dir)
110 cppgir_args += \
111 [f'-DDEFAULT_IGNORE_FILE=@gi_ignore_file_install_dir@/@gi_ignore_file@:@gi_ignore_file_install_dir@/@gi_ignore_file_platform@']
112 endif
113
114 # gir search path
115 if host_machine.system() != 'windows'
116 # add fixed fallback search places
117 cppgir_args += [
118 f'-DGI_DATA_DIR=@gi_install_full_datadir@/gir-1.0',
119 ]
120 gir_dir = get_option('gir_dir')
121 if gir_dir != ''
122 cppgir_args += [f'-DGI_GIR_DIR=@gir_dir@']
123 endif
124 gir_default_dirs = get_option('gir_default_dirs')
125 if gir_default_dirs != ''
126 cppgir_args += [f'-DDEFAULT_GIRPATH=@gir_default_dirs@']
127 endif
128 endif
129
130 if get_option('link_stdfs')
131 # some older gcc might sometimes (?) need this, even in c++17 mode
132 # see issue #80
133 fs_dep = compiler.find_library('stdc++fs')
134 cppgir_deps += [fs_dep]
135 endif
136
137 cppgir = executable('cppgir',
138 cppgir_sources,
139 cpp_args : cppgir_args,
140 dependencies : cppgir_deps,
141 install : true,
142 override_options : cppgir_overrides
143 )
144 meson.override_find_program('cppgir', cppgir)
145
146 # gi headers
147 pkgconfig = import('pkgconfig')
148
149 pkgconfig.generate(name: 'cppgir',
150 version : meson.project_version(),
151 subdirs : ['cppgir', 'cppgir' / 'override'],
152 description : 'GObject Introspection C++ wrapper generator.'
153 )
154
155 install_subdir('gi', install_dir : 'include' / 'cppgir')
156 install_subdir('override', install_dir : 'include' / 'cppgir')
157
158 inc = include_directories('.', 'override')
159 if get_option('internal_expected')
160 expected_lite_include = 'expected-lite' / 'include'
161 if not fs.exists(expected_lite_include / 'nonstd' / 'expected.hpp')
162 error('missing submodule expected-lite')
163 endif
164 # Add an include option and copy the directory is all we have to do.
165 # cppgir will automatically switch to `nonstd/expected.hpp` if it exists.
166 inc = [inc] + include_directories(expected_lite_include)
167 install_subdir(expected_lite_include / 'nonstd',
168 install_dir : 'include' / 'cppgir' / 'gi')
169 else
170 message('cppgir headers will require C++23')
171 endif
172
173 cppgir_dep = declare_dependency(include_directories: inc)
174 meson.override_dependency('cppgir', cppgir_dep)
175
176 # manpage
177 ronn = find_program('ronn', native : true, required : false)
178 if not ronn.found()
179 message('ronn manpage processor not found; not building manpage')
180 elif get_option('build_doc')
181 message('building manpage')
182 manpage = 'cppgir.1'
183 custom_target(manpage, command : [ronn, '--roff', '--pipe', '@INPUT@'],
184 capture : true, input : ['docs/cppgir.md'], output : manpage,
185 install : true, install_dir : join_paths(get_option('mandir'), 'man1'))
186 endif
187
188 # documentation, including examples
189 docdir = get_option('datadir') / 'doc' / 'cppgir'
190 install_data('README.md', 'docs/cppgir.md', install_dir : docdir)
191 install_subdir('examples', install_dir : docdir)