Search code examples
macosglibpangomeson-buildharfbuzz

How to set MACOSX_DEPLOYMENT_TARGET in meson for pango, harfbuzz, glib, etc


I am trying to compile libs for usage on OS X 10.8 and newer. When I am building for example libpng library, I am using this script and it works (resulting library is compatible with OS X 10.8 and newer)

export MACOSX_DEPLOYMENT_TARGET=10.8
./configure --disable-dependency-tracking --enable-shared
make check

And it works.

But here is the problem. I am not able to make it work for anythink what uses meson build system. For example pango:

mkdir build
export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig"
export MACOSX_DEPLOYMENT_TARGET=10.8
meson -Dintrospection=true -Duse_fontconfig=true --default-library=shared --buildtype=release . build
cd build
ninja

It fails in ninja step with error:

[70/128] Generating Pango-1.0.gir with a custom command
FAILED: pango/Pango-1.0.gir 
/usr/local/Cellar/gobject-introspection/1.64.1_2/bin/g-ir-scanner --no-libtool --namespace=Pango --nsversion=1.0 --warn-all --output pango/Pango-1.0.gir --c-include=pango/pango.h --quiet -I/Users/USER/pango-1.45.3/pango -I/Users/USER/pango-1.45.3/build/pango -I./. -I../. -I./pango/. -I../pango/. --filelist=/Users/USER/pango-1.45.3/build/pango/libpango-1.0.0.dylib.p/Pango_1.0_gir_filelist --include=HarfBuzz-0.0 --include=GObject-2.0 --include=cairo-1.0 --symbol-prefix=pango --identifier-prefix=Pango --pkg-export=pango --cflags-begin -D_POSIX_C_SOURCE=200809L -D_POSIX_THREAD_SAFE_FUNCTIONS -D_GNU_SOURCE -I./. -I../. -I./pango/. -I../pango/. -I/usr/local/Cellar/glib/2.64.4/include/glib-2.0 -I/usr/local/Cellar/glib/2.64.4/lib/glib-2.0/include -I/usr/local/opt/gettext/include -I/usr/local/Cellar/pcre/8.44/include -I/usr/local/Cellar/libffi/3.3/include -I/usr/local/Cellar/glib/2.64.4/include -I/usr/local/Cellar/fribidi/1.0.10/include/fribidi -I/usr/local/Cellar/harfbuzz/2.6.8/include/harfbuzz -I/usr/local/opt/freetype/include/freetype2 -I/usr/local/Cellar/graphite2/1.3.14/include -I/usr/local/Cellar/fontconfig/2.13.1/include -I/usr/local/Cellar/cairo/1.16.0_3/include/cairo -I/usr/local/Cellar/pixman/0.40.0/include/pixman-1 -I/usr/local/Cellar/libpng/1.6.37/include/libpng16 -I/usr/local/Cellar/gobject-introspection/1.64.1_2/include/gobject-introspection-1.0 --cflags-end --add-include-path=/usr/local/Cellar/gobject-introspection/1.64.1_2/share/gir-1.0 --library pango-1.0 -L/Users/USER/pango-1.45.3/build/pango -L/usr/local/Cellar/fribidi/1.0.10/lib -L/usr/local/Cellar/harfbuzz/2.6.8/lib -L/usr/local/opt/freetype/lib -L/usr/local/Cellar/cairo/1.16.0_3/lib --extra-library=m -L/usr/local/Cellar/glib/2.64.4/lib -L/usr/local/opt/gettext/lib --extra-library=glib-2.0 --extra-library=intl --extra-library=gobject-2.0 --extra-library=gio-2.0 -L/usr/local/Cellar/fribidi/1.0.10/lib --extra-library=fribidi -L/usr/local/Cellar/harfbuzz/2.6.8/lib --extra-library=harfbuzz -L/usr/local/Cellar/fontconfig/2.13.1/lib -L/usr/local/opt/freetype/lib --extra-library=fontconfig --extra-library=freetype -L/usr/local/Cellar/cairo/1.16.0_3/lib --extra-library=cairo -L/usr/local/Cellar/gobject-introspection/1.64.1_2/lib --extra-library=girepository-1.0 --sources-top-dirs /Users/USER/pango-1.45.3/subprojects/ --sources-top-dirs /Users/USER/pango-1.45.3/build/subprojects/
Traceback (most recent call last):
  File "/usr/local/Cellar/gobject-introspection/1.64.1_2/bin/g-ir-scanner", line 104, in <module>
    sys.exit(scanner_main(sys.argv))
  File "/usr/local/Cellar/gobject-introspection/1.64.1_2/lib/gobject-introspection/giscanner/scannermain.py", line 590, in scanner_main
    ss, filenames = create_source_scanner(options, args)
  File "/usr/local/Cellar/gobject-introspection/1.64.1_2/lib/gobject-introspection/giscanner/scannermain.py", line 463, in create_source_scanner
    ss.parse_files(filenames)
  File "/usr/local/Cellar/gobject-introspection/1.64.1_2/lib/gobject-introspection/giscanner/sourcescanner.py", line 262, in parse_files
    self._parse(headers)
  File "/usr/local/Cellar/gobject-introspection/1.64.1_2/lib/gobject-introspection/giscanner/sourcescanner.py", line 308, in _parse
    cc.preprocess(tmp_name_cpp,
  File "/usr/local/Cellar/gobject-introspection/1.64.1_2/lib/gobject-introspection/giscanner/ccompiler.py", line 272, in preprocess
    self.compiler.preprocess(source=source,
  File "/usr/local/Cellar/[email protected]/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/distutils/unixccompiler.py", line 107, in preprocess
    self.spawn(pp_args)
  File "/usr/local/Cellar/[email protected]/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/distutils/ccompiler.py", line 910, in spawn
    spawn(cmd, dry_run=self.dry_run)
  File "/usr/local/Cellar/[email protected]/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/distutils/spawn.py", line 36, in spawn
    _spawn_posix(cmd, search_path, dry_run=dry_run)
  File "/usr/local/Cellar/[email protected]/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/distutils/spawn.py", line 111, in _spawn_posix
    raise DistutilsPlatformError(my_msg)
distutils.errors.DistutilsPlatformError: $MACOSX_DEPLOYMENT_TARGET mismatch: now "10.8" but "11.0" during configure
[75/128] Generating symbol file pango/libpango-1.0.0.dylib.p/libpango-1.0.0.dylib.symbols
ninja: build stopped: subcommand failed.

How can I specify MACOSX_DEPLOYMENT_TARGET during configure?


Solution

  • I found the solution. I believe that there is a bug gobject-introspection in /usr/local/Cellar/gobject-introspection/1.64.1_2/bin/g-ir-scanner to be exact.

    If you will do this:

    export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig"
    export MACOSX_DEPLOYMENT_TARGET=10.8
    export MIN_SUPPORTED_MACOSX_DEPLOYMENT_TARGET=10.8
    export LDFLAGS='-mmacosx-version-min=10.8'
    export CFLAGS='-stdlib=libc++ -mmacosx-version-min=10.8'
    export CXXFLAGS='-stdlib=libc++ -mmacosx-version-min=10.8'
    
    mkdir build
    meson -Dintrospection=true -Duse_fontconfig=true --default-library=shared --buildtype=release . build
    cd build
    ninja
    

    You will get an error.

    But if you will omit the MACOSX_DEPLOYMENT_TARGET it will work without problem and resulting library is built for OS X 10.8 and newer. In example I'll unset the MACOSX_DEPLOYMENT_TARGET env variable:

    export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig"
    export MACOSX_DEPLOYMENT_TARGET=10.8
    export MIN_SUPPORTED_MACOSX_DEPLOYMENT_TARGET=10.8
    export LDFLAGS='-mmacosx-version-min=10.8'
    export CFLAGS='-stdlib=libc++ -mmacosx-version-min=10.8'
    export CXXFLAGS='-stdlib=libc++ -mmacosx-version-min=10.8'
    
    #unset MACOSX_DEPLOYMENT_TARGET env variable which broke the build before
    unset MACOSX_DEPLOYMENT_TARGET
    
    mkdir build
    meson -Dintrospection=true -Duse_fontconfig=true --default-library=shared --buildtype=release . build
    cd build
    ninja
    

    Now it works