meson.build 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # SPDX-FileCopyrightText: 2021 Andrea Pappacoda
  2. #
  3. # SPDX-License-Identifier: MIT
  4. project(
  5. 'cpp-httplib',
  6. 'cpp',
  7. license: 'MIT',
  8. default_options: [
  9. 'cpp_std=c++11',
  10. 'buildtype=release',
  11. 'b_ndebug=if-release',
  12. 'b_lto=true',
  13. 'warning_level=3'
  14. ],
  15. meson_version: '>=0.47.0'
  16. )
  17. # Check just in case downstream decides to edit the source
  18. # and add a project version
  19. version = meson.project_version()
  20. python3 = find_program('python3')
  21. if version == 'undefined'
  22. # Meson doesn't have regular expressions, but since it is implemented
  23. # in python we can be sure we can use it to parse the file manually
  24. version = run_command(
  25. python3, '-c', 'import re; raw_version = re.search("User\-Agent.*cpp\-httplib/([0-9]+\.?)+", open("httplib.h").read()).group(0); print(re.search("([0-9]+\\.?)+", raw_version).group(0))',
  26. check: true
  27. ).stdout().strip()
  28. endif
  29. message('cpp-httplib version ' + version)
  30. deps = [dependency('threads')]
  31. args = []
  32. openssl_dep = dependency('openssl', version: ['>=1.1.1', '<1.1.2'], required: get_option('cpp-httplib_openssl'))
  33. if openssl_dep.found()
  34. deps += openssl_dep
  35. args += '-DCPPHTTPLIB_OPENSSL_SUPPORT'
  36. endif
  37. zlib_dep = dependency('zlib', required: get_option('cpp-httplib_zlib'))
  38. if zlib_dep.found()
  39. deps += zlib_dep
  40. args += '-DCPPHTTPLIB_ZLIB_SUPPORT'
  41. endif
  42. brotli_deps = [dependency('libbrotlicommon', required: get_option('cpp-httplib_brotli'))]
  43. brotli_deps += dependency('libbrotlidec', required: get_option('cpp-httplib_brotli'))
  44. brotli_deps += dependency('libbrotlienc', required: get_option('cpp-httplib_brotli'))
  45. brotli_found_all = true
  46. foreach brotli_dep : brotli_deps
  47. if not brotli_dep.found()
  48. brotli_found_all = false
  49. endif
  50. endforeach
  51. if brotli_found_all
  52. deps += brotli_deps
  53. args += '-DCPPHTTPLIB_BROTLI_SUPPORT'
  54. endif
  55. cpp_httplib_dep = dependency('', required: false)
  56. if get_option('cpp-httplib_compile')
  57. httplib_ch = custom_target(
  58. 'split',
  59. input: 'httplib.h',
  60. output: ['httplib.cc', 'httplib.h'],
  61. command: [python3, files('split.py'), '--out', meson.current_build_dir()],
  62. install: true,
  63. install_dir: [false, get_option('includedir')]
  64. )
  65. lib = library(
  66. 'cpp-httplib',
  67. sources: httplib_ch,
  68. dependencies: deps,
  69. cpp_args: args,
  70. version: version,
  71. install: true
  72. )
  73. cpp_httplib_dep = declare_dependency(compile_args: args, dependencies: deps, link_with: lib, sources: httplib_ch[1])
  74. import('pkgconfig').generate(
  75. lib,
  76. description: 'A C++ HTTP/HTTPS server and client library',
  77. extra_cflags: args,
  78. url: 'https://github.com/yhirose/cpp-httplib',
  79. version: version
  80. )
  81. else
  82. install_headers('httplib.h')
  83. cpp_httplib_dep = declare_dependency(compile_args: args, dependencies: deps, include_directories: include_directories('.'))
  84. import('pkgconfig').generate(
  85. name: 'cpp-httplib',
  86. description: 'A C++ HTTP/HTTPS server and client library',
  87. install_dir: join_paths(get_option('datadir'), 'pkgconfig'),
  88. url: 'https://github.com/yhirose/cpp-httplib',
  89. version: version
  90. )
  91. endif
  92. if meson.version().version_compare('>=0.54.0')
  93. meson.override_dependency('cpp-httplib', cpp_httplib_dep)
  94. endif
  95. if get_option('cpp-httplib_test')
  96. subdir('test')
  97. endif