Add Meson support

Pistache now supports the Meson build system!

It is required to use Meson >=0.57
because previous versions can't read files,
and it wouldn't be possible to parse version.txt
to set the correct parameters in the .pc files and the shared library.
Such a recent version allows the users to
switch between the system-provided library
and the one they have in the subprojects folder
without even having to specify the fallback kwarg in dependency().

Since Meson provides builtin options for enabling code coverage
and PIC in static libraries there's no need for the PISTACHE_PIC option
and the "Profile target" mentioned by dennisjenkins75 in #840,
as they can be controlled with b_staticpic and b_coverage, respectively.

The cpp_std option is also set to c++17
even if the current minimun standard is C++14 because of #859.

If you don't know what Meson is, I highly recommend you to check it out.
parent 4f199506
......@@ -34,3 +34,10 @@
.vscode
.idea
# Clangd cache
.cache
# Meson Wrap DB cache
/subprojects/*
!/subprojects/*.wrap
This diff is collapsed.
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: pistache
Upstream-Contact: Dennis Jenkins <dennis.jenkins.75@gmail.com>
Source: https://github.com/oktal/pistache.git
Source: https://github.com/pistacheio/pistache.git
Comment: Upstream's Debianization.
Files: *
......
version=4
opts=filenamemangle=s/.+\/v?(\d\S+)\.tar\.bz2/pistache-$1\.tar\.bz2/ \
https://github.com/oktal/pistache/tags .*/?(\d+\.\d+.\d+)\.tar\.bz2
https://github.com/pistacheio/pistache/tags .*/?(\d+\.\d+.\d+)\.tar\.bz2
......@@ -2,6 +2,7 @@ OUTPUT_DIRECTORY = @CMAKE_CURRENT_BINARY_DIR@/docs/
INPUT = @CMAKE_SOURCE_DIR@/README.md @CMAKE_SOURCE_DIR@/src/ @CMAKE_SOURCE_DIR@/include/ @CMAKE_SOURCE_DIR@/examples/ @CMAKE_SOURCE_DIR@/docs/
USE_MDFILE_AS_MAINPAGE = @CMAKE_SOURCE_DIR@/README.md
EXCLUDE_PATTERNS = */.git/*
EXCLUDE_PATTERNS += */subprojects/*
EXCLUDE_PATTERNS += */tests/*
EXCLUDE_PATTERNS += */third-party/*
......
doxygen = find_program('doxygen', required: true)
configure_file(input: 'Doxyfile.in', output: 'Doxyfile', configuration: {
'CMAKE_CURRENT_BINARY_DIR': meson.current_build_dir(),
'CMAKE_SOURCE_DIR': meson.project_source_root(),
'PROJECT_NAME': meson.project_name()
})
run_target('docs', command: [doxygen, meson.current_build_dir()/'Doxyfile'])
rapidjson = subproject('rapidjson')
rapidjson_dep = dependency('rapidjson', fallback: ['rapidjson', 'rapidjson_dep'], required: true)
pistache_example_files = [
'custom_header',
'hello_server',
'http_client',
'http_server_shutdown',
'http_server',
'rest_server'
]
foreach example_name : pistache_example_files
executable('run'+example_name, example_name+'.cc', dependencies: pistache_static_dep)
endforeach
executable('run_rest_description', 'rest_description.cc', dependencies: [pistache_static_dep, rapidjson_dep])
subdir('pistache')
configure_file(input: 'version.h.in', output: 'version.h', configuration: version_data_conf, install: get_option('PISTACHE_INSTALL'), install_dir: prefix/get_option('includedir')/'pistache')
install_headers([
'async.h',
'base64.h',
'client.h',
'common.h',
'config.h',
'cookie.h',
'description.h',
'endpoint.h',
'errors.h',
'flags.h',
'http_defs.h',
'http.h',
'http_header.h',
'http_headers.h',
'iterator_adapter.h',
'listener.h',
'log.h',
'mailbox.h',
'mime.h',
'net.h',
'optional.h',
'os.h',
'peer.h',
'prototype.h',
'reactor.h',
'route_bind.h',
'router.h',
'ssl_wrappers.h',
'stream.h',
'string_logger.h',
'string_view.h',
'tcp.h',
'timer_pool.h',
'transport.h',
'type_checkers.h',
'typeid.h',
'utils.h',
'view.h'
], subdir: 'pistache')
install_subdir('thirdparty', install_dir: prefix/get_option('includedir')/'pistache')
project(
'pistache',
'cpp',
version: '0.0.0',
license: 'Apache-2.0',
default_options: [
'cpp_std=c++17',
'buildtype=release',
'b_ndebug=if-release',
'b_lto=false',
'warning_level=3'
],
meson_version: '>=0.57.0'
)
compiler = meson.get_compiler('cpp')
compiler_id = compiler.get_id()
prefix = get_option('prefix')
pc_libs = ['-lpistache', '-pthread']
# Wrapping arguments inside a call to get_supported_arguments so that only supported arguments get applied
# No need for -Wall -Wextra -Wpedantic, since warning_level is 3
add_project_arguments(compiler.get_supported_arguments(['-Wconversion', '-Wno-missing-field-initializers']), language: 'cpp')
# No need for --coverage, since b_coverage is set
if get_option('b_coverage')
add_global_arguments(compiler.get_supported_arguments(['-fstack-protector-all', '--param=ssp-buffer-size=4']), language: 'cpp')
endif
##### BEGIN CheckAtomic.cmake
is_libatomic_needed = false
cxx_atomics_check_code = '''
#include <atomic>
std::atomic<int> x;
int main(){return x;}
'''
has_working_cxx_atomics = compiler.compiles(cxx_atomics_check_code, name: 'std::atomic')
if (compiler_id.contains('clang') or compiler_id.contains('gcc')) and not has_working_cxx_atomics
assert(compiler.has_function('__atomic_fetch_add_4', args: '-latomic'), 'Host compiler appears to require libatomic, but cannot find it.')
has_working_cxx_atomics = compiler.compiles(cxx_atomics_check_code, args: '-latomic', name: 'std::atomic with libatomic')
assert(has_working_cxx_atomics, 'Host compiler must support std::atomic!')
is_libatomic_needed = true
endif
cxx_atomics64_check_code = '''
#include <atomic>
#include <cstdint>
std::atomic<uint64_t> x(0);
int main() {
uint64_t i = x.load(std::memory_order_relaxed);
return 0;
}
'''
has_working_cxx_atomics64 = compiler.compiles(cxx_atomics64_check_code, name: 'std::atomic<uint64_t>')
if not has_working_cxx_atomics64
assert(compiler.has_function('__atomic_load_8', args: '-latomic'), 'Host compiler appears to require libatomic for 64-bit operations, but cannot find it.')
has_working_cxx_atomics = compiler.compiles(cxx_atomics_check_code, args: '-latomic', name: 'std::atomic<uint64_t> with libatomic')
assert(has_working_cxx_atomics, 'Host compiler must support 64-bit std::atomic')
is_libatomic_needed = true
endif
##### END CheckAtomic.cmake
if is_libatomic_needed
pc_libs += '-latomic'
endif
deps_libpistache = [dependency('threads')]
if get_option('PISTACHE_USE_SSL')
deps_libpistache += dependency('openssl', required: true)
pc_libs += ['-lssl', '-lcrypto']
endif
fs = import('fs')
version_data_raw = fs.read('version.txt').split('\n')
version_data_conf = configuration_data()
foreach _ : version_data_raw
if _ != ''
__ = _.split(' ')
version_data_conf.set(__[0], __[-1])
endif
endforeach
pistache_version_str = '.'.join([version_data_conf.get_unquoted('VERSION_MAJOR'), version_data_conf.get_unquoted('VERSION_MINOR'), version_data_conf.get_unquoted('VERSION_PATCH')])
pistache_soversion_str = '.'.join([version_data_conf.get_unquoted('SONAME_VERSION_MAJOR'), version_data_conf.get_unquoted('SONAME_VERSION_MINOR')])
configure_file(input: 'libpistache.pc.in', output: 'libpistache.pc', install: get_option('PISTACHE_INSTALL'), install_dir: get_option('includedir')/'pistache', configuration: {
'prefix': prefix,
'exec_prefix': prefix/get_option('bindir'),
'libdir': prefix/get_option('libdir'),
'libs': ' '.join(pc_libs),
'includedir': prefix/get_option('includedir'),
'version': pistache_version_str+'-git'+version_data_conf.get_unquoted('VERSION_GIT_DATE')
})
incl_pistache = include_directories('include')
subdir('include')
subdir('src')
if get_option('PISTACHE_BUILD_TESTS')
subdir('tests')
endif
if get_option('PISTACHE_BUILD_EXAMPLES')
subdir('examples')
endif
if get_option('PISTACHE_BUILD_DOCS')
subdir('docs')
endif
option('PISTACHE_BUILD_TESTS', type: 'boolean', value: false, description: 'build tests alongside the project')
option('PISTACHE_ENABLE_NETWORK_TESTS', type: 'boolean', value: true, description: 'if tests are built, run ones needing network access')
option('PISTACHE_BUILD_EXAMPLES', type: 'boolean', value: false, description: 'build examples alongside the project')
option('PISTACHE_BUILD_DOCS', type: 'boolean', value: false, description: 'build docs alongside the project')
option('PISTACHE_INSTALL', type: 'boolean', value: true, description: 'add pistache as install target (recommended)')
option('PISTACHE_USE_SSL', type: 'boolean', value: false, description: 'add support for SSL server')
......@@ -26,10 +26,8 @@ Otherwise, here's how to build and install the latest release:
```shell
git clone --recurse-submodules https://github.com/pistacheio/pistache.git
cd pistache
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make
sudo make install
meson setup build
meson install -C build
```
Also, Pistache does not support Windows yet, but should work fine under [WSL](https://docs.microsoft.com/windows/wsl/about).
......
......@@ -246,7 +246,7 @@ void Transport::asyncWriteImpl(Fd fd) {
}
// EBADF can happen when the HTTP parser, in the case of
// an error, closes fd before the entire request is processed.
// https://github.com/oktal/pistache/issues/501
// https://github.com/pistacheio/pistache/issues/501
else if (errno == EBADF || errno == EPIPE || errno == ECONNRESET) {
wq.pop_front();
toWrite.erase(fd);
......
pistache_common_src = [
'common'/'base64.cc',
'common'/'cookie.cc',
'common'/'description.cc',
'common'/'http.cc',
'common'/'http_defs.cc',
'common'/'http_header.cc',
'common'/'http_headers.cc',
'common'/'mime.cc',
'common'/'net.cc',
'common'/'os.cc',
'common'/'peer.cc',
'common'/'reactor.cc',
'common'/'stream.cc',
'common'/'string_logger.cc',
'common'/'tcp.cc',
'common'/'timer_pool.cc',
'common'/'transport.cc',
'common'/'utils.cc'
]
pistache_server_src = [
'server'/'endpoint.cc',
'server'/'listener.cc',
'server'/'router.cc'
]
pistache_client_src = [
'client'/'client.cc'
]
if get_option('PISTACHE_USE_SSL')
add_project_arguments('-DPISTACHE_USE_SSL', language: 'cpp')
endif
libpistache_static = static_library(
'pistache', pistache_common_src+pistache_server_src+pistache_client_src,
include_directories: incl_pistache,
dependencies: deps_libpistache,
install: get_option('PISTACHE_INSTALL'),
pic: get_option('b_staticpic')
)
libpistache_shared = shared_library(
'pistache', pistache_common_src+pistache_server_src+pistache_client_src,
version: pistache_version_str,
soversion: pistache_soversion_str,
include_directories: incl_pistache,
dependencies: deps_libpistache,
install: get_option('PISTACHE_INSTALL')
)
pistache_static_dep = declare_dependency(link_with: libpistache_static, include_directories: incl_pistache)
pistache_shared_dep = declare_dependency(link_with: libpistache_shared, include_directories: incl_pistache)
if get_option('default_library') == 'static'
meson.override_dependency('pistache', pistache_static_dep)
else
meson.override_dependency('pistache', pistache_shared_dep)
endif
[wrap-file]
directory = googletest-release-1.10.0
source_url = https://github.com/google/googletest/archive/release-1.10.0.zip
source_filename = gtest-1.10.0.zip
source_hash = 94c634d499558a76fa649edb13721dce6e98fb1e7018dfaeba3cd7a083945e91
patch_url = https://wrapdb.mesonbuild.com/v1/projects/gtest/1.10.0/1/get_zip
patch_filename = gtest-1.10.0-1-wrap.zip
patch_hash = 04ff14e8880e4e465f6260221e9dfd56fea6bc7cce4c4aff0dc528e4a2c8f514
[wrap-file]
directory = rapidjson-1.1.0
source_url = https://github.com/Tencent/rapidjson/archive/v1.1.0.zip
source_filename = rapidjson-1.1.0.zip
source_hash = 8e00c38829d6785a2dfb951bb87c6974fa07dfe488aa5b25deec4b8bc0f6a3ab
patch_url = https://wrapdb.mesonbuild.com/v1/projects/rapidjson/1.1.0/1/get_zip
patch_filename = rapidjson-1.1.0-1-wrap.zip
patch_hash = 7e651680dc74da51b4d0ca4bd3de5d1cf2143dd6d81421b97a43d67536a84486
configure_file(input: 'server.crt', output: 'server.crt', copy: true)
configure_file(input: 'server.key', output: 'server.key', copy: true)
configure_file(input: 'client.key', output: 'client.key', copy: true)
configure_file(input: 'client.crt', output: 'client.crt', copy: true)
configure_file(input: 'rootCA.crt', output: 'rootCA.crt', copy: true)
configure_file(input: 'server_from_intermediate_with_chain.crt', output: 'server_from_intermediate_with_chain.crt', copy: true)
configure_file(input: 'server_from_intermediate.crt', output: 'server_from_intermediate.crt', copy: true)
configure_file(input: 'server_from_intermediate.key', output: 'server_from_intermediate.key', copy: true)
configure_file(input: 'intermediateCA.crt', output: 'intermediateCA.crt', copy: true)
curl_dep = dependency('libcurl', required: true)
gtest_main_dep = dependency('gtest', main: true, required: true, fallback: ['gtest', 'gtest_main_dep'])
valgrind = find_program('valgrind', required: false)
gcov = find_program('gcov', required: false)
cppcheck = find_program('cppcheck', required: false)
if cppcheck.found()
cppcheck_args = ['--enable=all','-DCPPCHECK','--suppress=*:third-party*','--suppress=*:tests*','--suppress=noExplicitConstructor:include/pistache/optional.h']
else
warning('can\'t find Cppcheck')
endif
# TODO
pistache_test_files = [
'mime_test',
'headers_test',
'async_test',
'typeid_test',
'router_test',
'cookie_test',
'cookie_test_2',
'cookie_test_3',
'view_test',
'http_parsing_test',
'http_uri_test',
'http_server_test',
'http_client_test',
'listener_test',
'request_size_test',
'streaming_test',
'rest_server_test',
'string_view_test',
'mailbox_test',
'stream_test',
'reactor_test',
'threadname_test',
'optional_test',
'log_api_test',
'string_logger_test'
]
if get_option('PISTACHE_ENABLE_NETWORK_TESTS')
pistache_test_files += 'net_test'
endif
if get_option('PISTACHE_USE_SSL')
pistache_test_files += 'https_server_test'
subdir('certs')
endif
foreach test_name : pistache_test_files
test(
test_name,
executable(
'run_'+test_name,
test_name+'.cc',
dependencies: [
pistache_shared_dep,
gtest_main_dep,
curl_dep
]
),
timeout: 60,
workdir: meson.current_build_dir(),
is_parallel: false
)
endforeach
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment