3

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 in build/meson and not in the root.

Can I easily build zstd as a meson subproject for my C++ library?

oleksii
  • 35,458
  • 16
  • 93
  • 163

1 Answers1

1

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:

  1. create meson.build in root subprojects' dir

  2. move project(...) from zstd/build/meson/meson.build to this one

  3. add subdir, so it contains:

    project(...)

    subdir('build')

  4. drop one-line meson.build to zstd/build

    subdir('meson')

pmod
  • 10,450
  • 1
  • 37
  • 50
  • 1
    Right, I was trying to figure this one out, thanks for clarifying. I didn't want to deviate too much from the zstd source code and didn't want to keep track of what is changing upstream (if anything). So I made a patch to an official meson wrap database, hopefully, that can be accepted and I can just use a one-liner `subproject ('zstd')` with a wrap file. Meanwhile, I would just use an older version 1.3.3 available in the database, here's my PR https://github.com/mesonbuild/zstd/pull/4 for the newer version, from what I see someone will have to make a zipped patch manually – oleksii Sep 27 '20 at 19:24
  • @oleksii thanks, you can try ask this on meson googlegroup where you have better chance to reach authors: The Meson Build System . I haven't worked with wraps but from what I've read and found it's not possible to change dir - maybe it's worth feature request. If you do please let me know I'd be interested to know what's better option... – pmod Sep 28 '20 at 07:43