meson.build 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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.62.0'
  16. )
  17. cxx = meson.get_compiler('cpp')
  18. # Check just in case downstream decides to edit the source
  19. # and add a project version
  20. version = meson.project_version()
  21. if version == 'undefined'
  22. version = cxx.get_define('CPPHTTPLIB_VERSION',
  23. prefix: '#include <httplib.h>',
  24. include_directories: include_directories('.')).strip('"')
  25. assert(version != '', 'failed to get version from httplib.h')
  26. endif
  27. if cxx.has_function('poll', prefix: '#include <poll.h>')
  28. # Use poll if present
  29. add_project_arguments('-DCPPHTTPLIB_USE_POLL', language: 'cpp')
  30. elif cxx.has_function('select', prefix: '#include <sys/select.h>')
  31. # Use select otherwise
  32. add_project_arguments('-DCPPHTTPLIB_USE_SELECT', language: 'cpp')
  33. endif
  34. deps = [dependency('threads')]
  35. args = []
  36. openssl_dep = dependency('openssl', version: '>=3.0.0', required: get_option('cpp-httplib_openssl'))
  37. if openssl_dep.found()
  38. deps += openssl_dep
  39. args += '-DCPPHTTPLIB_OPENSSL_SUPPORT'
  40. if host_machine.system() == 'darwin'
  41. macosx_keychain_dep = dependency('appleframeworks', modules: ['CoreFoundation', 'Security'], required: get_option('cpp-httplib_macosx_keychain'))
  42. if macosx_keychain_dep.found()
  43. deps += macosx_keychain_dep
  44. args += '-DCPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN'
  45. endif
  46. endif
  47. endif
  48. zlib_dep = dependency('zlib', required: get_option('cpp-httplib_zlib'))
  49. if zlib_dep.found()
  50. deps += zlib_dep
  51. args += '-DCPPHTTPLIB_ZLIB_SUPPORT'
  52. endif
  53. brotli_deps = [dependency('libbrotlicommon', required: get_option('cpp-httplib_brotli'))]
  54. brotli_deps += dependency('libbrotlidec', required: get_option('cpp-httplib_brotli'))
  55. brotli_deps += dependency('libbrotlienc', required: get_option('cpp-httplib_brotli'))
  56. brotli_found_all = true
  57. foreach brotli_dep : brotli_deps
  58. if not brotli_dep.found()
  59. brotli_found_all = false
  60. endif
  61. endforeach
  62. if brotli_found_all
  63. deps += brotli_deps
  64. args += '-DCPPHTTPLIB_BROTLI_SUPPORT'
  65. endif
  66. cpp_httplib_dep = dependency('', required: false)
  67. if get_option('cpp-httplib_compile')
  68. python3 = find_program('python3')
  69. httplib_ch = custom_target(
  70. 'split',
  71. input: 'httplib.h',
  72. output: ['httplib.cc', 'httplib.h'],
  73. command: [python3, files('split.py'), '--out', meson.current_build_dir()],
  74. install: true,
  75. install_dir: [false, get_option('includedir')]
  76. )
  77. lib = library(
  78. 'cpp-httplib',
  79. sources: httplib_ch,
  80. dependencies: deps,
  81. cpp_args: args,
  82. version: version,
  83. soversion: version.split('.')[0] + '.' + version.split('.')[1],
  84. install: true
  85. )
  86. cpp_httplib_dep = declare_dependency(compile_args: args, dependencies: deps, link_with: lib, sources: httplib_ch[1])
  87. import('pkgconfig').generate(
  88. lib,
  89. description: 'A C++ HTTP/HTTPS server and client library',
  90. extra_cflags: args,
  91. url: 'https://github.com/yhirose/cpp-httplib',
  92. version: version
  93. )
  94. else
  95. install_headers('httplib.h')
  96. cpp_httplib_dep = declare_dependency(compile_args: args, dependencies: deps, include_directories: '.')
  97. import('pkgconfig').generate(
  98. name: 'cpp-httplib',
  99. description: 'A C++ HTTP/HTTPS server and client library',
  100. install_dir: get_option('datadir')/'pkgconfig',
  101. url: 'https://github.com/yhirose/cpp-httplib',
  102. version: version
  103. )
  104. endif
  105. meson.override_dependency('cpp-httplib', cpp_httplib_dep)
  106. if get_option('cpp-httplib_test')
  107. subdir('test')
  108. endif