meson.build 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. project('coeurl', 'cpp',
  2. version : '0.1.1',
  3. license : 'MIT',
  4. meson_version : '>=0.54',
  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. #message(libcurl_proj.include_directories('libcurl'))
  73. #message(libcurl_proj.target('libcurl').path())
  74. message(libcurl_proj.target('libcurl').full_path())
  75. libcurl_dep = declare_dependency(include_directories: 'subprojects/curl-7.77.0/include', dependencies: libcurl_dep.partial_dependency(compile_args: true, link_args: true, links: true))
  76. #message(libcurl_proj.target('libcurl').get_variable('INTERFACE_INCLUDE_DIRECTORIES'))
  77. #message(libcurl_proj.get_variable('INTERFACE_INCLUDE_DIRECTORIES'))
  78. endif
  79. deps += [libcurl_dep]
  80. include = include_directories('include')
  81. defines = []
  82. if target_machine.system() == 'windows'
  83. defines += ['-DNOMINMAX', '-DWIN32_LEAN_AND_MEAN']
  84. endif
  85. if target_machine.system() == 'windows'
  86. cc = meson.get_compiler('c')
  87. deps += [
  88. cc.find_library('ws2_32', required: true), # socket functions
  89. cc.find_library('iphlpapi', required: true) # if_nametoindex needed for libevent
  90. ]
  91. endif
  92. lib = library('coeurl', ['lib/client.cpp', 'lib/request.cpp', 'lib/errors.cpp'],
  93. include_directories: include,
  94. cpp_args : defines,
  95. dependencies: deps,
  96. version: meson.project_version(),
  97. install : true)
  98. install_headers('include/coeurl/headers.hpp', 'include/coeurl/client.hpp', 'include/coeurl/request.hpp', 'include/coeurl/errors.hpp', subdir : 'coeurl')
  99. coeurl_dep = declare_dependency(include_directories: include, link_with: lib, dependencies: deps)
  100. meson.override_dependency('coeurl', coeurl_dep)
  101. if get_option('examples')
  102. subdir('examples')
  103. endif
  104. if get_option('tests')
  105. subdir('tests')
  106. endif
  107. pkg = import('pkgconfig')
  108. pkg.generate(lib,
  109. libraries : [lib],
  110. version : meson.project_version(),
  111. filebase : meson.project_name(),
  112. description : 'Simple library to do http requests asynchronously via CURL in C++.',
  113. url : 'https://nheko.im/nheko-reborn/coeurl')
  114. # No idea how to export working cmake config files, so don't do that for now
  115. #cmake = import('cmake')
  116. #cmake.write_basic_package_version_file(name: meson.project_name(), version: meson.project_version())
  117. #cmake.configure_package_config_file(
  118. # name: 'coeurl',
  119. # input: 'cmake/coeurl.cmake.in',
  120. # configuration: configuration_data()
  121. #)