1
1
module fpm_meta_hdf5
2
2
use fpm_compiler, only: compiler_t, get_include_flag
3
- use fpm_strings, only: str_begins_with_str, str_ends_with
3
+ use fpm_strings, only: str_begins_with_str, str_ends_with, string_t
4
4
use fpm_filesystem, only: join_path
5
- use fpm_pkg_config, only: assert_pkg_config, pkgcfg_has_package, &
6
- pkgcfg_get_libs, pkgcfg_get_build_flags, pkgcfg_get_version, pkgcfg_list_all
5
+ use fpm_pkg_config, only: assert_pkg_config, pkgcfg_has_package, pkgcfg_list_all
7
6
use fpm_meta_base, only: metapackage_t, destroy
8
- use fpm_strings , only: string_t, split
7
+ use fpm_meta_util , only: add_pkg_config_compile_options, lib_get_trailing
9
8
use fpm_error, only: error_t, fatal_error
10
- use fpm_versioning, only: new_version
11
9
12
10
implicit none
13
11
@@ -74,37 +72,8 @@ subroutine init_hdf5(this,compiler,error)
74
72
return
75
73
end if
76
74
77
- ! > Get version
78
- log = pkgcfg_get_version(name,error)
75
+ call add_pkg_config_compile_options(this, name, include_flag, libdir, error)
79
76
if (allocated (error)) return
80
- allocate (this% version)
81
- call new_version(this% version,log% s,error)
82
- if (allocated (error)) return
83
-
84
- ! > Get libraries
85
- libs = pkgcfg_get_libs(name,error)
86
- if (allocated (error)) return
87
-
88
- libdir = " "
89
- do i= 1 ,size (libs)
90
-
91
- if (str_begins_with_str(libs(i)% s,' -l' )) then
92
- this% has_link_libraries = .true.
93
- this% link_libs = [this% link_libs, string_t(libs(i)% s(3 :))]
94
-
95
- else ! -L and others: concatenate
96
- this% has_link_flags = .true.
97
- this% link_flags = string_t(trim (this% link_flags% s)// ' ' // libs(i)% s)
98
-
99
- ! Also save library dir
100
- if (str_begins_with_str(libs(i)% s,' -L' )) then
101
- libdir = libs(i)% s(3 :)
102
- elseif (str_begins_with_str(libs(i)% s,' /LIBPATH' )) then
103
- libdir = libs(i)% s(9 :)
104
- endif
105
-
106
- end if
107
- end do
108
77
109
78
! Some pkg-config hdf5.pc (e.g. Ubuntu) don't include the commonly-used HL HDF5 libraries,
110
79
! so let's add them if they exist
@@ -148,22 +117,6 @@ subroutine init_hdf5(this,compiler,error)
148
117
end do
149
118
endif
150
119
151
- ! > Get compiler flags
152
- flags = pkgcfg_get_build_flags(name,.true. ,error)
153
- if (allocated (error)) return
154
-
155
- do i= 1 ,size (flags)
156
-
157
- if (str_begins_with_str(flags(i)% s,include_flag)) then
158
- this% has_include_dirs = .true.
159
- this% incl_dirs = [this% incl_dirs, string_t(flags(i)% s(len (include_flag)+ 1 :))]
160
- else
161
- this% has_build_flags = .true.
162
- this% flags = string_t(trim (this% flags% s)// ' ' // flags(i)% s)
163
- end if
164
-
165
- end do
166
-
167
120
! > Add HDF5 modules as external
168
121
this% has_external_modules = .true.
169
122
this% external_modules = [string_t(' h5a' ), &
@@ -189,49 +142,4 @@ subroutine init_hdf5(this,compiler,error)
189
142
string_t(' hdf5' )]
190
143
191
144
end subroutine init_hdf5
192
-
193
- ! > Given a library name and folder, find extension and prefix
194
- subroutine lib_get_trailing (lib_name ,lib_dir ,prefix ,suffix ,found )
195
- character (* ), intent (in ) :: lib_name,lib_dir
196
- character (:), allocatable , intent (out ) :: prefix,suffix
197
- logical , intent (out ) :: found
198
-
199
- character (* ), parameter :: extensions(* ) = [character (11 ) :: ' .dll.a' ,' .a' ,' .dylib' ,' .dll' ]
200
- logical :: is_file
201
- character (:), allocatable :: noext,tokens(:),path
202
- integer :: l,k
203
-
204
- ! Extract name with no extension
205
- call split(lib_name,tokens,' .' )
206
- noext = trim (tokens(1 ))
207
-
208
- ! Get library extension: find file name: NAME.a, NAME.dll.a, NAME.dylib, libNAME.a, etc.
209
- found = .false.
210
- suffix = " "
211
- prefix = " "
212
- with_pref: do l= 1 ,2
213
- if (l== 2 ) then
214
- prefix = " lib"
215
- else
216
- prefix = " "
217
- end if
218
- find_ext: do k= 1 ,size (extensions)
219
- path = join_path(lib_dir,prefix// noext// trim (extensions(k)))
220
- inquire (file= path,exist= is_file)
221
-
222
- if (is_file) then
223
- suffix = trim (extensions(k))
224
- found = .true.
225
- exit with_pref
226
- end if
227
- end do find_ext
228
- end do with_pref
229
-
230
- if (.not. found) then
231
- prefix = " "
232
- suffix = " "
233
- end if
234
-
235
- end subroutine lib_get_trailing
236
-
237
145
end module fpm_meta_hdf5
0 commit comments