1 # This file is part of libsigc++.
3 project('libsigc++', 'cpp',
10 meson_version: '>= 0.55.0', # required for meson.add_dist_script(python3, ...)
11 # and meson.add_install_script(python3, ...)
14 sigcxx_api_version = '2.0'
15 sigcxx_pcname = 'sigc++-' + sigcxx_api_version
17 sigcxx_version_array = meson.project_version().split('.')
18 sigcxx_major_version = sigcxx_version_array[0].to_int()
19 sigcxx_minor_version = sigcxx_version_array[1].to_int()
20 sigcxx_micro_version = sigcxx_version_array[2].to_int()
22 # http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
23 # The relation between libtool's current:revison:age interface versioning
24 # and the .so filename, .so.x.y.z, is
28 # If libtool_soversion is updated as described in libtool's documentation,
29 # x.y.z will usually *not* be equal to meson.project_version().
30 libtool_soversion = [0, 0, 0]
31 sigcxx_libversion = '@0@.@1@.@2@'.format(
32 libtool_soversion[0] - libtool_soversion[2],
35 darwin_versions = [libtool_soversion[0] + 1, '@0@.@1@'.format(libtool_soversion[0] + 1, libtool_soversion[1])]
37 # Use these instead of meson.source_root() and meson.build_root() in subdirectories.
38 # source_root() and build_root() are not useful, if this is a subproject.
39 project_source_root = meson.current_source_dir()
40 project_build_root = meson.current_build_dir()
42 cpp_compiler = meson.get_compiler('cpp')
43 is_msvc = cpp_compiler.get_id() == 'msvc'
44 python3 = import('python').find_installation()
46 python_version = python3.language_version()
47 python_version_req = '>= 3.5'
48 if not python_version.version_compare(python_version_req)
49 error('Requires Python @0@, found @1@.'.format(python_version_req, python_version))
52 # Do we build from a git repository?
53 # Suppose we do if and only if a '.git' directory or file exists.
57 sys.exit(os.path.isdir("@0@") or os.path.isfile("@0@"))
58 '''.format(project_source_root / '.git')
59 is_git_build = run_command(python3, '-c', cmd_py, check: false).returncode() != 0
61 # Are we testing a dist tarball while it's being built?
62 # There ought to be a better way. https://github.com/mesonbuild/meson/issues/6866
63 is_dist_check = project_source_root.contains('dist-unpack') and \
64 project_build_root.contains('dist-build')
67 maintainer_mode_opt = get_option('maintainer-mode')
68 maintainer_mode = maintainer_mode_opt == 'true' or \
69 (maintainer_mode_opt == 'if-git-build' and is_git_build)
71 message('Looks like a tarball is being tested. ' + \
72 'Option "dist-warnings" is used instead of "warnings".')
73 warning_level = get_option('dist-warnings')
75 warning_level = get_option('warnings')
77 build_deprecated_api = get_option('build-deprecated-api')
78 build_documentation_opt = get_option('build-documentation')
79 build_documentation = build_documentation_opt == 'true' or \
80 (build_documentation_opt == 'if-maintainer-mode' and maintainer_mode)
81 build_examples = get_option('build-examples')
82 do_benchmark = get_option('benchmark')
84 # Installation directories are relative to {prefix}.
85 install_prefix = get_option('prefix')
86 install_includedir = get_option('includedir')
87 install_libdir = get_option('libdir')
88 install_datadir = get_option('datadir')
89 install_pkgconfigdir = install_libdir / 'pkgconfig'
92 # sigcxx_build_dep: Dependencies when building the libsigc++ library.
93 # sigcxx_dep (created in sigc++/meson.build):
94 # Dependencies when using the libsigc++ library.
95 sigcxx_build_dep = [] # No dependencies
97 benchmark_dep = dependency('boost', modules: ['system', 'timer'],
98 version: '>=1.20.0', required: do_benchmark)
99 can_benchmark = benchmark_dep.found()
101 # We must have Visual Studio 2015 or later...
102 if is_msvc and cpp_compiler.version().version_compare('<19')
103 error('Visual Studio 2015 or later is required')
106 # Some dependencies are required only in maintainer mode and/or
107 # if documentation shall be built.
108 mm_common_get = find_program('mm-common-get', required: false)
109 if maintainer_mode and not mm_common_get.found()
110 message('Maintainer mode requires the \'mm-common-get\' command. If it is not found,\n' +
111 'install the \'mm-common\' package, version 1.0.0 or higher.')
112 # If meson --wrap-mode != forcefallback, Meson falls back to the mm-common
113 # subproject only if mm-common-get is required.
114 mm_common_get = find_program('mm-common-get', required: true)
116 m4 = find_program('m4', required: maintainer_mode) # For building C++ code
117 doxygen = find_program('doxygen', required: build_documentation)
118 dot = find_program('dot', required: build_documentation) # Used by Doxygen
119 xsltproc = find_program('xsltproc', required: build_documentation)
121 script_dir = project_source_root / 'untracked' / 'build_scripts'
122 doc_reference = script_dir / 'doc-reference.py'
123 dist_changelog = script_dir / 'dist-changelog.py'
124 dist_build_scripts = script_dir / 'dist-build-scripts.py'
125 tutorial_custom_cmd = project_source_root / 'tools' / 'tutorial-custom-cmd.py'
128 # Copy files to untracked/build_scripts and untracked/docs.
129 run_command(mm_common_get, '--force', script_dir,
130 project_source_root / 'untracked' / 'docs',
137 sys.exit(os.path.isfile("@0@"))
138 '''.format(doc_reference)
139 file_exists = run_command(python3, '-c', cmd_py, check: false).returncode() != 0
141 warning('Missing files in untracked/. You may have to enable maintainer-mode.')
145 # Check if perl is required and available.
146 doc_perl_prop = run_command(
147 python3, doc_reference, 'get_script_property',
148 '', # MMDOCTOOLDIR is not used
152 if not (doc_perl_prop.returncode() == 0 and doc_perl_prop.stdout() == 'false')
153 # Perl is required, if documentation shall be built.
154 perl = find_program('perl', required: build_documentation)
157 # Set compiler warnings.
159 if warning_level == 'min'
161 warning_flags = ['/W3']
163 warning_flags = ['-Wall']
165 elif warning_level == 'max' or warning_level == 'fatal'
167 warning_flags = ['/W4']
169 warning_flags = '-pedantic -Wall -Wextra -Wsuggest-override -Wshadow -Wzero-as-null-pointer-constant -Wformat-security'.split()
171 if warning_level == 'fatal'
173 warning_flags += ['/WX']
175 warning_flags += ['-Werror']
180 warning_flags = cpp_compiler.get_supported_arguments(warning_flags)
181 add_project_arguments(warning_flags, language: 'cpp')
183 # MSVC: Ignore warnings that aren't really harmful, but make those
184 # that should not be overlooked stand out.
186 foreach wd : ['/FImsvc_recommended_pragmas.h', '/EHsc', '/wd4267']
187 disabled_warning = cpp_compiler.get_supported_arguments(wd)
188 add_project_arguments(disabled_warning, language: 'cpp')
193 pkg_conf_data = configuration_data()
194 pkg_conf_data.set('prefix', install_prefix)
195 pkg_conf_data.set('exec_prefix', '${prefix}')
196 pkg_conf_data.set('libdir', '${exec_prefix}' / install_libdir)
197 pkg_conf_data.set('datarootdir', '${prefix}' / install_datadir)
198 pkg_conf_data.set('datadir', '${datarootdir}')
199 pkg_conf_data.set('includedir', '${prefix}' / install_includedir)
200 pkg_conf_data.set('top_srcdir', project_source_root)
201 pkg_conf_data.set('PACKAGE_VERSION', meson.project_version())
202 pkg_conf_data.set('SIGCXX_API_VERSION', sigcxx_api_version)
204 if not build_deprecated_api
205 pkg_conf_data.set('SIGCXX_DISABLE_DEPRECATED', true)
207 pkg_conf_data.set('SIGCXX_MAJOR_VERSION', sigcxx_major_version)
208 pkg_conf_data.set('SIGCXX_MINOR_VERSION', sigcxx_minor_version)
209 pkg_conf_data.set('SIGCXX_MICRO_VERSION', sigcxx_micro_version)
210 foreach conf_test : ['gcc_template_specialization_operator_overload',
211 'msvc_template_specialization_operator_overload',
212 'have_sun_reverse_iterator',
213 'pragma_push_pop_macro']
214 if cpp_compiler.compiles(files('tools' / conf_test + '.cc'))
215 pkg_conf_data.set('SIGC_' + conf_test.to_upper(), true)
220 input: 'sigc++.pc.in',
221 output: sigcxx_pcname + '.pc',
222 configuration: pkg_conf_data,
223 install_dir: install_pkgconfigdir,
227 input: 'sigc++-uninstalled.pc.in',
228 output: sigcxx_pcname + '-uninstalled.pc',
229 configuration: pkg_conf_data,
232 install_includeconfigdir = install_libdir / sigcxx_pcname / 'include'
233 sigcxxconfig_h = configure_file(
234 input: 'sigc++config.h.meson',
235 output: 'sigc++config.h',
236 configuration: pkg_conf_data,
237 install_dir: install_includeconfigdir,
240 # add_dist_script() is not allowed in a subproject if meson.version() < 0.58.0.
241 can_add_dist_script = not meson.is_subproject() or meson.version().version_compare('>= 0.58.0')
247 subdir('docs/reference')
248 subdir('docs/manual')
250 if can_add_dist_script
251 # Add a ChangeLog file to the distribution directory.
252 meson.add_dist_script(
253 python3, dist_changelog,
256 # Add build scripts to the distribution directory, and delete .gitignore
257 # files and an empty $MESON_PROJECT_DIST_ROOT/build/ directory.
258 meson.add_dist_script(
259 python3, dist_build_scripts,
261 'untracked' / 'build_scripts',
265 if meson.is_subproject()
267 'htmlrefdir': install_prefix / install_docdir / 'reference' / 'html',
268 'htmlrefpub': 'http://library.gnome.org/devel/libsigc++/2.10/'
270 if build_documentation
271 pkgconfig_vars += {'doxytagfile': tag_file.full_path()}
272 # May be used in a main project.
273 global_tag_file_target = tag_file
275 sigcxx_dep = declare_dependency(
276 dependencies: sigcxx_own_dep,
277 variables: pkgconfig_vars,
280 # A main project that looks for sigcxx_pcname.pc shall find sigcxx_dep.
281 meson.override_dependency(sigcxx_pcname, sigcxx_dep)
285 real_maintainer_mode = ''
286 if maintainer_mode_opt == 'if-git-build'
287 real_maintainer_mode = ' (@0@)'.format(maintainer_mode)
290 real_build_documentation = ''
291 if build_documentation_opt == 'if-maintainer-mode'
292 real_build_documentation = ' (@0@)'.format(build_documentation)
295 validate = get_option('validation') and can_parse_and_validate
297 if get_option('validation') and not validate
298 explain_val = ' (requires xmllint with Relax NG and DocBook V5.0 support)'
301 build_pdf = build_pdf_by_default and can_build_pdf
303 if build_pdf_by_default and not build_pdf
304 explain_pdf = ' (requires dblatex or (xsltproc and fop))'
310 meson.project_name() + ' ' + meson.project_version(),
312 ' Maintainer mode: @0@@1@'.format(maintainer_mode_opt, real_maintainer_mode),
313 ' Compiler warnings: @0@'.format(warning_level),
314 ' Build deprecated API: @0@'.format(build_deprecated_api),
315 'Build HTML documentation: @0@@1@'.format(build_documentation_opt, real_build_documentation),
316 ' XML validation: @0@@1@'.format(validate, explain_val),
317 ' Build PDF: @0@@1@'.format(build_pdf, explain_pdf),
318 ' Build example programs: @0@'.format(build_examples),
319 ' Benchmark: @0@'.format(do_benchmark),
321 ' prefix: @0@'.format(install_prefix),
322 ' includedir: @0@'.format(install_prefix / install_includedir),
323 ' includesigcxxdir: @0@'.format(install_prefix / install_includedir / sigcxx_pcname),
324 ' libdir: @0@'.format(install_prefix / install_libdir),
325 ' includeconfigdir: @0@'.format(install_prefix / install_includeconfigdir),
326 ' pkgconfigdir: @0@'.format(install_prefix / install_pkgconfigdir),
327 ' datadir: @0@'.format(install_prefix / install_datadir),
328 ' docdir: @0@'.format(install_prefix / install_docdir),
329 ' devhelpdir: @0@'.format(install_prefix / install_devhelpdir),
330 ' tutorialdir: @0@'.format(install_prefix / install_tutorialdir),
334 message('\n'.join(summary))