From 2ae2ef4e4efca3b1dcf8124e1874a1148755d1d2 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Thu, 30 Sep 2021 18:30:20 -0400 Subject: [PATCH] add meson build support https://mesonbuild.com/ This should be feature-comparable with the cmake build (it even generates *-config.cmake files for installation, if cmake is installed to acquire the template). It supports all the major OSes, including macOS xcode and Windows visual studio support. meson also comes with some unique advantages. e.g. its builtin pkg-config generator module allows building third-party projects against an uninstalled developer build using pkg-config *-uninstalled.pc support. Also, and mainly, projects which use meson can make use of meson's subproject mechanism which allows installing a foo.wrap file into the project, after which dependency lookups for "foo" can retrieve it as an external project and build it in a single configure/compile process. This is very handy for building standalone executables, and somewhat invaluable on platforms that don't have a usable package manager. Documentation: https://mesonbuild.com/Wrap-dependency-system-manual.html In order for projects depending on pugixml to make use of this, pugixml needs to be buildable by meson, even if it isn't the default build system. --- meson.build | 68 +++++++++++++++++++++++++++++++++++++++++++++++ meson_options.txt | 5 ++++ tests/meson.build | 42 +++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 meson.build create mode 100644 meson_options.txt create mode 100644 tests/meson.build diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..02125e3 --- /dev/null +++ b/meson.build @@ -0,0 +1,68 @@ +project('pugixml', 'cpp', + version: '1.11.4', + meson_version: '>=0.46.0', + default_options: ['cpp_std=c++11'], +) + +cxx = meson.get_compiler('cpp') + +version = meson.project_version().split('.') +soversion = '.'.join([ version[0], version[1] ]) + +sources = files('src/pugixml.cpp') + +if host_machine.system() == 'windows' + win_mod = import('windows') + sources += win_mod.compile_resources('scripts/pugixml_dll.rc') +endif + +args = [] +if cxx.get_id() == 'msvc' + if get_option('default_library') == 'shared' + args +='-DPUGIXML_API=__declspec(dllexport)' + elif get_option('default_library') == 'both' + error('cannot build both shared and static on MSVC due to declspec') + endif +endif + +foreach opt: ['wchar_mode', 'compact', 'no_xpath', 'no_stl', 'no_exceptions'] + if get_option(opt) + args += '-DPUGIXML_' + opt.to_upper() + endif +endforeach + +pugixml_lib = library('pugixml', sources, + cpp_args: args, + version: soversion, + install: true, +) +install_headers('src/pugiconfig.hpp', 'src/pugixml.hpp') + +pugixml_dep = declare_dependency( + link_with: pugixml_lib, + include_directories: include_directories('src') +) + +import('pkgconfig').generate( + pugixml_lib, + description: 'Light-weight, simple and fast XML parser for C++ with XPath support.', + url: 'https://pugixml.org/', +) + +if find_program('cmake', required: false).found() + cmake = import('cmake') + cmake.write_basic_package_version_file( + name: meson.project_name(), + version: meson.project_version(), + compatibility: 'SameMajorVersion', + ) + cmake.configure_package_config_file( + input: 'scripts/pugixml-config.cmake.in', + name: meson.project_name(), + configuration: configuration_data(), + ) +endif + +subdir('tests') +pugixml_check = executable('pugixml-check', test_sources, dependencies: pugixml_dep) +test('pugixml-check', pugixml_check, workdir: meson.current_source_dir()) diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000..bb4e5ce --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,5 @@ +option('wchar_mode', type: 'boolean', value: false, description: 'Enable wchar_t mode') +option('compact', type: 'boolean', value: false) +option('no_xpath', type: 'boolean', value: false) +option('no_stl', type: 'boolean', value: false) +option('no_exceptions', type: 'boolean', value: false) diff --git a/tests/meson.build b/tests/meson.build new file mode 100644 index 0000000..fe47fff --- /dev/null +++ b/tests/meson.build @@ -0,0 +1,42 @@ +test_sources = files( + 'allocator.cpp', + 'main.cpp', + 'test_compact.cpp', + 'test.cpp', + 'test_deprecated.cpp', + 'test_document.cpp', + 'test_dom_modify.cpp', + 'test_dom_text.cpp', + 'test_dom_traverse.cpp', + 'test_header_guard.cpp', + 'test_header_iosfwd_1.cpp', + 'test_header_iosfwd_2.cpp', + 'test_header_iostream_1.cpp', + 'test_header_iostream_2.cpp', + 'test_header_only_1.cpp', + 'test_header_only_2.cpp', + 'test_header_string_1.cpp', + 'test_header_string_2.cpp', + 'test_header_string_iostream.cpp', + 'test_memory.cpp', + 'test_parse.cpp', + 'test_parse_doctype.cpp', + 'test_unicode.cpp', + 'test_version.cpp', + 'test_write.cpp', + 'test_xpath_api.cpp', + 'test_xpath.cpp', + 'test_xpath_functions.cpp', + 'test_xpath_operators.cpp', + 'test_xpath_parse.cpp', + 'test_xpath_paths_abbrev_w3c.cpp', + 'test_xpath_paths.cpp', + 'test_xpath_paths_w3c.cpp', + 'test_xpath_variables.cpp', + 'test_xpath_xalan_1.cpp', + 'test_xpath_xalan_2.cpp', + 'test_xpath_xalan_3.cpp', + 'test_xpath_xalan_4.cpp', + 'test_xpath_xalan_5.cpp', + 'writer_string.cpp', +)