meson.build 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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.63.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. deps = [dependency('threads')]
  28. args = []
  29. openssl_dep = dependency('openssl', version: '>=3.0.0', required: get_option('cpp-httplib_openssl'))
  30. if openssl_dep.found()
  31. deps += openssl_dep
  32. args += '-DCPPHTTPLIB_OPENSSL_SUPPORT'
  33. if host_machine.system() == 'darwin'
  34. macosx_keychain_dep = dependency('appleframeworks', modules: ['CoreFoundation', 'Security'], required: get_option('cpp-httplib_macosx_keychain'))
  35. if macosx_keychain_dep.found()
  36. deps += macosx_keychain_dep
  37. args += '-DCPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN'
  38. endif
  39. endif
  40. endif
  41. zlib_dep = dependency('zlib', required: get_option('cpp-httplib_zlib'))
  42. if zlib_dep.found()
  43. deps += zlib_dep
  44. args += '-DCPPHTTPLIB_ZLIB_SUPPORT'
  45. endif
  46. brotli_deps = [dependency('libbrotlicommon', required: get_option('cpp-httplib_brotli'))]
  47. brotli_deps += dependency('libbrotlidec', required: get_option('cpp-httplib_brotli'))
  48. brotli_deps += dependency('libbrotlienc', required: get_option('cpp-httplib_brotli'))
  49. brotli_found_all = true
  50. foreach brotli_dep : brotli_deps
  51. if not brotli_dep.found()
  52. brotli_found_all = false
  53. endif
  54. endforeach
  55. if brotli_found_all
  56. deps += brotli_deps
  57. args += '-DCPPHTTPLIB_BROTLI_SUPPORT'
  58. endif
  59. async_ns_opt = get_option('cpp-httplib_non_blocking_getaddrinfo')
  60. if host_machine.system() == 'windows'
  61. async_ns_dep = cxx.find_library('ws2_32', required: async_ns_opt)
  62. elif host_machine.system() == 'darwin'
  63. async_ns_dep = dependency('appleframeworks', modules: ['CFNetwork'], required: async_ns_opt)
  64. else
  65. async_ns_dep = cxx.find_library('anl', required: async_ns_opt)
  66. endif
  67. if async_ns_dep.found()
  68. deps += async_ns_dep
  69. args += '-DCPPHTTPLIB_USE_NON_BLOCKING_GETADDRINFO'
  70. endif
  71. cpp_httplib_dep = dependency('', required: false)
  72. if get_option('cpp-httplib_compile')
  73. python3 = find_program('python3')
  74. httplib_ch = custom_target(
  75. 'split',
  76. input: 'httplib.h',
  77. output: ['httplib.cc', 'httplib.h'],
  78. command: [python3, files('split.py'), '--out', meson.current_build_dir()],
  79. install: true,
  80. install_dir: [false, get_option('includedir')]
  81. )
  82. lib = library(
  83. 'cpp-httplib',
  84. sources: httplib_ch,
  85. dependencies: deps,
  86. cpp_args: args,
  87. version: version,
  88. soversion: version.split('.')[0] + '.' + version.split('.')[1],
  89. install: true
  90. )
  91. cpp_httplib_dep = declare_dependency(compile_args: args, dependencies: deps, link_with: lib, sources: httplib_ch[1], version: version)
  92. import('pkgconfig').generate(
  93. lib,
  94. description: 'A C++ HTTP/HTTPS server and client library',
  95. extra_cflags: args,
  96. url: 'https://github.com/yhirose/cpp-httplib',
  97. version: version
  98. )
  99. else
  100. install_headers('httplib.h')
  101. cpp_httplib_dep = declare_dependency(compile_args: args, dependencies: deps, include_directories: '.', version: version)
  102. import('pkgconfig').generate(
  103. name: 'cpp-httplib',
  104. description: 'A C++ HTTP/HTTPS server and client library',
  105. install_dir: get_option('datadir')/'pkgconfig',
  106. url: 'https://github.com/yhirose/cpp-httplib',
  107. version: version
  108. )
  109. endif
  110. meson.override_dependency('cpp-httplib', cpp_httplib_dep)
  111. if get_option('cpp-httplib_test')
  112. subdir('test')
  113. endif