diff options
author | Kjell Ahlstedt <kjellahlstedt@gmail.com> | 2020-03-01 13:30:00 +0100 |
---|---|---|
committer | Kjell Ahlstedt <kjellahlstedt@gmail.com> | 2020-03-01 13:30:00 +0100 |
commit | d378578484718d267bf429ef2e6eded695446b46 (patch) | |
tree | e0a38dc5fc9848012df87e56a460f74401f0e487 /glib | |
parent | 1df52bb90b7ca3780043b16acf5bb5eb483876f8 (diff) | |
download | glibmm-d378578484718d267bf429ef2e6eded695446b46.tar.gz |
Add support for building glibmm with Meson
glibmm can be built with either Autotools or Meson.
See MR !27
Diffstat (limited to 'glib')
-rw-r--r-- | glib/glibmm/meson.build | 373 | ||||
-rw-r--r-- | glib/glibmmconfig.h.meson | 125 | ||||
-rw-r--r-- | glib/meson.build | 103 |
3 files changed, 601 insertions, 0 deletions
diff --git a/glib/glibmm/meson.build b/glib/glibmm/meson.build new file mode 100644 index 00000000..29acfdac --- /dev/null +++ b/glib/glibmm/meson.build @@ -0,0 +1,373 @@ +# glib/glibmm + +# Input: glibmm_build_dep, glibmm_pcname, maintainer_mode, project_source_root, +# generate_binding_py, handle_built_files_py, m4_files, pm_files, +# glibmm_libversion, install_includedir, python3, glibmm_rc, gmmproc_dir, +# is_host_windows, gendef +# Output: glibmm_hg_ccg_basenames, glibmm_extra_h_files, built_files_root, +# glibmm_built_h_file_targets, glibmm_dep + +glibmm_defs_basefiles = [ + 'glib.defs', + 'glib_enums.defs', + 'glib_functions.defs', + 'glib_signals.defs', + 'glib_extra_objects.defs', + 'gmodule_enums.defs', + 'gmodule_functions.defs', + 'gobject_enums.defs', + 'gobject_functions.defs', + 'glib_docs.xml', + 'glib_docs_override.xml', +] + +glibmm_defs_files = [] +foreach file : glibmm_defs_basefiles + glibmm_defs_files += '..' / 'src' / file +endforeach + +# Generated from pairs of .hg and .ccg files. +glibmm_hg_ccg_basenames = [ + 'balancedtree', + 'binding', + 'bytes', + 'bytearray', + 'checksum', + 'convert', + 'date', + 'datetime', + 'enums', + 'fileutils', + 'iochannel', + 'keyfile', + 'markup', + 'miscutils', + 'module', + 'nodetree', + 'optioncontext', + 'optionentry', + 'optiongroup', + 'regex', + 'shell', + 'spawn', + 'timezone', + 'unicode', + 'uriutils', + 'variant', + 'variantdict', + 'variantiter', + 'varianttype', +] + +# Generated from .m4 files. +glibmm_h_m4_files = [ + 'value_basictypes.h', + 'variant_basictypes.h', +] + +glibmm_cc_m4_files = [ + 'value_basictypes.cc', + 'variant_basictypes.cc', +] + +# Pairs of hand-coded .h and .cc files. +glibmm_extra_h_cc_basenames = [ + 'base64', + 'class', + 'debug', + 'dispatcher', + 'error', + 'exceptionhandler', + 'extraclassinit', + 'init', + 'interface', + 'main', + 'object', + 'objectbase', + 'pattern', + 'property', + 'propertyproxy', + 'propertyproxy_base', + 'quark', + 'random', + 'signalproxy', + 'signalproxy_connectionnode', + 'stringutils', + 'timer', + 'ustring', + 'utility', + 'value', + 'value_custom', + 'variantdbusstring', + 'vectorutils', + 'wrap', +] + +glibmm_extra_h_files = [ + 'containerhandle_shared.h', + 'i18n-lib.h', + 'i18n.h', + 'priorities.h', + 'refptr.h', + 'wrap_init.h', +] + +glibmm_extra_ph_files = [ + 'private' / 'interface_p.h', + 'private' / 'object_p.h', +] + +glibmm_extra_cc_files = [] + +foreach file : glibmm_extra_h_cc_basenames + glibmm_extra_h_files += file + '.h' + glibmm_extra_cc_files += file + '.cc' +endforeach + +install_headers('..' / 'glibmm.h', subdir: glibmm_pcname) +install_headers(glibmm_extra_h_files, subdir: glibmm_pcname / 'glibmm') +install_headers(glibmm_extra_ph_files, subdir: glibmm_pcname / 'glibmm' / 'private') + +untracked_glibmm = 'untracked' / 'glib' / 'glibmm' +src_untracked_glibmm = project_source_root / untracked_glibmm + +if maintainer_mode + + # Maintainer mode. Generate .h and .cc files from .hg and .ccg files in ../src. + + # docs/reference/meson.build needs these. + built_files_root = project_build_root + glibmm_built_h_file_targets = [] + + # Force meson+ninja to generate source files before anything is compiled. + # Compilation must depend on these targets. + glibmm_built_cc_file_targets = [] + + hg_files = [] + foreach file : glibmm_hg_ccg_basenames + hg_files += '..' / 'src' / file + '.hg' + endforeach + + # Create wrap_init.cc in project_build_root/glib/glibmm. + glibmm_built_cc_file_targets += custom_target('glibmm-wrap_init.cc', + input: hg_files, + output: 'wrap_init.cc', + command: [ + python3, generate_binding_py, 'generate_wrap_init', + gmmproc_dir, + '@OUTPUT@', + 'Glib', # namespace + '@INPUT@', + ], + build_by_default: maintainer_mode, + install: false, + ) + + # Create .h/_p.h/.cc files in project_build_root/glib/glibmm + # from .hg/.ccg files in project_source_root/glib/src. + foreach file : glibmm_hg_ccg_basenames + hg_file = '..' / 'src' / file + '.hg' + ccg_file = '..' / 'src' / file + '.ccg' + built_file_target = custom_target('glibmm-' + file + '.cc', + input: [hg_file, ccg_file], + output: [file + '.stamp', file + '.cc', file + '.h'], + command: [ + python3, handle_built_files_py, 'gmmproc', + gmmproc_dir, + project_source_root / 'tools' / 'pm', + '@OUTPUT0@', + file, + meson.current_source_dir() / '..' / 'src', + project_source_root / 'tools' / 'm4', + ], + depend_files: glibmm_defs_files + m4_files + pm_files, + build_by_default: maintainer_mode, + install: false, + ) + glibmm_built_cc_file_targets += built_file_target[1] + glibmm_built_h_file_targets += built_file_target[2] + endforeach + + # Create .h and .cc files in project_build_root/glib/glibmm + # from .m4 files in project_source_root/glib/src. + foreach output_file : glibmm_h_m4_files + glibmm_cc_m4_files + input_file = '..' / 'src' / output_file + '.m4' + built_file_target = custom_target('glibmm-' + output_file, + input: input_file, + output: output_file, + command: [ + python3, handle_built_files_py, 'build_from_m4', + meson.current_source_dir() / '..' / 'src', + '@INPUT@', + '@OUTPUT@', + ], + depend_files: '..' / 'src' / 'template.macros.m4', + build_by_default: maintainer_mode, + install: false, + ) + if output_file.endswith('.cc') + glibmm_built_cc_file_targets += built_file_target + else + glibmm_built_h_file_targets += built_file_target + endif + endforeach + + # Create dummy_header.h, depending on all generated headers. + # It's created if it does not exist, but it's never updated. + # It guarantees that all generated headers are built before glibmm_library + # is built, at the same time avoiding unnecessary recompilations. + # If glibmm_built_h_file_targets would be listed as sources to glibmm_library, + # all generated .cc files could be recompiled if one generated .h file has + # been changed. + built_dummy_h_file_target = custom_target('glibmm-dummy_header.h', + input: glibmm_built_h_file_targets, + output: 'dummy_header.h', + command: [ + python3, dummy_header_py, + '@OUTPUT@', + ], + build_by_default: maintainer_mode, + install: false, + ) + + extra_include_dirs = ['..'] + glibmm_library = library(glibmm_pcname, + glibmm_built_cc_file_targets, glibmm_extra_cc_files, built_dummy_h_file_target, + version: glibmm_libversion, + include_directories: extra_include_dirs, + cpp_args: '-DGLIBMM_BUILD=1', + dependencies: glibmm_build_dep, + install: true, + ) + + built_h_cc_dir = meson.current_build_dir() + +else # not maintainer_mode + + # Not maintainer mode. Compile built source code files in + # project_source_root/untracked/glib/glibmm. + + # docs/reference/meson.build needs these. + built_files_root = project_source_root / 'untracked' + glibmm_built_h_file_targets = [] + + # Two cases: + # 1. The source code comes from a tarball, where the built files + # are stored in project_source_root/untracked. + # There are no built files in the build tree. + # 2. Files have been built in the build tree. Then maintainer_mode has + # been changed from true to false. Files that are missing or not up to date + # in project_source_root/untracked are copied from the build tree. + + # Try to copy built source code files to the source tree. + run_command( + python3, generate_binding_py, 'copy_built_files', + meson.current_build_dir(), + src_untracked_glibmm, + glibmm_hg_ccg_basenames, + ) + run_command( + python3, handle_built_files_py, 'copy_built_files', + meson.current_build_dir(), + src_untracked_glibmm, + glibmm_h_m4_files + glibmm_cc_m4_files, + ) + + built_cc_files = [ src_untracked_glibmm / 'wrap_init.cc' ] + foreach file : glibmm_hg_ccg_basenames + built_cc_files += src_untracked_glibmm / file + '.cc' + endforeach + foreach file : glibmm_cc_m4_files + built_cc_files += src_untracked_glibmm / file + endforeach + + extra_include_dirs = [ '..', '..' / '..' / 'untracked' / 'glib' ] + + # We need this so that we can run gendef.exe to get the .def file + # needed for obtaining the .lib file for the glibmm DLL + glib_int_lib = static_library('glibmm-int', + built_cc_files, glibmm_extra_cc_files, + include_directories: extra_include_dirs, + cpp_args: '-DGLIBMM_BUILD=1', + dependencies: glibmm_build_dep, + install: false, + ) + + glibmm_def = [] + glibmm_extra_link_args = [] + extra_glibmm_objects = [] + + if is_msvc + glibmm_def = custom_target('glibmm.def', + output: 'glibmm.def', + depends: glib_int_lib, + command: [ gendef, + '@OUTPUT@', + '@0@-@1@.dll'.format(glibmm_pcname, glibmm_libversion.split('.')[0]), + glib_int_lib.full_path(), + ], + install: false, + ) + glibmm_extra_link_args = ['/def:@0@'.format(glibmm_def.full_path())] + endif + + # Build the .rc file for Windows builds and link to it + if is_host_windows + windows = import('windows') + glibmm_res = windows.compile_resources(glibmm_rc) + extra_glibmm_objects += glibmm_res + endif + + glibmm_library = library(glibmm_pcname, extra_glibmm_objects, + objects: glib_int_lib.extract_all_objects(), + version: glibmm_libversion, + dependencies: glibmm_build_dep, + link_depends: glibmm_def, + link_args: glibmm_extra_link_args, + install: true, + ) + + built_h_cc_dir = src_untracked_glibmm + +endif + +# Install built .h and _p.h files. +meson.add_install_script( + python3.path(), generate_binding_py, 'install_built_h_files', + built_h_cc_dir, + install_includedir / glibmm_pcname / 'glibmm', # subdir below {prefix} + glibmm_hg_ccg_basenames +) +# Install .h files built from .m4 files. +meson.add_install_script( + python3.path(), handle_built_files_py, 'install_built_h_files', + built_h_cc_dir, + install_includedir / glibmm_pcname / 'glibmm', # subdir below {prefix} + glibmm_h_m4_files, +) + +if not meson.is_subproject() + # Distribute built files. + # (add_dist_script() is not allowed in a subproject) + meson.add_dist_script( + python3.path(), generate_binding_py, 'dist_built_files', + built_h_cc_dir, + untracked_glibmm, + glibmm_hg_ccg_basenames, + ) + meson.add_dist_script( + python3.path(), handle_built_files_py, 'dist_built_files', + built_h_cc_dir, + untracked_glibmm, + glibmm_h_m4_files + glibmm_cc_m4_files, + ) +endif + +# This is useful in the main project when glibmm is used as a subproject. +# It's also used when building example programs and test programs. +glibmm_dep = declare_dependency( + sources: glibmm_built_h_file_targets, + link_with: glibmm_library, + include_directories: extra_include_dirs, + dependencies: glibmm_build_dep, +) diff --git a/glib/glibmmconfig.h.meson b/glib/glibmmconfig.h.meson new file mode 100644 index 00000000..177f745b --- /dev/null +++ b/glib/glibmmconfig.h.meson @@ -0,0 +1,125 @@ +#ifndef _GLIBMM_CONFIG_H +#define _GLIBMM_CONFIG_H + +/* Define to omit deprecated API from the library. */ +#mesondefine GLIBMM_DISABLE_DEPRECATED + +/* Major version number of glibmm. */ +#mesondefine GLIBMM_MAJOR_VERSION + +/* Minor version number of glibmm. */ +#mesondefine GLIBMM_MINOR_VERSION + +/* Micro version number of glibmm. */ +#mesondefine GLIBMM_MICRO_VERSION + +/* Define if glibmm is built as a static library */ +#mesondefine GLIBMM_STATIC_LIB + +/* The size of wchar_t, as computed by sizeof. */ +#mesondefine GLIBMM_SIZEOF_WCHAR_T + +/* Defined when the -Ddebug-refcounting configure argument was given */ +#mesondefine GLIBMM_DEBUG_REFCOUNTING + +#ifdef _WIN32 + /* Win32 compilers have a lot of varation */ +# if defined(_MSC_VER) +# define GLIBMM_MSC 1 +# define GLIBMM_WIN32 1 +# define GLIBMM_DLL 1 +# elif defined(__CYGWIN__) +# define GLIBMM_CONFIGURE 1 +# elif defined(__MINGW32__) +# define GLIBMM_WIN32 1 +# define GLIBMM_CONFIGURE 1 +# else + /* AIX clR compiler complains about this even though it doesn't get this far */ +# error "Unknown architecture (send me gcc --dumpspecs or equiv)" +# endif +#else +# define GLIBMM_CONFIGURE 1 +#endif /* _WIN32 */ + +#ifdef GLIBMM_CONFIGURE + +/* Define only on Mac OS, COCOA */ +#mesondefine GLIBMM_OS_COCOA + +/* Define if extern "C" and extern "C++" function pointers are compatible. */ +#mesondefine GLIBMM_CAN_ASSIGN_NON_EXTERN_C_FUNCTIONS_TO_EXTERN_C_CALLBACKS + +/* Define if non-instantiated templates may dynamic_cast<> to an undefined + type. */ +#mesondefine GLIBMM_CAN_USE_DYNAMIC_CAST_IN_UNUSED_TEMPLATE_WITHOUT_DEFINITION + +/* Defined if a static member variable may be initialized inline to + std::string::npos */ +#mesondefine GLIBMM_HAVE_ALLOWS_STATIC_INLINE_NPOS + +/* Define if the compiler disambiguates template specializations for const and + non-const types. */ +#mesondefine GLIBMM_HAVE_DISAMBIGUOUS_CONST_TEMPLATE_SPECIALIZATIONS + +/* Defined if std::iterator_traits<> is standard-conforming */ +#mesondefine GLIBMM_HAVE_STD_ITERATOR_TRAITS + +/* Defined if std::reverse_iterator is in Sun libCstd style */ +#mesondefine GLIBMM_HAVE_SUN_REVERSE_ITERATOR + +/* Defined if the STL containers have templated sequence ctors */ +#mesondefine GLIBMM_HAVE_TEMPLATE_SEQUENCE_CTORS + +/* Define to 1 if wide stream is available. */ +#mesondefine GLIBMM_HAVE_WIDE_STREAM + +#endif /* GLIBMM_CONFIGURE */ + +#ifdef GLIBMM_MSC +# define GLIBMM_HAVE_STD_ITERATOR_TRAITS 1 +# define GLIBMM_HAVE_TEMPLATE_SEQUENCE_CTORS 1 +# define GLIBMM_HAVE_WIDE_STREAM 1 +# define GLIBMM_HAVE_DISAMBIGUOUS_CONST_TEMPLATE_SPECIALIZATIONS 1 +# define GLIBMM_CAN_USE_DYNAMIC_CAST_IN_UNUSED_TEMPLATE_WITHOUT_DEFINITION 1 +# define GLIBMM_CAN_ASSIGN_NON_EXTERN_C_FUNCTIONS_TO_EXTERN_C_CALLBACKS 1 +# pragma warning (disable: 4786 4355 4800 4181) + +#if (_MSC_VER < 1900) +/* The C++-11 keywords noexcept and thread_local are supported on + * Visual Studio 2013 via Microsoft-specific extensions, but are + * supported directly in Visual Studio 2015 + */ + +#define _ALLOW_KEYWORD_MACROS 1 + +#ifndef noexcept +#define noexcept _NOEXCEPT +#endif + +#ifndef thread_local +#define thread_local __declspec (thread) +#endif + +#endif /* _MSC_VER < 1900 */ +#endif /* GLIBMM_MSC */ + +/* Enable DLL-specific stuff only when not building a static library */ +#if !defined(__CYGWIN__) && defined(__MINGW32__) && !defined(GLIBMM_STATIC_LIB) +# define GLIBMM_DLL 1 +#endif + +#ifdef GLIBMM_DLL +# if defined(GLIBMM_BUILD) && defined(_WINDLL) + /* Do not dllexport as it is handled by gendef on MSVC */ +# define GLIBMM_API +# elif !defined(GLIBMM_BUILD) +# define GLIBMM_API __declspec(dllimport) +# else + /* Build a static library */ +# define GLIBMM_API +# endif /* GLIBMM_BUILD - _WINDLL */ +#else +# define GLIBMM_API +#endif /* GLIBMM_DLL */ + +#endif /* _GLIBMM_CONFIG_H */ diff --git a/glib/meson.build b/glib/meson.build new file mode 100644 index 00000000..bf9141c7 --- /dev/null +++ b/glib/meson.build @@ -0,0 +1,103 @@ +# glib + +# Input: install_prefix, install_libdir, install_datadir, install_includedir, +# glibmm_pcname, giomm_pcname, glibmm_api_version, glibmm_requires, +# giomm_requires, build_deprecated_api, install_pkgconfigdir, +# is_os_cocoa, cpp_compiler, glibmm_major_version, glibmm_minor_version, +# glibmm_micro_version +# Output: pkg_conf_data, install_glibmmconfigdir, glibmmconfig_h + +pkg_conf_data = configuration_data() +pkg_conf_data.set('prefix', install_prefix) +pkg_conf_data.set('exec_prefix', '${prefix}') +pkg_conf_data.set('libdir', '${exec_prefix}' / install_libdir) +pkg_conf_data.set('datarootdir', '${prefix}' / install_datadir) +pkg_conf_data.set('datadir', '${datarootdir}') +pkg_conf_data.set('includedir', '${prefix}' / install_includedir) +pkg_conf_data.set('PACKAGE_TARNAME', meson.project_name()) +pkg_conf_data.set('PACKAGE_VERSION', meson.project_version()) +pkg_conf_data.set('GLIBMM_MODULE_NAME', glibmm_pcname) +pkg_conf_data.set('GLIBMM_API_VERSION', glibmm_api_version) +pkg_conf_data.set('GLIBMM_MODULES', glibmm_requires) +pkg_conf_data.set('GIOMM_MODULE_NAME', giomm_pcname) +pkg_conf_data.set('GIOMM_API_VERSION', glibmm_api_version) +pkg_conf_data.set('GIOMM_MODULES', giomm_requires) +if not build_deprecated_api + pkg_conf_data.set('GLIBMM_DISABLE_DEPRECATED', 1) + pkg_conf_data.set('GIOMM_DISABLE_DEPRECATED', 1) +endif +pkg_conf_data.set('GLIBMM_MAJOR_VERSION', glibmm_major_version) +pkg_conf_data.set('GLIBMM_MINOR_VERSION', glibmm_minor_version) +pkg_conf_data.set('GLIBMM_MICRO_VERSION', glibmm_micro_version) +pkg_conf_data.set('GIOMM_MAJOR_VERSION', glibmm_major_version) +pkg_conf_data.set('GIOMM_MINOR_VERSION', glibmm_minor_version) +pkg_conf_data.set('GIOMM_MICRO_VERSION', glibmm_micro_version) +if get_option('default_library') == 'static' + pkg_conf_data.set('GLIBMM_STATIC_LIB', 1) + pkg_conf_data.set('GIOMM_STATIC_LIB', 1) +endif + +configure_file( + input: 'glibmm.pc.in', + output: glibmm_pcname + '.pc', + configuration: pkg_conf_data, + install_dir: install_pkgconfigdir, +) + +glibmm_pkg_uninst_conf_data = configuration_data() +glibmm_pkg_uninst_conf_data.merge_from(pkg_conf_data) +glibmm_pkg_uninst_conf_data.set('srcdir', meson.current_source_dir()) + +configure_file( + input: 'glibmm-uninstalled.pc.in', + output: glibmm_pcname + '-uninstalled.pc', + configuration: glibmm_pkg_uninst_conf_data, +) + +glibmm_config_conf_data = configuration_data() +glibmm_config_conf_data.merge_from(pkg_conf_data) +if get_option('debug-refcounting') + glibmm_config_conf_data.set('GLIBMM_DEBUG_REFCOUNTING', 1) +endif +if is_os_cocoa + glibmm_config_conf_data.set('GLIBMM_OS_COCOA', 1) +endif +glibmm_config_conf_data.set('GLIBMM_SIZEOF_WCHAR_T', cpp_compiler.sizeof('wchar_t')) + +conf_tests = [ +# [preprocessor-macro-name, file-name, message] + ['GLIBMM_HAVE_WIDE_STREAM', 'have_wide_stream.cc', 'Wide stream support'], + ['GLIBMM_HAVE_STD_ITERATOR_TRAITS', 'have_std_iterator_traits.cc', + 'std::iterator_traits<> is standard-conforming'], + ['GLIBMM_HAVE_SUN_REVERSE_ITERATOR', 'have_sun_reverse_iterator.cc', + 'std::reverse_iterator is in Sun libCstd style'], + ['GLIBMM_HAVE_TEMPLATE_SEQUENCE_CTORS', 'have_template_sequence_ctors.cc', + 'STL containers have templated sequence ctors'], + ['GLIBMM_HAVE_DISAMBIGUOUS_CONST_TEMPLATE_SPECIALIZATIONS', + 'have_disambiguous_const_template_specializations.cc', + 'Disambiguates template specializations for const and non-const types'], + ['GLIBMM_CAN_USE_DYNAMIC_CAST_IN_UNUSED_TEMPLATE_WITHOUT_DEFINITION', + 'can_use_dynamic_cast_in_unused_template_wo_def.cc', + 'Non-instantiated templates may dynamic_cast<> to an undefined type'], + ['GLIBMM_CAN_ASSIGN_NON_EXTERN_C_FUNCTIONS_TO_EXTERN_C_CALLBACKS', + 'can_assign_non_extern_c_functions_to_extern_c_cb.cc', + 'extern "C" and extern "C++" function pointers are compatible'], + ['GLIBMM_HAVE_ALLOWS_STATIC_INLINE_NPOS', 'allows_static_inline_npos.cc', + 'A static member variable may be initialized inline to std::string::npos'], +] + +foreach conf_test : conf_tests + if cpp_compiler.compiles( + files('..' / 'tools' / 'conf_tests' / conf_test[1]), + name: conf_test[2]) + glibmm_config_conf_data.set(conf_test[0], 1) + endif +endforeach + +install_glibmmconfigdir = install_libdir / glibmm_pcname / 'include' +glibmmconfig_h = configure_file( + input: 'glibmmconfig.h.meson', + output: 'glibmmconfig.h', + configuration: glibmm_config_conf_data, + install_dir: install_glibmmconfigdir, +) |