meson.build 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. if cxx.sizeof('void *') != 8
  19. if host_machine.system() == 'windows'
  20. error('unsupported architecture: cpp-httplib doesn\'t support 32-bit Windows. Please use a 64-bit compiler.')
  21. else
  22. warning('cpp-httplib doesn\'t support 32-bit platforms. Please use a 64-bit compiler.')
  23. endif
  24. endif
  25. # Check just in case downstream decides to edit the source
  26. # and add a project version
  27. version = meson.project_version()
  28. if version == 'undefined'
  29. version = cxx.get_define('CPPHTTPLIB_VERSION',
  30. prefix: '#include <httplib.h>',
  31. include_directories: include_directories('.')).strip('"')
  32. assert(version != '', 'failed to get version from httplib.h')
  33. endif
  34. deps = [dependency('threads')]
  35. args = []
  36. if get_option('tls').allowed()
  37. tls_found = false
  38. if get_option('tls_backend') == 'openssl'
  39. openssl_dep = dependency('openssl', version: '>=3.0.0', required: get_option('tls'))
  40. if openssl_dep.found()
  41. deps += openssl_dep
  42. args += '-DCPPHTTPLIB_OPENSSL_SUPPORT'
  43. tls_found = true
  44. endif
  45. else
  46. mbedtls_dep = dependency('mbedtls', required: get_option('tls'))
  47. mbedtlsx509_dep = dependency('mbedx509', required: get_option('tls'))
  48. mbedtlscrypto_dep = dependency('mbedcrypto', required: get_option('tls'))
  49. if mbedtls_dep.found() and mbedtlsx509_dep.found() and mbedtlscrypto_dep.found()
  50. deps += mbedtls_dep
  51. deps += mbedtlsx509_dep
  52. deps += mbedtlscrypto_dep
  53. args += '-DCPPHTTPLIB_MBEDTLS_SUPPORT'
  54. tls_found = true
  55. endif
  56. endif
  57. if tls_found and host_machine.system() == 'darwin'
  58. disable_macosx_certs = get_option('disable_macosx_automatic_root_certificates')
  59. if disable_macosx_certs
  60. args += '-DCPPHTTPLIB_DISABLE_MACOSX_AUTOMATIC_ROOT_CERTIFICATES'
  61. else
  62. macosx_keychain_dep = dependency('appleframeworks', modules: ['CFNetwork', 'CoreFoundation', 'Security'], required: true)
  63. deps += macosx_keychain_dep
  64. endif
  65. endif
  66. endif
  67. zlib_dep = dependency('zlib', required: get_option('zlib'))
  68. if zlib_dep.found()
  69. deps += zlib_dep
  70. args += '-DCPPHTTPLIB_ZLIB_SUPPORT'
  71. endif
  72. brotli_deps = [dependency('libbrotlicommon', required: get_option('brotli'))]
  73. brotli_deps += dependency('libbrotlidec', required: get_option('brotli'))
  74. brotli_deps += dependency('libbrotlienc', required: get_option('brotli'))
  75. brotli_found_all = true
  76. foreach brotli_dep : brotli_deps
  77. if not brotli_dep.found()
  78. brotli_found_all = false
  79. endif
  80. endforeach
  81. if brotli_found_all
  82. deps += brotli_deps
  83. args += '-DCPPHTTPLIB_BROTLI_SUPPORT'
  84. endif
  85. zstd_dep = dependency('libzstd', required: get_option('zstd'))
  86. if zstd_dep.found()
  87. deps += zstd_dep
  88. args += '-DCPPHTTPLIB_ZSTD_SUPPORT'
  89. endif
  90. async_ns_opt = get_option('non_blocking_getaddrinfo')
  91. if host_machine.system() == 'windows'
  92. async_ns_dep = cxx.find_library('ws2_32', required: async_ns_opt)
  93. elif host_machine.system() == 'darwin'
  94. async_ns_dep = dependency('appleframeworks', modules: ['CFNetwork', 'CoreFoundation'], required: async_ns_opt)
  95. else
  96. async_ns_dep = cxx.find_library('anl', required: async_ns_opt)
  97. endif
  98. if async_ns_dep.found()
  99. deps += async_ns_dep
  100. args += '-DCPPHTTPLIB_USE_NON_BLOCKING_GETADDRINFO'
  101. endif
  102. cpp_httplib_dep = dependency('', required: false)
  103. if get_option('compile')
  104. python3 = find_program('python3')
  105. httplib_ch = custom_target(
  106. 'split',
  107. input: 'httplib.h',
  108. output: ['httplib.cc', 'httplib.h'],
  109. command: [python3, files('split.py'), '--out', meson.current_build_dir()],
  110. install: true,
  111. install_dir: [false, get_option('includedir')]
  112. )
  113. lib = library(
  114. 'cpp-httplib',
  115. sources: httplib_ch,
  116. dependencies: deps,
  117. cpp_args: args,
  118. version: version,
  119. soversion: version.split('.')[0] + '.' + version.split('.')[1],
  120. install: true
  121. )
  122. cpp_httplib_dep = declare_dependency(compile_args: args, dependencies: deps, link_with: lib, sources: httplib_ch[1], version: version)
  123. import('pkgconfig').generate(
  124. lib,
  125. description: 'A C++ HTTP/HTTPS server and client library',
  126. extra_cflags: args,
  127. url: 'https://github.com/yhirose/cpp-httplib',
  128. version: version
  129. )
  130. else
  131. install_headers('httplib.h')
  132. cpp_httplib_dep = declare_dependency(compile_args: args, dependencies: deps, include_directories: '.', version: version)
  133. import('pkgconfig').generate(
  134. name: 'cpp-httplib',
  135. description: 'A C++ HTTP/HTTPS server and client library',
  136. install_dir: get_option('datadir')/'pkgconfig',
  137. url: 'https://github.com/yhirose/cpp-httplib',
  138. version: version
  139. )
  140. endif
  141. meson.override_dependency('cpp-httplib', cpp_httplib_dep)
  142. if get_option('test')
  143. subdir('test')
  144. endif