meson.build 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. 'buildtype=release',
  10. 'b_ndebug=if-release',
  11. 'b_lto=true',
  12. 'warning_level=3'
  13. ],
  14. meson_version: '>=0.47.0'
  15. )
  16. # Check just in case downstream decides to edit the source
  17. # and add a project version
  18. version = meson.project_version()
  19. if version == 'undefined'
  20. git = find_program('git', required: false)
  21. if git.found()
  22. result = run_command(git, 'describe', '--tags', '--abbrev=0')
  23. if result.returncode() == 0
  24. version = result.stdout().strip('v\n')
  25. endif
  26. endif
  27. endif
  28. python = import('python').find_installation('python3')
  29. # If version is still undefined it means that the git method failed
  30. if version == 'undefined'
  31. # Meson doesn't have regular expressions, but since it is implemented
  32. # in python we can be sure we can use it to parse the file manually
  33. version = run_command(
  34. python, '-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))'
  35. ).stdout().strip()
  36. endif
  37. message('cpp-httplib version ' + version)
  38. deps = [dependency('threads')]
  39. args = []
  40. openssl_dep = dependency('openssl', version: ['>=1.1.1', '<1.1.2'], required: get_option('cpp-httplib_openssl'))
  41. if openssl_dep.found()
  42. deps += openssl_dep
  43. args += '-DCPPHTTPLIB_OPENSSL_SUPPORT'
  44. endif
  45. zlib_dep = dependency('zlib', required: get_option('cpp-httplib_zlib'))
  46. if zlib_dep.found()
  47. deps += zlib_dep
  48. args += '-DCPPHTTPLIB_ZLIB_SUPPORT'
  49. endif
  50. brotli_deps = [dependency('libbrotlicommon', required: get_option('cpp-httplib_brotli'))]
  51. brotli_deps += dependency('libbrotlidec', required: get_option('cpp-httplib_brotli'))
  52. brotli_deps += dependency('libbrotlienc', required: get_option('cpp-httplib_brotli'))
  53. brotli_found_all = true
  54. foreach brotli_dep : brotli_deps
  55. if not brotli_dep.found()
  56. brotli_found_all = false
  57. endif
  58. endforeach
  59. if brotli_found_all
  60. deps += brotli_deps
  61. args += '-DCPPHTTPLIB_BROTLI_SUPPORT'
  62. endif
  63. cpp_httplib_dep = dependency('', required : false)
  64. if get_option('cpp-httplib_compile')
  65. httplib_ch = custom_target(
  66. 'split',
  67. input: 'httplib.h',
  68. output: ['httplib.cc', 'httplib.h'],
  69. command: [python, files('split.py'), '--out', meson.current_build_dir()],
  70. install: true,
  71. install_dir: [false, get_option('includedir')]
  72. )
  73. lib = library(
  74. 'cpp-httplib',
  75. sources: httplib_ch,
  76. dependencies: deps,
  77. cpp_args: args,
  78. version: version,
  79. install: true
  80. )
  81. cpp_httplib_dep = declare_dependency(link_with: lib, sources: httplib_ch[1])
  82. import('pkgconfig').generate(
  83. lib,
  84. description: 'A C++ HTTP/HTTPS server and client library',
  85. url: 'https://github.com/yhirose/cpp-httplib',
  86. version: version
  87. )
  88. else
  89. install_headers('httplib.h')
  90. cpp_httplib_dep = declare_dependency(include_directories: include_directories('.'), dependencies: deps)
  91. endif
  92. if meson.version().version_compare('>=0.54.0')
  93. meson.override_dependency('cpp-httplib', cpp_httplib_dep)
  94. endif