Skip to content

Commit 559b9b0

Browse files
committed
hdf5 *dash* fortran
1 parent 78e8649 commit 559b9b0

File tree

1 file changed

+84
-6
lines changed

1 file changed

+84
-6
lines changed

src/fpm_meta.f90

Lines changed: 84 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,20 +1690,24 @@ subroutine init_hdf5(this,compiler,error)
16901690
type(compiler_t), intent(in) :: compiler
16911691
type(error_t), allocatable, intent(out) :: error
16921692

1693-
integer :: i
1694-
logical :: s
1693+
character(*), parameter :: find_hl(*) = &
1694+
[character(11) :: '_hl_fortran','hl_fortran','_fortran','_hl']
1695+
character(*), parameter :: candidates(5) = &
1696+
[character(15) :: 'hdf5_hl_fortran','hdf5-hl-fortran','hdf5_fortran','hdf5-fortran',&
1697+
'hdf5_hl','hdf5','hdf5-serial']
1698+
1699+
integer :: i,j,k
1700+
logical :: s,found_hl(size(find_hl))
16951701
type(string_t) :: log
1696-
type(string_t), allocatable :: libs(:),flags(:),modules(:)
1702+
type(string_t), allocatable :: libs(:),flags(:),modules(:),non_fortran(:)
16971703
character(len=:), allocatable :: name,module_flag,include_flag
1698-
character(*), parameter :: candidates(5) = &
1699-
[character(15) :: 'hdf5_hl_fortran','hdf5_fortran','hdf5_hl','hdf5','hdf5-serial']
17001704

17011705
module_flag = get_module_flag(compiler,"")
17021706
include_flag = get_include_flag(compiler,"")
17031707

17041708
!> Cleanup
17051709
call destroy(this)
1706-
allocate(this%link_libs(0),this%incl_dirs(0),this%external_modules(0))
1710+
allocate(this%link_libs(0),this%incl_dirs(0),this%external_modules(0),non_fortran(0))
17071711
this%link_flags = string_t("")
17081712
this%flags = string_t("")
17091713

@@ -1765,6 +1769,80 @@ subroutine init_hdf5(this,compiler,error)
17651769
end if
17661770
end do
17671771

1772+
! Some pkg-config hdf5.pc (e.g. Ubuntu) don't include the commonly-used HL HDF5 libraries,
1773+
! so let's add them if they exist
1774+
do i=1,size(this%link_libs)
1775+
1776+
found_hl = .false.
1777+
1778+
if (.not.str_ends_with(this%link_libs(i)%s, find_hl)) then
1779+
1780+
finals: do k=1,size(find_hl)
1781+
do j=1,size(this%link_libs)
1782+
if (str_begins_with_str(this%link_libs(j)%s,this%link_libs(i)%s) .and. &
1783+
str_ends_with(this%link_libs(j)%s,find_hl(k))) then
1784+
found_hl(k) = .true.
1785+
cycle finals
1786+
end if
1787+
end do
1788+
end do finals
1789+
1790+
! For each of the missing libraries, if there is a file,
1791+
!
1792+
1793+
1794+
print *, this%link_libs(i)%s,' does not end: ',found_hl
1795+
1796+
end if
1797+
1798+
!
1799+
! for larg in self.get_link_args():
1800+
! lpath = Path(larg)
1801+
! # some pkg-config hdf5.pc (e.g. Ubuntu) don't include the commonly-used HL HDF5 libraries,
1802+
! # so let's add them if they exist
1803+
! # additionally, some pkgconfig HDF5 HL files are malformed so let's be sure to find HL anyway
1804+
! if lpath.is_file():
1805+
! hl = []
1806+
! if language == 'cpp':
1807+
! hl += ['_hl_cpp', '_cpp']
1808+
! elif language == 'fortran':
1809+
! hl += ['_hl_fortran', 'hl_fortran', '_fortran']
1810+
! hl += ['_hl'] # C HL library, always needed
1811+
!
1812+
! suffix = '.' + lpath.name.split('.', 1)[1] # in case of .dll.a
1813+
! for h in hl:
1814+
! hlfn = lpath.parent / (lpath.name.split('.', 1)[0] + h + suffix)
1815+
! if hlfn.is_file():
1816+
! link_args.append(str(hlfn))
1817+
! # HDF5 C libs are required by other HDF5 languages
1818+
! link_args.append(larg)
1819+
! else:
1820+
! link_args.append(larg)
1821+
!
1822+
1823+
end do
1824+
1825+
!
1826+
! # additionally, some pkgconfig HDF5 HL files are malformed so let's be sure to find HL anyway
1827+
! if lpath.is_file():
1828+
! hl = []
1829+
! if language == 'cpp':
1830+
! hl += ['_hl_cpp', '_cpp']
1831+
! elif language == 'fortran':
1832+
! hl += ['_hl_fortran', 'hl_fortran', '_fortran']
1833+
! hl += ['_hl'] # C HL library, always needed
1834+
!
1835+
! suffix = '.' + lpath.name.split('.', 1)[1] # in case of .dll.a
1836+
! for h in hl:
1837+
! hlfn = lpath.parent / (lpath.name.split('.', 1)[0] + h + suffix)
1838+
! if hlfn.is_file():
1839+
! link_args.append(str(hlfn))
1840+
! # HDF5 C libs are required by other HDF5 languages
1841+
! link_args.append(larg)
1842+
! else:
1843+
! link_args.append(larg)
1844+
! link_args.append(larg)
1845+
17681846
!> Get compiler flags
17691847
flags = pkgcfg_get_build_flags(name,.true.,error)
17701848
if (allocated(error)) return

0 commit comments

Comments
 (0)