Skip to content

CFLAGS/LDFLAGS containing `"-Xpreprocessor <foobar>" from dependencies are breaking ARGS and LINK_ARGS in build.ninja #15764

@dimpase

Description

@dimpase

Describe the bug
dependencies might have flag combos such as -Xpreprocessor -fopenmp in pkg-config files (one example would be OpenBLAS on
macOS in Homebrew, see https://formulae.brew.sh/formula/openblas). With certain extra dependencies we see -Xpreprocessor getting
separated from -fopenmp in build.ninja ARGS and/or LINK_ARGS.

A short reproducer showing incorrect LINK_ARGS generation attached. There one gets -Xpreprocessor -fopenmp swapped around.

build tp: c_LINKER tp.p/tp.c.o | /usr/lib64/libopenblas.so
 LINK_ARGS = -Wl,--as-needed -Wl,--no-undefined -fopenmp -Xpreprocessor /usr/lib64/libopenblas.so -framework Foobar

In some other cases on sagemath/sage#41626 we see -Xpreprocessor getting to the end of ARGS or LINK_FLAGS,
or right in front of -framework.

To Reproduce
On a x86_64 Linux (you might need to modify openblas.cp on different platforms)
create a project by putting the following meson.build, tp.c and (modified) openblas.pc (these files are also
attached at the end as a tar archive)

project(
  'tp',
  'c',
  meson_version : '>= 1.3.0',
  version : '0.1',
  default_options : ['warning_level=3'],
)

openmp = dependency('openmp', required: false, disabler: true)
blas = dependency('openblas')
dependencies = [
openmp, blas
]

sources = [
  'tp.c',
]

exe = executable(
  'tp',
  sources,
  dependencies : dependencies,
  install : true,
)

test('basic', exe)

tp.c:

#include <omp.h>
#include <openblas/cblas.h>

#define PROJECT_NAME "tp"

int main(int argc, char **argv) {
    return 0;
}

openblas.pc

libdir=/usr/lib64
libprefix=
libnamesuffix=
libsuffix=
includedir=/usr/include/openblas
omp_opt=-Xpreprocessor -fopenmp
openblas_config= USE_64BITINT= DYNAMIC_ARCH= DYNAMIC_OLDER= NO_CBLAS= NO_LAPACK= NO_LAPACKE= NO_AFFINITY=1 USE_OPENMP=1 HASWELL MAX_THREADS=64
version=0.3.33
extralib=-lm -lpthread -lgfortran -lm -lpthread -lgfortran -lgomp
Name: openblas
Description: OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version
Version: ${version}
URL: https://github.com/xianyi/OpenBLAS
Libs: ${omp_opt} -L${libdir} -l${libprefix}openblas${libsuffix}${libnamesuffix} -framework Foobar
Libs.private: ${extralib}
Cflags: ${omp_opt} -I${includedir}  -framework Foobar

and run

export PKG_CONFIG_PATH=.
meson setup build

Then inspect the generated build/build.ninja.

Expected behavior
Preserved token -Xpreprocessor -fopenmp in LINK_ARGS

system parameters

  • Is this a cross build or just a plain native build (for the same computer)? - plain.
  • what operating system (e.g. MacOS Catalina, Windows 10, CentOS 8.0, Ubuntu 18.04, etc.): macOS 26, Linux x86_64 (Gentoo)
  • what Python version are you using e.g. 3.8.0 - 3.13.13.
  • what meson --version: 1.11.1
  • what ninja --version if it's a Ninja build: n/a (no need to run ninja to see the error)

bugpro.tgz

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions