Populate settings with parsed values and environment fallbacks.
This routine centralizes:
- build_dir, profile, features,
- Fortran/C/C++ toolchain selection (FC, CC, CXX, AR),
- Common compile and link flags (--flag, --c-flag, --cxx-flag, --link-flag).
Environment variables are consulted only when the corresponding CLI option is empty.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(fpm_build_settings), | intent(inout) | :: | settings | |||
| character(len=*), | intent(in) | :: | build_dir | |||
| logical, | intent(in) | :: | prune | |||
| character(len=*), | intent(in) | :: | profile | |||
| type(string_t), | intent(in), | allocatable | :: | features(:) | ||
| character(len=*), | intent(in) | :: | compiler_in | |||
| character(len=*), | intent(in) | :: | c_compiler_in | |||
| character(len=*), | intent(in) | :: | cxx_compiler_in | |||
| character(len=*), | intent(in) | :: | archiver_in | |||
| character(len=*), | intent(in) | :: | flag_in | |||
| character(len=*), | intent(in) | :: | cflag_in | |||
| character(len=*), | intent(in) | :: | cxxflag_in | |||
| character(len=*), | intent(in) | :: | ldflag_in |
subroutine init_build_settings(settings, build_dir, prune, profile, features, compiler_in, c_compiler_in, cxx_compiler_in, archiver_in, flag_in, cflag_in, cxxflag_in, ldflag_in) class(fpm_build_settings), intent(inout) :: settings character(len=*), intent(in) :: build_dir logical, intent(in) :: prune character(len=*), intent(in) :: profile type(string_t), allocatable, intent(in) :: features(:) character(len=*), intent(in) :: compiler_in, c_compiler_in, cxx_compiler_in, archiver_in character(len=*), intent(in) :: flag_in, cflag_in, cxxflag_in, ldflag_in character(len=:), allocatable :: v character(len=2048) :: buf integer :: n, stat settings%verbose = .false. settings%prune = prune if (len_trim(build_dir) > 0) then settings%build_dir = trim(build_dir) end if if (len_trim(profile) > 0) settings%profile = trim(profile) if (allocated(settings%features)) deallocate(settings%features) if (allocated(features)) then if (size(features) > 0) then allocate(settings%features(size(features))) settings%features = features end if end if v = trim(compiler_in) if (len_trim(v) == 0) then buf = "" n = 0 stat = 0 call get_environment_variable("FC", buf, length=n, status=stat) if (stat == 0 .and. n > 0) v = trim(buf(1:n)) end if if (len_trim(v) == 0) v = "gfortran" settings%compiler = trim(v) v = trim(c_compiler_in) if (len_trim(v) == 0) then buf = "" n = 0 stat = 0 call get_environment_variable("CC", buf, length=n, status=stat) if (stat == 0 .and. n > 0) v = trim(buf(1:n)) end if if (len_trim(v) > 0) settings%c_compiler = trim(v) v = trim(cxx_compiler_in) if (len_trim(v) == 0) then buf = "" n = 0 stat = 0 call get_environment_variable("CXX", buf, length=n, status=stat) if (stat == 0 .and. n > 0) v = trim(buf(1:n)) end if if (len_trim(v) > 0) settings%cxx_compiler = trim(v) v = trim(archiver_in) if (len_trim(v) == 0) then buf = "" n = 0 stat = 0 call get_environment_variable("AR", buf, length=n, status=stat) if (stat == 0 .and. n > 0) v = trim(buf(1:n)) end if if (len_trim(v) > 0) settings%archiver = trim(v) v = trim(flag_in) if (len_trim(v) > 0) settings%flag = trim(v) v = trim(cflag_in) if (len_trim(v) > 0) settings%cflag = trim(v) v = trim(cxxflag_in) if (len_trim(v) > 0) settings%cxxflag = trim(v) v = trim(ldflag_in) if (len_trim(v) > 0) settings%ldflag = trim(v) end subroutine init_build_settings