meson.build 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. openssl_dep = dependency('openssl', version: '>=3.0.0', required: get_option('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: ['CFNetwork', 'CoreFoundation', 'Security'], required: get_option('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('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('brotli'))]
  54. brotli_deps += dependency('libbrotlidec', required: get_option('brotli'))
  55. brotli_deps += dependency('libbrotlienc', required: get_option('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. zstd_dep = dependency('libzstd', required: get_option('zstd'))
  67. if zstd_dep.found()
  68. deps += zstd_dep
  69. args += '-DCPPHTTPLIB_ZSTD_SUPPORT'
  70. endif
  71. async_ns_opt = get_option('non_blocking_getaddrinfo')
  72. if host_machine.system() == 'windows'
  73. async_ns_dep = cxx.find_library('ws2_32', required: async_ns_opt)
  74. elif host_machine.system() == 'darwin'
  75. async_ns_dep = dependency('appleframeworks', modules: ['CFNetwork', 'CoreFoundation'], required: async_ns_opt)
  76. else
  77. async_ns_dep = cxx.find_library('anl', required: async_ns_opt)
  78. endif
  79. if async_ns_dep.found()
  80. deps += async_ns_dep
  81. args += '-DCPPHTTPLIB_USE_NON_BLOCKING_GETADDRINFO'
  82. endif
  83. cpp_httplib_dep = dependency('', required: false)
  84. if get_option('compile')
  85. python3 = find_program('python3')
  86. httplib_ch = custom_target(
  87. 'split',
  88. input: 'httplib.h',
  89. output: ['httplib.cc', 'httplib.h'],
  90. command: [python3, files('split.py'), '--out', meson.current_build_dir()],
  91. install: true,
  92. install_dir: [false, get_option('includedir')]
  93. )
  94. lib = library(
  95. 'cpp-httplib',
  96. sources: httplib_ch,
  97. dependencies: deps,
  98. cpp_args: args,
  99. version: version,
  100. soversion: version.split('.')[0] + '.' + version.split('.')[1],
  101. install: true
  102. )
  103. cpp_httplib_dep = declare_dependency(compile_args: args, dependencies: deps, link_with: lib, sources: httplib_ch[1], version: version)
  104. import('pkgconfig').generate(
  105. lib,
  106. description: 'A C++ HTTP/HTTPS server and client library',
  107. extra_cflags: args,
  108. url: 'https://github.com/yhirose/cpp-httplib',
  109. version: version
  110. )
  111. else
  112. install_headers('httplib.h')
  113. cpp_httplib_dep = declare_dependency(compile_args: args, dependencies: deps, include_directories: '.', version: version)
  114. import('pkgconfig').generate(
  115. name: 'cpp-httplib',
  116. description: 'A C++ HTTP/HTTPS server and client library',
  117. install_dir: get_option('datadir')/'pkgconfig',
  118. url: 'https://github.com/yhirose/cpp-httplib',
  119. version: version
  120. )
  121. endif
  122. meson.override_dependency('cpp-httplib', cpp_httplib_dep)
  123. if get_option('test')
  124. subdir('test')
  125. endif