build(meson): always install a pkg-config file (#1182)

A pkg-config file was previously installed only if cpp-httplib was being
built as a compiled library.

Since architecture-independent .pc files
can exist in /usr/share/pkgconfig, it can be useful to install one even
when installing the header-only version (for example, it could be used
by third party projects to easily find out if cpp-httplib is installed
and its version, using something like Meson's `dependency()` or CMake's

The change makes the Meson build behave a bit more like the CMake one,
as it also always installs a CMake Config file, but here the pkg-config
file gets installed to the correct architecture-independent directory
(`datadir` represents /usr/share on Linux and simiar systems).

Lastly, I made some minor cleanups.
Andrea Pappacoda 7 months ago committed by GitHub
parent 894fcc8e02
commit 8ecdb11979
No known key found for this signature in database
  1. 15
  2. 2

@ -19,12 +19,13 @@ project(
# Check just in case downstream decides to edit the source
# and add a project version
version = meson.project_version()
python = import('python').find_installation('python3')
python3 = find_program('python3')
if version == 'undefined'
# Meson doesn't have regular expressions, but since it is implemented
# in python we can be sure we can use it to parse the file manually
version = run_command(
python, '-c', 'import re; raw_version ="User\-Agent.*cpp\-httplib/([0-9]+\.?)+", open("httplib.h").read()).group(0); print("([0-9]+\\.?)+", raw_version).group(0))'
python3, '-c', 'import re; raw_version ="User\-Agent.*cpp\-httplib/([0-9]+\.?)+", open("httplib.h").read()).group(0); print("([0-9]+\\.?)+", raw_version).group(0))',
check: true
@ -68,7 +69,7 @@ if get_option('cpp-httplib_compile')
input: 'httplib.h',
output: ['', 'httplib.h'],
command: [python, files(''), '--out', meson.current_build_dir()],
command: [python3, files(''), '--out', meson.current_build_dir()],
install: true,
install_dir: [false, get_option('includedir')]
@ -92,6 +93,14 @@ if get_option('cpp-httplib_compile')
cpp_httplib_dep = declare_dependency(compile_args: args, dependencies: deps, include_directories: include_directories('.'))
name: 'cpp-httplib',
description: 'A C++ HTTP/HTTPS server and client library',
install_dir: join_paths(get_option('datadir'), 'pkgconfig'),
url: '',
version: version
if meson.version().version_compare('>=0.54.0')

@ -5,5 +5,5 @@
option('cpp-httplib_openssl', type: 'feature', value: 'auto', description: 'Enable OpenSSL support')
option('cpp-httplib_zlib', type: 'feature', value: 'auto', description: 'Enable zlib support')
option('cpp-httplib_brotli', type: 'feature', value: 'auto', description: 'Enable Brotli support')
option('cpp-httplib_compile', type: 'boolean', value: false, description: 'Split the header into a compilable header & source file (requires Python 3)')
option('cpp-httplib_compile', type: 'boolean', value: false, description: 'Split the header into a compilable header & source file')
option('cpp-httplib_test', type: 'boolean', value: false, description: 'Build tests')