|
| 1 | +module fpm_meta_netcdf |
| 2 | + use fpm_compiler, only: compiler_t, get_include_flag |
| 3 | + use fpm_meta_base, only: metapackage_t, destroy |
| 4 | + use fpm_meta_util, only: add_pkg_config_compile_options |
| 5 | + use fpm_pkg_config, only: assert_pkg_config, pkgcfg_has_package, pkgcfg_list_all |
| 6 | + use fpm_strings, only: string_t |
| 7 | + use fpm_error, only: error_t, fatal_error |
| 8 | + |
| 9 | + implicit none |
| 10 | + |
| 11 | + private |
| 12 | + |
| 13 | + public :: init_netcdf |
| 14 | + |
| 15 | + contains |
| 16 | + |
| 17 | + !> Initialize NetCDF metapackage for the current system |
| 18 | + subroutine init_netcdf(this,compiler,error) |
| 19 | + class(metapackage_t), intent(inout) :: this |
| 20 | + type(compiler_t), intent(in) :: compiler |
| 21 | + type(error_t), allocatable, intent(out) :: error |
| 22 | + |
| 23 | + logical :: s |
| 24 | + character(len=:), allocatable :: include_flag, libdir |
| 25 | + |
| 26 | + include_flag = get_include_flag(compiler,"") |
| 27 | + |
| 28 | + !> Cleanup |
| 29 | + call destroy(this) |
| 30 | + allocate(this%link_libs(0),this%incl_dirs(0),this%external_modules(0)) |
| 31 | + this%link_flags = string_t("") |
| 32 | + this%flags = string_t("") |
| 33 | + |
| 34 | + !> Assert pkg-config is installed |
| 35 | + if (.not.assert_pkg_config()) then |
| 36 | + call fatal_error(error, 'netcdf metapackage requires pkg-config') |
| 37 | + return |
| 38 | + end if |
| 39 | + |
| 40 | + if (.not. pkgcfg_has_package('netcdf')) then |
| 41 | + call fatal_error(error,'pkg-config could not find a suitable netcdf package.') |
| 42 | + end if |
| 43 | + call add_pkg_config_compile_options(this, 'netcdf', include_flag, libdir, error) |
| 44 | + if (allocated(error)) return |
| 45 | + |
| 46 | + if (.not. pkgcfg_has_package('netcdf-fortran')) then |
| 47 | + call fatal_error(error, & |
| 48 | + 'pkg-config could not find a suitable netcdf-fortran package.') |
| 49 | + end if |
| 50 | + call add_pkg_config_compile_options(this, 'netcdf-fortran', include_flag, libdir, error) |
| 51 | + if (allocated(error)) return |
| 52 | + |
| 53 | + |
| 54 | + !> Add NetCDF modules as external |
| 55 | + this%has_external_modules = .true. |
| 56 | + this%external_modules = [string_t('netcdf')] |
| 57 | + |
| 58 | + print *, 'NetCDF metapackage initialized successfully.' |
| 59 | + |
| 60 | + end subroutine init_netcdf |
| 61 | +end module fpm_meta_netcdf |
0 commit comments