|
| 1 | +# Copyright © 2024 Dylan Baker |
| 2 | +# |
| 3 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 4 | +# of this software and associated documentation files (the "Software"), to deal |
| 5 | +# in the Software without restriction, including without limitation the rights |
| 6 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 7 | +# copies of the Software, and to permit persons to whom the Software is |
| 8 | +# furnished to do so, subject to the following conditions: |
| 9 | +# |
| 10 | +# The above copyright notice and this permission notice shall be included in |
| 11 | +# all copies or substantial portions of the Software. |
| 12 | +# |
| 13 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 18 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 19 | +# THE SOFTWARE. |
| 20 | + |
| 21 | +project( |
| 22 | + 'cxxopts', |
| 23 | + 'cpp', |
| 24 | + version : run_command( |
| 25 | + 'meson/version.py', files('include/cxxopts.hpp'), capture : true, check : true).stdout().strip(), |
| 26 | + meson_version : '>= 0.64', |
| 27 | + license : 'MIT', |
| 28 | + default_options : ['cpp_std=c++11', 'warning_level=2'], |
| 29 | +) |
| 30 | + |
| 31 | +cpp = meson.get_compiler('cpp') |
| 32 | + |
| 33 | +with_warnings = get_option('warnings').disable_auto_if(meson.is_subproject()).allowed() |
| 34 | +if with_warnings |
| 35 | + add_project_arguments( |
| 36 | + cpp.get_supported_arguments( |
| 37 | + '-Wsuggest-override', |
| 38 | + '-Wshadow', |
| 39 | + '-Weffc++', |
| 40 | + '-Wsign-compare', |
| 41 | + '-Wshadow', |
| 42 | + '-Wwrite-strings', |
| 43 | + '-Wpointer-arith', |
| 44 | + '-Winit-self', |
| 45 | + '-Wconversion', |
| 46 | + '-Wno-sign-conversion', |
| 47 | + ), |
| 48 | + language : 'cpp', |
| 49 | + ) |
| 50 | +endif |
| 51 | + |
| 52 | +install_headers('include/cxxopts.hpp') |
| 53 | + |
| 54 | +dep_icu = dependency('icu-uc', required : get_option('icu')) |
| 55 | +if dep_icu.found() |
| 56 | + add_project_arguments('-DCXXOPTS_USE_UNICODE', language : 'cpp') |
| 57 | +endif |
| 58 | + |
| 59 | +with_examples = get_option('examples').disable_auto_if(meson.is_subproject()).allowed() |
| 60 | +if with_examples |
| 61 | + executable( |
| 62 | + 'example', |
| 63 | + 'src/example.cpp', |
| 64 | + include_directories : 'include', |
| 65 | + dependencies : dep_icu, |
| 66 | + override_options : ['cpp_std=c++17'], |
| 67 | + ) |
| 68 | +endif |
| 69 | + |
| 70 | +with_tests = get_option('tests').disable_auto_if(meson.is_subproject()).allowed() |
| 71 | +if with_tests |
| 72 | + test( |
| 73 | + 'link', |
| 74 | + executable( |
| 75 | + 'link_test', |
| 76 | + 'test/link_a.cpp', 'test/link_b.cpp', |
| 77 | + dependencies : dep_icu, |
| 78 | + include_directories : 'include', |
| 79 | + ) |
| 80 | + ) |
| 81 | + |
| 82 | + # Fuzzer test is not as trivial as it should be |
| 83 | + |
| 84 | + # Meson can generate basic cmake-configs files, but not when targets are used, |
| 85 | + # so these tests don't make sense |
| 86 | +endif |
| 87 | + |
| 88 | +extra_cflags = [] |
| 89 | +if dep_icu.found() |
| 90 | + extra_cflags += ['-DCXXOPTS_USE_UNICODE'] |
| 91 | +endif |
| 92 | + |
| 93 | +dep_cxxopts = declare_dependency( |
| 94 | + include_directories : 'include', |
| 95 | + dependencies : dep_icu, |
| 96 | + compile_args : extra_cflags, |
| 97 | +) |
| 98 | + |
| 99 | +meson.override_dependency('cxxopts', dep_cxxopts) |
| 100 | + |
| 101 | +pkg = import('pkgconfig') |
| 102 | + |
| 103 | +pkg.generate( |
| 104 | + name : 'cxxopts', |
| 105 | + description : 'A header-only lightweight C++ command line option parser', |
| 106 | + url : 'https://github.com/jarro2783/cxxopts', |
| 107 | + extra_cflags : extra_cflags, |
| 108 | + requires : dep_icu, |
| 109 | + dataonly : not dep_icu.found(), |
| 110 | +) |
0 commit comments