@@ -1690,20 +1690,24 @@ subroutine init_hdf5(this,compiler,error)
1690
1690
type (compiler_t), intent (in ) :: compiler
1691
1691
type (error_t), allocatable , intent (out ) :: error
1692
1692
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))
1695
1701
type (string_t) :: log
1696
- type (string_t), allocatable :: libs(:),flags(:),modules(:)
1702
+ type (string_t), allocatable :: libs(:),flags(:),modules(:),non_fortran(:)
1697
1703
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' ]
1700
1704
1701
1705
module_flag = get_module_flag(compiler," " )
1702
1706
include_flag = get_include_flag(compiler," " )
1703
1707
1704
1708
! > Cleanup
1705
1709
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 ) )
1707
1711
this% link_flags = string_t(" " )
1708
1712
this% flags = string_t(" " )
1709
1713
@@ -1765,6 +1769,80 @@ subroutine init_hdf5(this,compiler,error)
1765
1769
end if
1766
1770
end do
1767
1771
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
+
1768
1846
! > Get compiler flags
1769
1847
flags = pkgcfg_get_build_flags(name,.true. ,error)
1770
1848
if (allocated (error)) return
0 commit comments