add_executable_sources Subroutine

public subroutine add_executable_sources(sources, executables, scope, auto_discover, error)

Add to sources using the executable and test entries in the manifest and applies any executable-specific overrides such as executable%name. Adds all sources (including modules) from each executable%source_dir


Type IntentOptional AttributesName
type(srcfile_t), intent(inout), allocatable, target:: sources(:)

List of srcfile_t objects to append to. Allocated if not allocated

class(executable_config_t), intent(in) :: executables(:)

List of executable_config_t entries from manifest

integer, intent(in) :: scope

Scope to apply to the discovered sources: either FPM_SCOPE_APP or FPM_SCOPE_TEST, see fpm_model

logical, intent(in) :: auto_discover

If .false. only executables and tests specified in the manifest are added to sources

type(error_t), intent(out), allocatable:: error

Error handling



TypeVisibility AttributesNameInitial
type(string_t), public, allocatable:: exe_dirs(:)
type(srcfile_t), public :: exe_source
integer, public :: i
integer, public :: j

Source Code

subroutine add_executable_sources(sources,executables,scope,auto_discover,error)
    !> List of `[[srcfile_t]]` objects to append to. Allocated if not allocated
    type(srcfile_t), allocatable, intent(inout), target :: sources(:)
    !> List of `[[executable_config_t]]` entries from manifest
    class(executable_config_t), intent(in) :: executables(:)
    !> Scope to apply to the discovered sources: either `FPM_SCOPE_APP` or `FPM_SCOPE_TEST`, see [[fpm_model]]
    integer, intent(in) :: scope
    !> If `.false.` only executables and tests specified in the manifest are added to `sources`
    logical, intent(in) :: auto_discover
    !> Error handling
    type(error_t), allocatable, intent(out) :: error

    integer :: i, j

    type(string_t), allocatable :: exe_dirs(:)
    type(srcfile_t) :: exe_source

    call get_executable_source_dirs(exe_dirs,executables)

    do i=1,size(exe_dirs)
        call add_sources_from_dir(sources,exe_dirs(i)%s, scope, &
                     with_executables=auto_discover, recurse=.false., error=error)

        if (allocated(error)) then
        end if
    end do

    exe_loop: do i=1,size(executables)

        ! Check if executable already discovered automatically
        !  and apply any overrides
        do j=1,size(sources)

            if (basename(sources(j)%file_name,suffix=.true.) == executables(i)%main .and.&
                 canon_path(dirname(sources(j)%file_name)) == &
                 canon_path(executables(i)%source_dir) ) then

                sources(j)%exe_name = executables(i)%name
                if (allocated(executables(i)%link)) then
                    sources(j)%link_libraries = executables(i)%link
                end if
                cycle exe_loop

            end if

        end do

        ! Add if not already discovered (auto_discovery off)
        exe_source = parse_source(join_path(executables(i)%source_dir,executables(i)%main),error)
        exe_source%exe_name = executables(i)%name
        if (allocated(executables(i)%link)) then
            exe_source%link_libraries = executables(i)%link
        end if
        exe_source%unit_scope = scope

        if (allocated(error)) return

        if (.not.allocated(sources)) then
            sources = [exe_source]
            sources = [sources, exe_source]
        end if

    end do exe_loop

end subroutine add_executable_sources