| 1 |
project( |
| 2 |
'coeurl', |
| 3 |
'cpp', |
| 4 |
version: '0.3.2', |
| 5 |
license: 'MIT', |
| 6 |
meson_version: '>=0.55', |
| 7 |
default_options: [ |
| 8 |
'warning_level=3', |
| 9 |
'cpp_std=c++17', |
| 10 |
'curl:http=enabled', |
| 11 |
'curl:tool=disabled', |
| 12 |
'curl:tests=disabled', |
| 13 |
'curl:unittests=disabled', |
| 14 |
'curl:dict=disabled', |
| 15 |
'curl:file=disabled', |
| 16 |
'curl:ftp=disabled', |
| 17 |
'curl:gopher=disabled', |
| 18 |
'curl:imap=disabled', |
| 19 |
'curl:ipfs=disabled', |
| 20 |
'curl:ldap=disabled', |
| 21 |
'curl:ldaps=disabled', |
| 22 |
'curl:mqtt=disabled', |
| 23 |
'curl:pop3=disabled', |
| 24 |
'curl:rtmp=disabled', |
| 25 |
'curl:rtsp=disabled', |
| 26 |
'curl:smb=disabled', |
| 27 |
'curl:smtp=disabled', |
| 28 |
'curl:telnet=disabled', |
| 29 |
'curl:tftp=disabled', |
| 30 |
], |
| 31 |
) |
| 32 |
|
| 33 |
deps = [ |
| 34 |
dependency('threads', required: true), |
| 35 |
dependency('spdlog', required: true), |
| 36 |
dependency('libcurl', required: true), |
| 37 |
] |
| 38 |
|
| 39 |
|
| 40 |
libevent_dep = dependency( |
| 41 |
'libevent_core', |
| 42 |
required: get_option('wrap_mode') == 'nofallback', |
| 43 |
) |
| 44 |
if target_machine.system() != 'windows' |
| 45 |
libevent_threads_dep = dependency( |
| 46 |
'libevent_pthreads', |
| 47 |
required: get_option('wrap_mode') == 'nofallback', |
| 48 |
) |
| 49 |
endif |
| 50 |
|
| 51 |
if ( |
| 52 |
not libevent_dep.found() |
| 53 |
or not libevent_threads_dep.found() |
| 54 |
or get_option( |
| 55 |
'wrap_mode', |
| 56 |
) == 'forcefallback' |
| 57 |
or 'libevent' in get_option( |
| 58 |
'force_fallback_for', |
| 59 |
) |
| 60 |
) |
| 61 |
cmake = import('cmake') |
| 62 |
libevent_options = cmake.subproject_options() |
| 63 |
libevent_options.add_cmake_defines( |
| 64 |
{ |
| 65 |
'EVENT__LIBRARY_TYPE': 'STATIC', |
| 66 |
'BUILD_SHARED_LIBS': false, |
| 67 |
'BUILD_SHARED_AND_STATIC_LIBS': false, |
| 68 |
'EVENT__DISABLE_OPENSSL': 'ON', |
| 69 |
'EVENT__DISABLE_BENCHMARK': true, |
| 70 |
'EVENT__DISABLE_TESTS': true, |
| 71 |
'EVENT__DISABLE_REGRESS': true, |
| 72 |
'EVENT__DISABLE_SAMPLES': true, |
| 73 |
'EVENT__MSVC_STATIC_RUNTIME': ['mt', 'mtd', 'static_from_buildtype'].contains( |
| 74 |
get_option('b_vscrt'), |
| 75 |
), |
| 76 |
}, |
| 77 |
) |
| 78 |
if target_machine.system() != 'windows' |
| 79 |
libevent_options.add_cmake_defines( |
| 80 |
{ |
| 81 |
'CMAKE_C_FLAGS': '-fPIC', |
| 82 |
}, |
| 83 |
) |
| 84 |
endif |
| 85 |
libevent_options.set_override_option('werror', 'false') |
| 86 |
libevent_options.set_override_option('warning_level', '0') |
| 87 |
libevent_proj = cmake.subproject('libevent', options: libevent_options) |
| 88 |
libevent_dep = libevent_proj.dependency('event_core_static') |
| 89 |
|
| 90 |
if target_machine.system() == 'windows' |
| 91 |
# the cmake project links the thread support into the library directly... |
| 92 |
libevent_threads_dep = dependency('', required: false) |
| 93 |
else |
| 94 |
libevent_threads_dep = libevent_proj.dependency('event_pthreads_static') |
| 95 |
endif |
| 96 |
endif |
| 97 |
|
| 98 |
deps += [libevent_dep, libevent_threads_dep] |
| 99 |
|
| 100 |
include = include_directories('include') |
| 101 |
|
| 102 |
defines = [] |
| 103 |
if target_machine.system() == 'windows' |
| 104 |
defines += ['-DNOMINMAX', '-DWIN32_LEAN_AND_MEAN'] |
| 105 |
endif |
| 106 |
|
| 107 |
if target_machine.system() == 'windows' |
| 108 |
cc = meson.get_compiler('c') |
| 109 |
deps += [ |
| 110 |
cc.find_library('ws2_32', required: true), # socket functions |
| 111 |
cc.find_library('iphlpapi', required: true), # if_nametoindex needed for libevent |
| 112 |
] |
| 113 |
endif |
| 114 |
|
| 115 |
version_parts = meson.project_version().split('.') |
| 116 |
soversion = version_parts.get(0) + '.' + version_parts.get(1) |
| 117 |
|
| 118 |
lib = library( |
| 119 |
'coeurl', |
| 120 |
['lib/client.cpp', 'lib/request.cpp', 'lib/errors.cpp'], |
| 121 |
include_directories: include, |
| 122 |
cpp_args: defines, |
| 123 |
dependencies: deps, |
| 124 |
#version: meson.project_version(), |
| 125 |
soversion: soversion, |
| 126 |
install: true, |
| 127 |
) |
| 128 |
|
| 129 |
install_headers( |
| 130 |
'include/coeurl/headers.hpp', |
| 131 |
'include/coeurl/client.hpp', |
| 132 |
'include/coeurl/request.hpp', |
| 133 |
'include/coeurl/errors.hpp', |
| 134 |
subdir: 'coeurl', |
| 135 |
) |
| 136 |
|
| 137 |
coeurl_dep = declare_dependency( |
| 138 |
include_directories: include, |
| 139 |
link_with: lib, |
| 140 |
dependencies: deps, |
| 141 |
) |
| 142 |
meson.override_dependency('coeurl', coeurl_dep) |
| 143 |
|
| 144 |
if get_option('examples') |
| 145 |
subdir('examples') |
| 146 |
endif |
| 147 |
|
| 148 |
if get_option('tests') |
| 149 |
subdir('tests') |
| 150 |
endif |
| 151 |
|
| 152 |
pkg = import('pkgconfig') |
| 153 |
pkg.generate( |
| 154 |
lib, |
| 155 |
libraries: [lib], |
| 156 |
version: meson.project_version(), |
| 157 |
filebase: meson.project_name(), |
| 158 |
description: 'Simple library to do http requests asynchronously via CURL in C++.', |
| 159 |
url: 'https://nheko.im/nheko-reborn/coeurl', |
| 160 |
) |
| 161 |
|
| 162 |
# No idea how to export working cmake config files, so don't do that for now |
| 163 |
#cmake = import('cmake') |
| 164 |
#cmake.write_basic_package_version_file(name: meson.project_name(), version: meson.project_version()) |
| 165 |
#cmake.configure_package_config_file( |
| 166 |
# name: 'coeurl', |
| 167 |
# input: 'cmake/coeurl.cmake.in', |
| 168 |
# configuration: configuration_data() |
| 169 |
#) |