meson.build 3.2 KB

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