Building the Fortran stdlib with Meson?

Hello! I was wondering if anyone has been building the stdlib with Meson. In particular, I’ve been attempting to use Meson’s CMake module to build the stdlib as a CMake-based dependency. However, I run into an issue where the compiler (gfortran) ends up being called in an invalid way (with multiple -J options). I’m wondering if others have been compiling the stdlib with Meson as the primary build system, and there’s just some configuration I need to change. Or if there’s some part of the stdlib’s CMake configuration that makes it incompatible with Meson’s CMake module. Or something else.

A minimal example of this issue is simple. The repository of the example can be found here: GitHub - golmschenk/meson_fortran_stdlib. However, it’s just two small files. The meson.build which looks like:

project('meson_fortran_stdlib', 'fortran')

fortran_compiler = meson.get_compiler('fortran')

cmake = import('cmake')

fortran_stdlib = cmake.subproject('fortran_stdlib')
fortran_stdlib_dependency = fortran_stdlib.dependency('fortran_stdlib')

And the .wrap file in the subprojects directory which explains to Meson where to find the stdlib source files:

[wrap-git]
url = https://github.com/fortran-lang/stdlib.git
revision = fb4ca801f0c8e0ed09f9d137c620676fa348ebdd
depth = 1

The resulting error during the build looks like:

[57/123] Compiling Fortran object subprojects/fortran_stdlib/libtest_drive_lib.a.p/89665cd3cd59bf740a2e3bbbe807994591eb3475___CMake_build__deps_test-drive-src_src_testdrive_version.f90.o
FAILED: subprojects/fortran_stdlib/libtest_drive_lib.a.p/89665cd3cd59bf740a2e3bbbe807994591eb3475___CMake_build__deps_test-drive-src_src_testdrive_version.f90.o subprojects/fortran_stdlib/libtest_drive_lib.a.p/testdrive_version.mod 
gfortran -Isubprojects/fortran_stdlib/libtest_drive_lib.a.p -Isubprojects/fortran_stdlib -I../subprojects/fortran_stdlib -Isubprojects/fortran_stdlib/__CMake_build/_deps/test-drive-build/include -I../subprojects/fortran_stdlib/__CMake_build/_deps/test-drive-build/include -Isubprojects/fortran_stdlib/__CMake_build -I../subprojects/fortran_stdlib/__CMake_build -fdiagnostics-color=always -Wall -O0 -g -fimplicit-none -ffree-line-length-132 -O2 -g -DNDEBUG -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk -J_deps/test-drive-build/include -fPIC -DWITH_QP=1 -DWITH_XDP=0 -Jsubprojects/fortran_stdlib/libtest_drive_lib.a.p -o subprojects/fortran_stdlib/libtest_drive_lib.a.p/89665cd3cd59bf740a2e3bbbe807994591eb3475___CMake_build__deps_test-drive-src_src_testdrive_version.f90.o -c /Users/golmschenk/Code/meson_fortran_stdlib/builddir/subprojects/fortran_stdlib/__CMake_build/_deps/test-drive-src/src/testdrive_version.f90
f951: Fatal Error: gfortran: Only one '-J' option allowed

with minor differences if I’m building it on another machine (this build was on macOS, but I encounter the same issue on a Linux machine). I also tried disabling testing for the build to see if it was only occurring for test files, but a similar error occurs later in such as case.

If anyone has been using Meson with the stdlib, I would be interested to know what their configuration is. Otherwise, if someone has some insight about the build systems or compiler configurations as to how to resolve this, that would be great. Thank you for your time!