fortran-lang / fpm

Fortran Package Manager (fpm)
https://fpm.fortran-lang.org
MIT License
868 stars 97 forks source link

links added to specific executables are not added at the end of the loader command #811

Open urbanjost opened 1 year ago

urbanjost commented 1 year ago

Description

See https://fortran-lang.discourse.group/t/how-to-get-external-libs-provided-to-fpm-in-the-right-place/4873/5

Either the library built by the package or library names specified by a link= directive in the fpm.toml manifest file need moved. The questions about where values specified via the environment variables or the --link-flag switch might be a more difficult question, as more than just library names can be specified which there might be a reason to not be at the end of the load command.

So whether additional features to control the placement of options is required or not, the default should be modeled after make(1) defaults:

        $(FC) -o $@ $(FFLAGS) $(LDFLAGS) $(FOBJ) $(LIBS)

athough whether another switch --link to match the link= directive, or an ability to specify a build rule more like make(1) or changing the use of the project library to another -Lbuild/... -lname option instead of a full pathname is a better solution is a good question.

A single-pass loader with positionally-sensitive keys is difficult to model using M_CLI2 (which is insensitive to the order of parameters). If that is required M_CLI2 can be changed relatively easily to be aware of order other than appending multiple occurrences of the same keyword from left to right; or perhaps the --link-flag could take a before: or after: key, etc. But links specified for a specific executable in the fpm.toml file should go at the end of the loader command; as at least currently only library names are allowed (ie, 'link="-L/somewhere -lmylib"' is not allowed, just 'links=["mylib"]'

Expected Behaviour

expected library names to be added at the end of the loader command; or at least for the project library pathname to precede the library names.

Version of fpm

all

Platform and Architecture

all

Additional Information

No response

urbanjost commented 1 year ago

I made a version that seems to work, but is not clean as it duplicates some of the files in complex builds. Found it is not as straight forward as I hoped. I am going to continue testing what I do have to see if it breaks, as having dependencies with external dependencies and building multiple modules and having multiple executables with different dependencies might break it, for starters.

I did it by changing fpm_targets.f90. It is going to take me while to make sure that is the right place and if it works with cases I do not even have (yet); so if anyone knows exactly where to tweak this let me know; as I think this is going to take a while to do right.