meson.build 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. cxx = meson.get_compiler('cpp')
  23. version = cxx.get_define('CPPHTTPLIB_VERSION',
  24. prefix: '#include <httplib.h>',
  25. include_directories: include_directories('.')).strip('"')
  26. assert(version != '', 'failed to get version from httplib.h')
  27. endif
  28. message('cpp-httplib version ' + version)
  29. deps = [dependency('threads')]
  30. args = []
  31. openssl_dep = dependency('openssl', version: '>=1.1.1', required: get_option('cpp-httplib_openssl'))
  32. if openssl_dep.found()
  33. deps += openssl_dep
  34. args += '-DCPPHTTPLIB_OPENSSL_SUPPORT'
  35. endif
  36. zlib_dep = dependency('zlib', required: get_option('cpp-httplib_zlib'))
  37. if zlib_dep.found()
  38. deps += zlib_dep
  39. args += '-DCPPHTTPLIB_ZLIB_SUPPORT'
  40. endif
  41. brotli_deps = [dependency('libbrotlicommon', required: get_option('cpp-httplib_brotli'))]
  42. brotli_deps += dependency('libbrotlidec', required: get_option('cpp-httplib_brotli'))
  43. brotli_deps += dependency('libbrotlienc', required: get_option('cpp-httplib_brotli'))
  44. brotli_found_all = true
  45. foreach brotli_dep : brotli_deps
  46. if not brotli_dep.found()
  47. brotli_found_all = false
  48. endif
  49. endforeach
  50. if brotli_found_all
  51. deps += brotli_deps
  52. args += '-DCPPHTTPLIB_BROTLI_SUPPORT'
  53. endif
  54. cpp_httplib_dep = dependency('', required: false)
  55. if get_option('cpp-httplib_compile')
  56. httplib_ch = custom_target(
  57. 'split',
  58. input: 'httplib.h',
  59. output: ['httplib.cc', 'httplib.h'],
  60. command: [python3, files('split.py'), '--out', meson.current_build_dir()],
  61. install: true,
  62. install_dir: [false, get_option('includedir')]
  63. )
  64. lib = library(
  65. 'cpp-httplib',
  66. sources: httplib_ch,
  67. dependencies: deps,
  68. cpp_args: args,
  69. version: version,
  70. install: true
  71. )
  72. cpp_httplib_dep = declare_dependency(compile_args: args, dependencies: deps, link_with: lib, sources: httplib_ch[1])
  73. import('pkgconfig').generate(
  74. lib,
  75. description: 'A C++ HTTP/HTTPS server and client library',
  76. extra_cflags: args,
  77. url: 'https://github.com/yhirose/cpp-httplib',
  78. version: version
  79. )
  80. else
  81. install_headers('httplib.h')
  82. cpp_httplib_dep = declare_dependency(compile_args: args, dependencies: deps, include_directories: include_directories('.'))
  83. import('pkgconfig').generate(
  84. name: 'cpp-httplib',
  85. description: 'A C++ HTTP/HTTPS server and client library',
  86. install_dir: join_paths(get_option('datadir'), 'pkgconfig'),
  87. url: 'https://github.com/yhirose/cpp-httplib',
  88. version: version
  89. )
  90. endif
  91. if meson.version().version_compare('>=0.54.0')
  92. meson.override_dependency('cpp-httplib', cpp_httplib_dep)
  93. endif
  94. if get_option('cpp-httplib_test')
  95. subdir('test')
  96. endif