I want to use zstd compression library for my C++ library project. My build system is based on meson. My meson.build file looks like this
project('foo', 'cpp', default_options :
['cpp_std=c++17', 'buildtype=release'],
version : '0.1', license: 'MIT')
subproject('zstd', default_options: 'builddir=build/meson')
I made a zstd meson wrap file subprojects/zstd.wrap
[wrap-file]
directory = zstd-1.4.5
source_url = https://github.com/facebook/zstd/releases/download/v1.4.5/zstd-1.4.5.tar.gz
source_filename = zstd-1.4.5.tar.gz
source_hash = 98e91c7c6bf162bf90e4e70fdbc41a8188b9fa8de5ad840c401198014406ce9e
When I run meson compile I get this error
../meson.build:5:0: ERROR: Subproject exists but has no meson.build file
The issue seems to be in the fact that zstd uses CMAKE as a default build system and meson file lives in build/meson subfolder, and not in the root where meson expects it. I tried:
- Using
default_options: 'builddir=build/meson'for the subproject, but that had no effect - Building zstd using CMAKE integration but failed with other errors and it made the setup more complicated
- Making a patch to move zstd meson build files up two directories to the root of
zstd, but that required more dependencies and later failed with paths resolution, as zstd expects files inbuild/mesonand not in the root.
Can I easily build zstd as a meson subproject for my C++ library?
There is no option builddir in meson, and with default_options you can anyway set only that subproject's project options (zstd/build/meson/meson_options.txt). Thus, I think, the only way to solve this is to create a patch and it should be rather simple:
create meson.build in root subprojects' dir
move project(...) from zstd/build/meson/meson.build to this one
add subdir, so it contains:
project(...)
subdir('build')
drop one-line meson.build to zstd/build
subdir('meson')