get_export_flags Function

public function get_export_flags(self, target_dir, target_name) result(export_flags)

Generate library export flags for a shared library build

Type Bound

compiler_t

Arguments

Type IntentOptional Attributes Name
class(compiler_t), intent(in) :: self

Instance of the compiler

character(len=*), intent(in) :: target_dir

Path and package name

character(len=*), intent(in) :: target_name

Path and package name

Return Value character(len=:), allocatable


Variables

Type Visibility Attributes Name Initial
character(len=:), public, allocatable :: def_path
character(len=:), public, allocatable :: implib_path

Source Code

function get_export_flags(self, target_dir, target_name) result(export_flags)
    !> Instance of the compiler
    class(compiler_t), intent(in) :: self
    !> Path and package name
    character(len=*), intent(in) :: target_dir, target_name
    character(len=:), allocatable :: export_flags

    character(len=:), allocatable :: implib_path, def_path

    ! Only apply on Windows
    if (get_os_type() /= OS_WINDOWS) then
        export_flags = ""
        return
    end if

    select case (self%id)

    case (id_gcc, id_caf, id_f95)
        ! GNU-based: emit both import library and def file
        implib_path = quote(join_path(target_dir, target_name // ".dll.a") , for_cmd=.true.)
        def_path    = quote(join_path(target_dir, target_name // ".def" ) , for_cmd=.true.)

        export_flags = " -Wl,--out-implib," // implib_path // &
                       " -Wl,--output-def," // def_path

    case (id_intel_classic_windows, id_intel_llvm_windows)
        ! Intel/MSVC-style
        implib_path = quote(join_path(target_dir, target_name // ".lib") , for_cmd=.true.)
        def_path    = quote(join_path(target_dir, target_name // ".def") , for_cmd=.true.)
                
        export_flags = " /IMPLIB:" // implib_path // &
                       " /DEF:" // def_path

    case default
        
        export_flags = ""  ! Do nothing elsewhere

    end select

end function get_export_flags