meson.build 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. project('coeurl', 'cpp',
  2. version : '0.3.1',
  3. license : 'MIT',
  4. meson_version : '>=0.55',
  5. default_options : ['warning_level=3', 'cpp_std=c++17']
  6. )
  7. deps = [
  8. dependency('threads', required: true),
  9. dependency('spdlog', required: true)
  10. ]
  11. libcurl_dep = dependency('libcurl', required: get_option('wrap_mode') == 'nofallback')
  12. libevent_dep = dependency('libevent_core', required: get_option('wrap_mode') == 'nofallback',)
  13. if target_machine.system() == 'windows'
  14. libevent_threads_dep = dependency('libevent_windows', required: get_option('wrap_mode') == 'nofallback',)
  15. else
  16. libevent_threads_dep = dependency('libevent_pthreads', required: get_option('wrap_mode') == 'nofallback',)
  17. endif
  18. if (not libevent_dep.found()
  19. or not libevent_threads_dep.found()
  20. or get_option('wrap_mode') == 'forcefallback'
  21. or 'libevent' in get_option('force_fallback_for'))
  22. cmake = import('cmake')
  23. libevent_options = cmake.subproject_options()
  24. libevent_options.add_cmake_defines({
  25. 'EVENT__LIBRARY_TYPE': 'STATIC',
  26. 'BUILD_SHARED_LIBS': false,
  27. 'BUILD_SHARED_AND_STATIC_LIBS': false,
  28. 'EVENT__DISABLE_OPENSSL': true,
  29. 'EVENT__DISABLE_BENCHMARK': true,
  30. 'EVENT__DISABLE_TESTS': true,
  31. 'EVENT__DISABLE_REGRESS': true,
  32. 'EVENT__DISABLE_SAMPLES': true,
  33. 'EVENT__MSVC_STATIC_RUNTIME': ['mt', 'mtd', 'static_from_buildtype'].contains(get_option('b_vscrt')),
  34. })
  35. if target_machine.system() != 'windows'
  36. libevent_options.add_cmake_defines({
  37. 'CMAKE_C_FLAGS': '-fPIC',
  38. })
  39. endif
  40. libevent_options.set_override_option('werror', 'false')
  41. libevent_options.set_override_option('warning_level', '0')
  42. libevent_proj = cmake.subproject('libevent', options: libevent_options)
  43. libevent_dep = libevent_proj.dependency('event_core_static')
  44. if target_machine.system() == 'windows'
  45. # the cmake project links the thread support into the library directly...
  46. libevent_threads_dep = dependency('', required : false)
  47. else
  48. libevent_threads_dep = libevent_proj.dependency('event_pthreads_static')
  49. endif
  50. endif
  51. deps += [libevent_dep, libevent_threads_dep]
  52. if (not libcurl_dep.found()
  53. or get_option('wrap_mode') == 'forcefallback'
  54. or 'libcurl' in get_option('force_fallback_for'))
  55. cmake = import('cmake')
  56. libcurl_options = cmake.subproject_options()
  57. libcurl_options.add_cmake_defines({
  58. 'BUILD_SHARED_LIBS': false,
  59. 'BUILD_SHARED_AND_STATIC_LIBS': false,
  60. 'HTTP_ONLY': true,
  61. 'CMAKE_USE_LIBSSH2': false,
  62. })
  63. if target_machine.system() != 'windows'
  64. libcurl_options.add_cmake_defines({
  65. 'CMAKE_C_FLAGS': '-fPIC',
  66. })
  67. endif
  68. libcurl_options.set_override_option('werror', 'false')
  69. libcurl_options.set_override_option('warning_level', '0')
  70. libcurl_proj = cmake.subproject('curl', options: libcurl_options)
  71. libcurl_dep = libcurl_proj.dependency('libcurl')
  72. endif
  73. deps += [libcurl_dep]
  74. include = include_directories('include')
  75. defines = []
  76. if target_machine.system() == 'windows'
  77. defines += ['-DNOMINMAX', '-DWIN32_LEAN_AND_MEAN']
  78. endif
  79. if target_machine.system() == 'windows'
  80. cc = meson.get_compiler('c')
  81. deps += [
  82. cc.find_library('ws2_32', required: true), # socket functions
  83. cc.find_library('iphlpapi', required: true) # if_nametoindex needed for libevent
  84. ]
  85. endif
  86. version_parts = meson.project_version().split('.')
  87. soversion = version_parts.get(0) + '.' + version_parts.get(1)
  88. lib = library('coeurl', ['lib/client.cpp', 'lib/request.cpp', 'lib/errors.cpp'],
  89. include_directories: include,
  90. cpp_args : defines,
  91. dependencies: deps,
  92. #version: meson.project_version(),
  93. soversion: soversion,
  94. install : true)
  95. install_headers('include/coeurl/headers.hpp', 'include/coeurl/client.hpp', 'include/coeurl/request.hpp', 'include/coeurl/errors.hpp', subdir : 'coeurl')
  96. coeurl_dep = declare_dependency(include_directories: include, link_with: lib, dependencies: deps)
  97. meson.override_dependency('coeurl', coeurl_dep)
  98. if get_option('examples')
  99. subdir('examples')
  100. endif
  101. if get_option('tests')
  102. subdir('tests')
  103. endif
  104. pkg = import('pkgconfig')
  105. pkg.generate(lib,
  106. libraries : [lib],
  107. version : meson.project_version(),
  108. filebase : meson.project_name(),
  109. description : 'Simple library to do http requests asynchronously via CURL in C++.',
  110. url : 'https://nheko.im/nheko-reborn/coeurl')
  111. # No idea how to export working cmake config files, so don't do that for now
  112. #cmake = import('cmake')
  113. #cmake.write_basic_package_version_file(name: meson.project_name(), version: meson.project_version())
  114. #cmake.configure_package_config_file(
  115. # name: 'coeurl',
  116. # input: 'cmake/coeurl.cmake.in',
  117. # configuration: configuration_data()
  118. #)