Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fortran packages using pkg-config #445

Open
7 tasks
ivan-pi opened this issue Apr 16, 2021 · 9 comments
Open
7 tasks

Fortran packages using pkg-config #445

ivan-pi opened this issue Apr 16, 2021 · 9 comments

Comments

@ivan-pi
Copy link
Member

ivan-pi commented Apr 16, 2021

I've created this issue to keep track of some of the (scientific) packages which provide a pkg-config file and could be candidates for testing with fpm.

You can see a list of package files already installed on your system with the command pkg-config --list-all.

@ivan-pi
Copy link
Member Author

ivan-pi commented Apr 16, 2021

Feel free to add more packages to the first post.

@awvwgk
Copy link
Member

awvwgk commented Apr 16, 2021

stdlib does provide a pc file and even some more or less transparent logic how it is generated:
https://github.com/fortran-lang/stdlib/blob/3621b03c5748b309113316168eae7b6ddc973851/config/CMakeLists.txt#L3-L13

@ivan-pi
Copy link
Member Author

ivan-pi commented Apr 17, 2021

Related to FFTW and also discussion #447, the default installation of FFTW will place a set of source files containing the interfaces to the C routines in /usr/include:

$ ls /usr/include/fftw* -l
-rw-r--r-- 1 root root  2447 Dez  9  2017 /usr/include/fftw3.f
-rw-r--r-- 1 root root 54596 Dez  9  2017 /usr/include/fftw3.f03
-rw-r--r-- 1 root root 31394 Dez  9  2017 /usr/include/fftw3.h
-rw-r--r-- 1 root root 26983 Dez  9  2017 /usr/include/fftw3l.f03
-rw-r--r-- 1 root root 25682 Dez  9  2017 /usr/include/fftw3q.f03

Now to bypass the whole issue of shipping Fortran modules, the FFTW manual recommends that users who want to import FFTW routines as a module, should define one themselves:

  module FFTW3
    use, intrinsic :: iso_c_binding
    include 'fftw3.f03'
  end module

However, since gfortran doesn't search /usr/include/, anyone who wants to use FFTW still needs to append the flag -I/usr/include.

Also the system installed .pc file is not geared towards Fortran users:

$ pkg-config --cflags fftw3

$ pkg-config --libs fftw3
-lfftw3

@awvwgk
Copy link
Member

awvwgk commented Apr 17, 2021

We would have to add --keep-system-cflags in case we detect GFortran to work around this issue.

❯ pkg-config fftw3 --cflags --keep-system-cflags
-I/usr/include 

@ivan-pi
Copy link
Member Author

ivan-pi commented Apr 17, 2021

It looks like you are using pkgconf (see https://github.com/pkgconf/pkgconf/blob/2fdc5f0081dcf22fa476767877d13097eb81e255/cli/main.c#L849)

On my installation:

$ pkg-config --version
0.29.1
$ pkg-config fftw3 --cflags --keep-system-cflags
Unknown option --keep-system-cflags

So the different command line options of pkg-config programs can potentially make a bigger mess.

This might also affect your reply to Milan in #439 (comment)

@awvwgk
Copy link
Member

awvwgk commented Apr 17, 2021

Arch Linux uses pkgconf (1.7.3) with symlinking it as pkg-config. This means we can't workaround this issue with GFortran by using pkg-config options because they won't be supported in all implementations.

Our alternatives for GFortran would be

  1. implement our own non-standard pkg-config to read the pc files in a GFortran friendly way
  2. manually detect the system include paths and append them to the compile arguments as -I options
  3. fix the bug in upstream GFortran

@awvwgk
Copy link
Member

awvwgk commented Apr 17, 2021

Another solution for FFTW3 with GFortran would be using the C preprocessor instead of the Fortran include directive with:

module fftw3
   use, intrinsic :: iso_c_binding
#include "fftw3.f03"
end module fftw3

@ivan-pi
Copy link
Member Author

ivan-pi commented Apr 17, 2021

That works, but the file needs to given the .F90 suffix in order to invoke the preprocessor automatically (for all compilers). In the long term, I would ultimately prefer the system fftw packages change their default install location (and suffix) of the interface files (unless we reach agreement that /usr/include/ is the right location for these).

Another option would be to offer an fftw3 module fpm package in a fortran-lang repository.

@arjenmarkus
Copy link
Member

Should this be of use, sometime ago I wrote a module to read pkg-config files, including substitution of macros.
See the attached file: pkgconfig.f90.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants