meson.build 4.1 KB

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