meson.build 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. macosx_keychain_dep = dependency('appleframeworks', modules: ['CFNetwork', 'CoreFoundation', 'Security'], required: get_option('macosx_keychain'))
  59. if macosx_keychain_dep.found()
  60. deps += macosx_keychain_dep
  61. args += '-DCPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN'
  62. endif
  63. endif
  64. endif
  65. zlib_dep = dependency('zlib', required: get_option('zlib'))
  66. if zlib_dep.found()
  67. deps += zlib_dep
  68. args += '-DCPPHTTPLIB_ZLIB_SUPPORT'
  69. endif
  70. brotli_deps = [dependency('libbrotlicommon', required: get_option('brotli'))]
  71. brotli_deps += dependency('libbrotlidec', required: get_option('brotli'))
  72. brotli_deps += dependency('libbrotlienc', required: get_option('brotli'))
  73. brotli_found_all = true
  74. foreach brotli_dep : brotli_deps
  75. if not brotli_dep.found()
  76. brotli_found_all = false
  77. endif
  78. endforeach
  79. if brotli_found_all
  80. deps += brotli_deps
  81. args += '-DCPPHTTPLIB_BROTLI_SUPPORT'
  82. endif
  83. zstd_dep = dependency('libzstd', required: get_option('zstd'))
  84. if zstd_dep.found()
  85. deps += zstd_dep
  86. args += '-DCPPHTTPLIB_ZSTD_SUPPORT'
  87. endif
  88. async_ns_opt = get_option('non_blocking_getaddrinfo')
  89. if host_machine.system() == 'windows'
  90. async_ns_dep = cxx.find_library('ws2_32', required: async_ns_opt)
  91. elif host_machine.system() == 'darwin'
  92. async_ns_dep = dependency('appleframeworks', modules: ['CFNetwork', 'CoreFoundation'], required: async_ns_opt)
  93. else
  94. async_ns_dep = cxx.find_library('anl', required: async_ns_opt)
  95. endif
  96. if async_ns_dep.found()
  97. deps += async_ns_dep
  98. args += '-DCPPHTTPLIB_USE_NON_BLOCKING_GETADDRINFO'
  99. endif
  100. cpp_httplib_dep = dependency('', required: false)
  101. if get_option('compile')
  102. python3 = find_program('python3')
  103. httplib_ch = custom_target(
  104. 'split',
  105. input: 'httplib.h',
  106. output: ['httplib.cc', 'httplib.h'],
  107. command: [python3, files('split.py'), '--out', meson.current_build_dir()],
  108. install: true,
  109. install_dir: [false, get_option('includedir')]
  110. )
  111. lib = library(
  112. 'cpp-httplib',
  113. sources: httplib_ch,
  114. dependencies: deps,
  115. cpp_args: args,
  116. version: version,
  117. soversion: version.split('.')[0] + '.' + version.split('.')[1],
  118. install: true
  119. )
  120. cpp_httplib_dep = declare_dependency(compile_args: args, dependencies: deps, link_with: lib, sources: httplib_ch[1], version: version)
  121. import('pkgconfig').generate(
  122. lib,
  123. description: 'A C++ HTTP/HTTPS server and client library',
  124. extra_cflags: args,
  125. url: 'https://github.com/yhirose/cpp-httplib',
  126. version: version
  127. )
  128. else
  129. install_headers('httplib.h')
  130. cpp_httplib_dep = declare_dependency(compile_args: args, dependencies: deps, include_directories: '.', version: version)
  131. import('pkgconfig').generate(
  132. name: 'cpp-httplib',
  133. description: 'A C++ HTTP/HTTPS server and client library',
  134. install_dir: get_option('datadir')/'pkgconfig',
  135. url: 'https://github.com/yhirose/cpp-httplib',
  136. version: version
  137. )
  138. endif
  139. meson.override_dependency('cpp-httplib', cpp_httplib_dep)
  140. if get_option('test')
  141. subdir('test')
  142. endif