# Copyright 2021-2023 David Robillard # SPDX-License-Identifier: 0BSD OR GPL-3.0-or-later project( 'ganv', ['c', 'cpp'], default_options: [ 'b_ndebug=if-release', 'buildtype=release', 'c_std=c99', 'cpp_std=c++11', ], license: 'GPLv3+', meson_version: '>= 0.56.0', version: '1.8.3', ) ganv_src_root = meson.current_source_dir() major_version = meson.project_version().split('.')[0] version_suffix = '-@0@'.format(major_version) versioned_name = 'ganv' + version_suffix ############################# # Compilers and Build Tools # ############################# # Required tools pkg = import('pkgconfig') gnome = import('gnome') cc = meson.get_compiler('c') cpp = meson.get_compiler('cpp') ######################## # Warning Suppressions # ######################## warning_level = get_option('warning_level') clang_common_suppressions = [ '-Wno-cast-qual', '-Wno-covered-switch-default', '-Wno-disabled-macro-expansion', '-Wno-documentation-unknown-command', '-Wno-double-promotion', '-Wno-float-conversion', '-Wno-float-equal', '-Wno-implicit-fallthrough', '-Wno-implicit-float-conversion', '-Wno-padded', '-Wno-reserved-id-macro', '-Wno-reserved-identifier', '-Wno-shadow', '-Wno-shorten-64-to-32', '-Wno-sign-conversion', '-Wno-switch-default', '-Wno-switch-enum', '-Wno-unused-macros', '-Wno-used-but-marked-unused', ] gcc_common_suppressions = [ '-Wno-cast-qual', '-Wno-conversion', '-Wno-deprecated-declarations', '-Wno-double-promotion', '-Wno-float-conversion', '-Wno-float-equal', '-Wno-format', '-Wno-implicit-fallthrough', '-Wno-padded', '-Wno-shadow', '-Wno-sign-conversion', '-Wno-suggest-attribute=const', '-Wno-suggest-attribute=pure', '-Wno-switch-default', '-Wno-switch-enum', '-Wno-unused-macros', ] # C c_suppressions = [] if cc.get_id() == 'clang' if warning_level == 'everything' c_suppressions += [ '-Wno-bad-function-cast', '-Wno-declaration-after-statement', '-Wno-documentation', '-Wno-unsafe-buffer-usage', ] if host_machine.system() == 'freebsd' c_suppressions += [ '-Wno-c11-extensions', ] endif endif if warning_level in ['everything', '3'] c_suppressions += ( clang_common_suppressions + [ '-Wno-cast-function-type', '-Wno-pedantic', ] ) endif elif cc.get_id() == 'gcc' if warning_level == 'everything' c_suppressions += [ '-Wno-bad-function-cast', '-Wno-c++-compat', '-Wno-unsuffixed-float-constants', ] endif if warning_level in ['everything', '3'] c_suppressions += ( gcc_common_suppressions + [ '-Wno-pedantic', ] ) endif if warning_level in ['everything', '3', '2'] c_suppressions += ( gcc_common_suppressions + [ '-Wno-cast-function-type', ] ) endif elif cc.get_id() == 'msvc' if warning_level == 'everything' c_suppressions += [ '/wd4061', # enumerator in switch is not explicitly handled '/wd4100', # unreferenced formal parameter '/wd4191', # unsafe function conversion '/wd4200', # zero-sized array in struct/union '/wd4244', # possible loss of data from integer conversion '/wd4267', # possible loss of data from size conversion '/wd4365', # signed/unsigned mismatch '/wd4514', # unreferenced inline function has been removed '/wd4706', # assignment within conditional expression '/wd4710', # function not inlined '/wd4711', # function selected for automatic inline expansion '/wd4800', # implicit conversion from int to bool '/wd4820', # padding added after construct '/wd4996', # POSIX name for this item is deprecated '/wd5045', # compiler will insert Spectre mitigation ] endif endif c_suppressions = cc.get_supported_arguments(c_suppressions) # C++ cpp_suppressions = [] if cpp.get_id() == 'clang' cpp_suppressions += clang_common_suppressions if warning_level == 'everything' cpp_suppressions += [ '-Wno-c++98-compat', '-Wno-exit-time-destructors', '-Wno-global-constructors', '-Wno-missing-noreturn', '-Wno-old-style-cast', '-Wno-unsafe-buffer-usage', '-Wno-weak-vtables', '-Wno-zero-as-null-pointer-constant', ] endif if warning_level in ['everything', '3'] cpp_suppressions += [ '-Wno-cast-function-type', ] endif elif cpp.get_id() == 'gcc' cpp_suppressions += gcc_common_suppressions if warning_level == 'everything' cpp_suppressions += [ '-Wno-effc++', '-Wno-missing-noreturn', '-Wno-null-dereference', '-Wno-old-style-cast', '-Wno-redundant-tags', '-Wno-useless-cast', '-Wno-zero-as-null-pointer-constant', ] endif if warning_level in ['everything', '3'] cpp_suppressions += [ '-Wno-pedantic', ] endif if warning_level in ['everything', '3', '2'] cpp_suppressions += [ '-Wno-cast-function-type', ] endif endif cpp_suppressions = cpp.get_supported_arguments(cpp_suppressions) ################ # Dependencies # ################ m_dep = cc.find_library('m', required: false) intl_dep = cc.find_library('intl', required: get_option('nls')) gtk2_dep = dependency('gtk+-2.0', version: '>= 2.10.0', include_type: 'system') gtkmm2_dep = dependency( 'gtkmm-2.4', include_type: 'system', version: '>= 2.10.0', ) gvc_dep = dependency( 'libgvc', include_type: 'system', required: get_option('graphviz'), ) ########################## # Platform Configuration # ########################## # Use versioned name everywhere to support parallel major version installations if host_machine.system() == 'windows' if get_option('default_library') == 'both' error('default_library=both is not supported on Windows') endif soversion = '' else soversion = meson.project_version().split('.')[0] endif ################# # Configuration # ################# config_defines = [] # Graphviz layout if gvc_dep.found() config_defines += ['-DHAVE_AGRAPH'] endif # Force-directed graph layout if not get_option('fdgl').disabled() config_defines += ['-DGANV_FDGL'] endif # Light theme if get_option('light') config_defines += ['-DGANV_USE_LIGHT_THEME'] endif # Native language support if not get_option('nls').disabled() dgettext_code = '''#include int main(void) { !!dgettext("ganv", "string"); }''' config_defines += [ '-DHAVE_DGETTEXT=@0@'.format( cc.compiles(dgettext_code, name: 'dgettext').to_int(), ), ] endif add_project_arguments(config_defines, language: ['c', 'cpp']) ########### # Library # ########### include_dirs = include_directories('include') c_headers = files( 'include/ganv/box.h', 'include/ganv/canvas.h', 'include/ganv/circle.h', 'include/ganv/edge.h', 'include/ganv/ganv.h', 'include/ganv/group.h', 'include/ganv/item.h', 'include/ganv/module.h', 'include/ganv/node.h', 'include/ganv/port.h', 'include/ganv/text.h', 'include/ganv/types.h', 'include/ganv/widget.h', ) cpp_headers = files( 'include/ganv/Box.hpp', 'include/ganv/Canvas.hpp', 'include/ganv/Circle.hpp', 'include/ganv/Edge.hpp', 'include/ganv/Item.hpp', 'include/ganv/Module.hpp', 'include/ganv/Node.hpp', 'include/ganv/Port.hpp', 'include/ganv/ganv.hpp', 'include/ganv/types.hpp', 'include/ganv/wrap.hpp', ) sources = files( 'src/Canvas.cpp', 'src/Port.cpp', 'src/box.c', 'src/circle.c', 'src/edge.c', 'src/group.c', 'src/item.c', 'src/module.c', 'src/node.c', 'src/port.c', 'src/text.c', 'src/widget.c', ) # Set appropriate arguments for building against the library type extra_args = [] if get_option('default_library') == 'static' extra_args = ['-DGANV_STATIC'] endif # Generate marshal files with glib-genmarshal ganv_marshal_sources = gnome.genmarshal( 'ganv-marshal', extra_args: ['--quiet'], prefix: 'ganv_marshal', sources: files('src/ganv-marshal.list'), ) # Build shared and/or static library libganv = library( versioned_name, sources + ganv_marshal_sources, c_args: c_suppressions + extra_args + ['-DGANV_INTERNAL'], cpp_args: cpp_suppressions + extra_args + ['-DGANV_INTERNAL'], darwin_versions: [major_version + '.0.0', meson.project_version()], dependencies: [gtk2_dep, gtkmm2_dep, gvc_dep, intl_dep, m_dep], include_directories: include_dirs, install: true, soversion: soversion, version: meson.project_version(), ) # Declare dependency for internal meson dependants ganv_dep = declare_dependency( compile_args: extra_args, include_directories: include_dirs, link_with: libganv, ) # Generage pkg-config file for external dependants pkg.generate( libganv, description: 'Interactive Gtk canvas widget for graph-based interfaces', extra_cflags: extra_args, filebase: versioned_name, name: 'Ganv', subdirs: [versioned_name], version: meson.project_version(), ) # Override pkg-config dependency for internal meson dependants meson.override_dependency(versioned_name, ganv_dep) # Install headers to a versioned include directory install_headers(c_headers + cpp_headers, subdir: versioned_name / 'ganv') # Generate GObject introspection data if not get_option('gir').disabled() # TODO: With newer g-ir-scanner we could simply do # ['--compiler=' + cpp.cmd_array()[0]] g_ir_scanner_args = ['--quiet'] if target_machine.system() == 'darwin' g_ir_scanner_args += ['-lc++'] elif target_machine.system() in ['gnu', 'linux'] g_ir_scanner_args += ['-lstdc++'] endif gnome.generate_gir( libganv, dependencies: [ganv_dep], extra_args: g_ir_scanner_args, fatal_warnings: true, header: 'ganv.h', includes: ['GObject-2.0', 'Gdk-2.0', 'Gtk-2.0'], install: true, namespace: 'Ganv', nsversion: '1.0', sources: sources + c_headers + ganv_marshal_sources, ) endif if not meson.is_subproject() summary('Install prefix', get_option('prefix')) summary('Headers', get_option('prefix') / get_option('includedir')) summary('Libraries', get_option('prefix') / get_option('libdir')) endif