fpm_model Module

The fpm package model

Defines the fpm model data types which encapsulate all information required to correctly build a package and its dependencies.

The process (see [[build_model(subroutine)]]) for generating a valid [[fpm_model]] involves source files discovery (fpm_sources) and parsing (fpm_source_parsing).

Once a valid [[fpm_model]] has been constructed, it may be passed to [[fpm_targets:targets_from_sources]] to generate a list of build targets for the backend.

Enumerations

Source type: FPM_UNIT_* Describes the type of source file — determines build target generation

The logical order of precedence for assigning unit_type is as follows:

 if source-file contains program then
   unit_type = FPM_UNIT_PROGRAM
 else if source-file contains non-module subroutine/function then
   unit_type = FPM_UNIT_SUBPROGRAM
 else if source-file contains submodule then
   unit_type = FPM_UNIT_SUBMODULE
 else if source-file contains module then
   unit_type = FPM_UNIT_MODULE
 end if

@note Note A source file is only designated FPM_UNIT_MODULE if it only contains modules - no non-module subprograms. (This allows tree-shaking/pruning of build targets based on unused module dependencies.)

Source scope: FPM_SCOPE_* Describes the scoping rules for using modules — controls module dependency resolution



Variables

Type Visibility Attributes Name Initial
integer, public, parameter :: FPM_SCOPE_APP = 3

Module-use scope is library/dependency and app modules

integer, public, parameter :: FPM_SCOPE_DEP = 2

Module-use scope is library/dependency modules only

integer, public, parameter :: FPM_SCOPE_EXAMPLE = 5
integer, public, parameter :: FPM_SCOPE_LIB = 1

Module-use scope is library/dependency modules only

integer, public, parameter :: FPM_SCOPE_TEST = 4

Module-use scope is library/dependency and test modules

integer, public, parameter :: FPM_SCOPE_UNKNOWN = -1

Source has no module-use scope

integer, public, parameter :: FPM_UNIT_CHEADER = 6

Source type is c header file

integer, public, parameter :: FPM_UNIT_CPPSOURCE = 7

Souce type is c++ source file.

integer, public, parameter :: FPM_UNIT_CSOURCE = 5

Source type is c source file

integer, public, parameter :: FPM_UNIT_MODULE = 2

Source only contains one or more fortran modules

integer, public, parameter :: FPM_UNIT_PROGRAM = 1

Source contains a fortran program

integer, public, parameter :: FPM_UNIT_SUBMODULE = 3

Source contains one or more fortran submodules

integer, public, parameter :: FPM_UNIT_SUBPROGRAM = 4

Source contains one or more fortran subprogram not within modules

integer, public, parameter :: FPM_UNIT_UNKNOWN = -1

Source type unknown


Derived Types

type, public, extends(serializable_t) ::  fortran_features_t

Enabled Fortran language features

Components

Type Visibility Attributes Name Initial
logical, public :: implicit_external = .false.

Use implicit external interface

logical, public :: implicit_typing = .false.

Use default implicit typing

character(len=:), public, allocatable :: source_form

Form to use for all Fortran sources

Type-Bound Procedures

generic, public :: dump => dump_to_toml, dump_to_file, dump_to_unit
procedure, public :: dump_to_toml => fft_dump_to_toml
generic, public :: load => load_from_toml, load_from_file, load_from_unit
procedure, public :: load_from_toml => fft_load_from_toml
generic, public :: operator(==) => serializable_is_same
procedure, public :: serializable_is_same => fft_is_same ../../

Serialization interface

procedure, public, non_overridable :: test_serialization ../../

Test load/write roundtrip

type, public, extends(serializable_t) ::  fpm_model_t

Type describing everything required to build the root package and its dependencies.

Components

Type Visibility Attributes Name Initial
type(archiver_t), public :: archiver

Archiver object

character(len=:), public, allocatable :: build_prefix

Base directory for build

character(len=:), public, allocatable :: c_compile_flags

Command line flags passed to C for compilation

type(compiler_t), public :: compiler

Compiler object

character(len=:), public, allocatable :: cxx_compile_flags

Command line flags passed to C++ for compilation

type(dependency_tree_t), public :: deps

Project dependencies

logical, public :: enforce_module_names = .false.

Whether module names should be prefixed with the package name

type(string_t), public, allocatable :: external_modules(:)

External modules used

character(len=:), public, allocatable :: fortran_compile_flags

Command line flags passed to fortran for compilation

type(string_t), public, allocatable :: include_dirs(:)

Include directories

logical, public :: include_tests = .true.

Whether tests should be added to the build list

character(len=:), public, allocatable :: link_flags

Command line flags passed to the linker

type(string_t), public, allocatable :: link_libraries(:)

Native libraries to link against

type(string_t), public :: module_prefix

Prefix for all module names

character(len=:), public, allocatable :: package_name

Name of root package

type(package_t), public, allocatable :: packages(:)

Array of packages (including the root package)

Type-Bound Procedures

generic, public :: dump => dump_to_toml, dump_to_file, dump_to_unit
procedure, public :: dump_to_toml => model_dump_to_toml
generic, public :: load => load_from_toml, load_from_file, load_from_unit
procedure, public :: load_from_toml => model_load_from_toml
generic, public :: operator(==) => serializable_is_same
procedure, public :: serializable_is_same => model_is_same ../../

Serialization interface

procedure, public, non_overridable :: test_serialization ../../

Test load/write roundtrip

type, public, extends(serializable_t) ::  package_t

Type for describing a single package

Components

Type Visibility Attributes Name Initial
logical, public :: enforce_module_names = .false.

Module naming conventions

type(fortran_features_t), public :: features

Language features

type(string_t), public :: module_prefix

Prefix for all module names

character(len=:), public, allocatable :: name

Name of package

type(preprocess_config_t), public :: preprocess

List of macros.

type(srcfile_t), public, allocatable :: sources(:)

Array of sources

character(len=:), public, allocatable :: version

Package version number.

Type-Bound Procedures

generic, public :: dump => dump_to_toml, dump_to_file, dump_to_unit
procedure, public :: dump_to_toml => package_dump_to_toml
generic, public :: load => load_from_toml, load_from_file, load_from_unit
procedure, public :: load_from_toml => package_load_from_toml
generic, public :: operator(==) => serializable_is_same
procedure, public :: serializable_is_same => package_is_same ../../

Serialization interface

procedure, public, non_overridable :: test_serialization ../../

Test load/write roundtrip

type, public, extends(serializable_t) ::  srcfile_t

Type for describing a source file

Components

Type Visibility Attributes Name Initial
integer(kind=int64), public :: digest

Current hash

character(len=:), public, allocatable :: exe_name

Name of executable for FPM_UNIT_PROGRAM

character(len=:), public, allocatable :: file_name

File path relative to cwd

type(string_t), public, allocatable :: include_dependencies(:)

Files INCLUDEd by this source file

type(string_t), public, allocatable :: link_libraries(:)

Native libraries to link against

type(string_t), public, allocatable :: modules_provided(:)

Modules provided by this source file (lowerstring)

type(string_t), public, allocatable :: modules_used(:)

Modules USEd by this source file (lowerstring)

type(string_t), public, allocatable :: parent_modules(:)

Parent modules (submodules only)

integer, public :: unit_scope = FPM_SCOPE_UNKNOWN

Target module-use scope

integer, public :: unit_type = FPM_UNIT_UNKNOWN

Type of source unit

Type-Bound Procedures

generic, public :: dump => dump_to_toml, dump_to_file, dump_to_unit
procedure, public :: dump_to_toml => srcfile_dump_to_toml
generic, public :: load => load_from_toml, load_from_file, load_from_unit
procedure, public :: load_from_toml => srcfile_load_from_toml
generic, public :: operator(==) => serializable_is_same
procedure, public :: serializable_is_same => srcfile_is_same ../../

Serialization interface

procedure, public, non_overridable :: test_serialization ../../

Test load/write roundtrip


Functions

public function FPM_SCOPE_NAME(flag) result(name)

Return the character name of a scope flag

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: flag

Return Value character(len=:), allocatable


Subroutines

public subroutine show_model(model)

Arguments

Type IntentOptional Attributes Name
type(fpm_model_t), intent(in) :: model