Skip to content

Improve pkg-config file generation for external BLAS/LAPACK dependencies #1109

@zoziha

Description

@zoziha

Description

Problem Statement

When building the Fortran Standard Library with external BLAS/LAPACK libraries, the generated fortran_stdlib.pc file includes absolute paths to the BLAS/LAPACK libraries. This is problematic for system packaging (e.g., MSYS2) where the library should reference system-wide installed libraries using standard pkg-config syntax.

Current Behavior

  • Absolute paths in pkg-config: The generated fortran_stdlib.pc file includes absolute paths to BLAS/LAPACK libraries, e.g., /path/to/libopenblas.dll or /path/to/mkl_core.dll
  • No pkg-config integration: The build system does not leverage existing pkg-config files for BLAS/LAPACK libraries
  • Packaging complexity: System packagers need to patch the generated pkg-config file

Root Cause

The current build system directly uses the absolute paths found by find_package(BLAS) and find_package(LAPACK) without considering if the BLAS/LAPACK vendor provides a pkg-config file.
(I know little about MKL and am not sure if it provides .pc files, while openblas has one.)

Proposed Solution

  1. Detect pkg-config files: Check if common BLAS/LAPACK vendors (e.g., OpenBLAS, Intel MKL) provide pkg-config files
  2. Use standard syntax: When a pkg-config file exists, use the Requires field instead of absolute paths
  3. Maintain compatibility: Fall back to absolute paths when no pkg-config file is available

Expected Behaviour

Current problematic output:

Libs: -L${libdir} -lfortran_stdlib /path/to/libopenblas.dll ...

Desired output:

Requires: openblas
Libs: -L${libdir} -lfortran_stdlib ...

or just

Libs: -L${libdir} -lfortran_stdlib -lopenblas ...
Cflags: -I${includedir} -I${moduledir} -I/folder/to/libopenblas.dll

Version of stdlib

0ede301

Platform and Architecture

Windows OS

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions