aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md4
-rwxr-xr-xinstall.sh13
-rw-r--r--manifest-reference.md26
-rw-r--r--src/fpm.f9028
-rw-r--r--src/fpm/manifest/build.f9016
-rw-r--r--src/fpm_backend.f9043
-rw-r--r--src/fpm_command_line.f903
-rw-r--r--src/fpm_compiler.f90170
-rw-r--r--src/fpm_environment.f9036
-rw-r--r--src/fpm_filesystem.f9010
-rw-r--r--src/fpm_model.f9020
-rw-r--r--src/fpm_targets.f9032
-rw-r--r--test/fpm_test/test_module_dependencies.f909
-rw-r--r--test/new_test/new_test.f906
14 files changed, 341 insertions, 75 deletions
diff --git a/README.md b/README.md
index d4e9002..69ae2ee 100644
--- a/README.md
+++ b/README.md
@@ -60,7 +60,7 @@ or from [miniconda](https://docs.conda.io/en/latest/miniconda.html).
To setup *fpm* within Github actions for automated testing, you can use the [fortran-lang/setup-fpm](https://github.com/marketplace/actions/setup-fpm) action.
-#### Bootstraping on other platforms
+#### Bootstrapping on other platforms
For other platforms and architectures have a look at the [bootstrapping instructions](#bootstrapping-instructions).
@@ -101,7 +101,7 @@ This guide explains the process of building *fpm* on a platform for the first ti
To build *fpm* without a prior *fpm* version a single source file version is available
at each release.
-To build manually using the single source distribution use
+To build manually using the single source distribution, run the following code (from within the current directory)
```
mkdir _tmp
diff --git a/install.sh b/install.sh
index 7f3908b..6c51304 100755
--- a/install.sh
+++ b/install.sh
@@ -52,7 +52,18 @@ if [ -z ${FFLAGS+x} ]; then
fi
mkdir -p $BOOTSTRAP_DIR
-curl -LJ $SOURCE_URL > $BOOTSTRAP_DIR/fpm.f90
+
+if command -v curl > /dev/null 2>&1; then
+ FETCH="curl -L"
+elif command -v wget > /dev/null 2>&1; then
+ FETCH="wget -O -"
+else
+ echo "No download mechanism found. Install curl or wget first."
+ exit 1
+fi
+
+$FETCH $SOURCE_URL > $BOOTSTRAP_DIR/fpm.f90
+
$FC $FFLAGS -J $BOOTSTRAP_DIR $BOOTSTRAP_DIR/fpm.f90 -o $BOOTSTRAP_DIR/fpm
$BOOTSTRAP_DIR/fpm install --compiler "$FC" --flag "$FFLAGS" --prefix "$PREFIX"
diff --git a/manifest-reference.md b/manifest-reference.md
index f92bd22..cd79b0b 100644
--- a/manifest-reference.md
+++ b/manifest-reference.md
@@ -33,6 +33,8 @@ Every manifest file consists of the following sections:
Toggle automatic discovery of executables
- [*link*](#link-external-libraries):
Link with external dependencies
+ - [*external-modules*](#use-system-installed-modules):
+ Specify modules used that are not within your fpm package
- Target sections:
- [*library*](#library-configuration)
Configuration of the library target
@@ -353,6 +355,30 @@ In this case the order of the libraries matters:
link = ["blas", "lapack"]
```
+## Use system-installed modules
+
+To use modules that are not defined within your fpm package or its dependencies,
+specify the module name using the *external-modules* key in the *build* table.
+
+> __Important:__ *fpm* cannot automatically locate external module files; it is the responsibility
+> of the user to specify the necessary include directories using compiler flags such that
+> the compiler can locate external module files during compilation.
+
+*Example:*
+
+```toml
+[build]
+external-modules = "netcdf"
+```
+
+Multiple external modules can be specified as a list.
+
+*Example:*
+
+```toml
+[build]
+external-modules = ["netcdf", "h5lt"]
+```
## Automatic target discovery
diff --git a/src/fpm.f90 b/src/fpm.f90
index 31b68ff..5854cfb 100644
--- a/src/fpm.f90
+++ b/src/fpm.f90
@@ -4,12 +4,12 @@ use fpm_backend, only: build_package
use fpm_command_line, only: fpm_build_settings, fpm_new_settings, &
fpm_run_settings, fpm_install_settings, fpm_test_settings
use fpm_dependency, only : new_dependency_tree
-use fpm_environment, only: run
+use fpm_environment, only: run, get_env, get_archiver
use fpm_filesystem, only: is_dir, join_path, number_of_rows, list_files, exists, basename
use fpm_model, only: fpm_model_t, srcfile_t, show_model, &
FPM_SCOPE_UNKNOWN, FPM_SCOPE_LIB, FPM_SCOPE_DEP, &
FPM_SCOPE_APP, FPM_SCOPE_EXAMPLE, FPM_SCOPE_TEST
-use fpm_compiler, only: get_module_flags, is_unknown_compiler
+use fpm_compiler, only: get_module_flags, is_unknown_compiler, get_default_c_compiler
use fpm_sources, only: add_executable_sources, add_sources_from_dir
@@ -51,6 +51,7 @@ subroutine build_model(model, settings, package, error)
allocate(model%include_dirs(0))
allocate(model%link_libraries(0))
+ allocate(model%external_modules(0))
call new_dependency_tree(model%deps, cache=join_path("build", "cache.toml"))
call model%deps%add(package, error)
@@ -62,6 +63,10 @@ subroutine build_model(model, settings, package, error)
model%fortran_compiler = settings%compiler
endif
+ model%archiver = get_archiver()
+ call get_default_c_compiler(model%fortran_compiler, model%c_compiler)
+ model%c_compiler = get_env('FPM_C_COMPILER',model%c_compiler)
+
if (is_unknown_compiler(model%fortran_compiler)) then
write(*, '(*(a:,1x))') &
"<WARN>", "Unknown compiler", model%fortran_compiler, "requested!", &
@@ -147,7 +152,7 @@ subroutine build_model(model, settings, package, error)
if (.not.allocated(model%packages(i)%sources)) allocate(model%packages(i)%sources(0))
if (allocated(dependency%library)) then
-
+
if (allocated(dependency%library%source_dir)) then
lib_dir = join_path(dep%proj_dir, dependency%library%source_dir)
if (is_dir(lib_dir)) then
@@ -165,12 +170,16 @@ subroutine build_model(model, settings, package, error)
end if
end do
end if
-
+
end if
if (allocated(dependency%build%link)) then
model%link_libraries = [model%link_libraries, dependency%build%link]
end if
+
+ if (allocated(dependency%build%external_modules)) then
+ model%external_modules = [model%external_modules, dependency%build%external_modules]
+ end if
end associate
end do
if (allocated(error)) return
@@ -178,8 +187,9 @@ subroutine build_model(model, settings, package, error)
if (settings%verbose) then
write(*,*)'<INFO> BUILD_NAME: ',settings%build_name
write(*,*)'<INFO> COMPILER: ',settings%compiler
- write(*,*)'<INFO> COMPILER OPTIONS: ', model%fortran_compile_flags
- write(*,*)'<INFO> INCLUDE DIRECTORIES: [', string_cat(model%include_dirs,','),']'
+ write(*,*)'<INFO> C COMPILER: ',model%c_compiler
+ write(*,*)'<INFO> COMPILER OPTIONS: ', model%fortran_compile_flags
+ write(*,*)'<INFO> INCLUDE DIRECTORIES: [', string_cat(model%include_dirs,','),']'
end if
! Check for duplicate modules
@@ -190,7 +200,7 @@ subroutine build_model(model, settings, package, error)
end subroutine build_model
! Check for duplicate modules
-subroutine check_modules_for_duplicates(model, duplicates_found)
+subroutine check_modules_for_duplicates(model, duplicates_found)
type(fpm_model_t), intent(in) :: model
integer :: maxsize
integer :: i,j,k,l,m,modi
@@ -370,7 +380,7 @@ subroutine cmd_run(settings,test)
! Check all names are valid
! or no name and found more than one file
- toomany= size(settings%name).eq.0 .and. size(executables).gt.1
+ toomany= size(settings%name).eq.0 .and. size(executables).gt.1
if ( any(.not.found) &
& .or. &
& ( (toomany .and. .not.test) .or. (toomany .and. settings%runner .ne. '') ) &
@@ -420,7 +430,7 @@ subroutine cmd_run(settings,test)
end if
end do
endif
- contains
+ contains
subroutine compact_list_all()
integer, parameter :: LINE_WIDTH = 80
integer :: i, j, nCol
diff --git a/src/fpm/manifest/build.f90 b/src/fpm/manifest/build.f90
index d96974f..c9b3f44 100644
--- a/src/fpm/manifest/build.f90
+++ b/src/fpm/manifest/build.f90
@@ -34,6 +34,9 @@ module fpm_manifest_build
!> Libraries to link against
type(string_t), allocatable :: link(:)
+ !> External modules to use
+ type(string_t), allocatable :: external_modules(:)
+
contains
!> Print information on this instance
@@ -87,6 +90,9 @@ contains
call get_value(table, "link", self%link, error)
if (allocated(error)) return
+ call get_value(table, "external-modules", self%external_modules, error)
+ if (allocated(error)) return
+
end subroutine new_build_config
@@ -110,7 +116,7 @@ contains
do ikey = 1, size(list)
select case(list(ikey)%key)
- case("auto-executables", "auto-examples", "auto-tests", "link")
+ case("auto-executables", "auto-examples", "auto-tests", "link", "external-modules")
continue
case default
@@ -135,7 +141,7 @@ contains
!> Verbosity of the printout
integer, intent(in), optional :: verbosity
- integer :: pr, ilink
+ integer :: pr, ilink, imod
character(len=*), parameter :: fmt = '("#", 1x, a, t30, a)'
if (present(verbosity)) then
@@ -156,6 +162,12 @@ contains
write(unit, fmt) " - " // self%link(ilink)%s
end do
end if
+ if (allocated(self%external_modules)) then
+ write(unit, fmt) " - external modules"
+ do imod = 1, size(self%external_modules)
+ write(unit, fmt) " - " // self%external_modules(imod)%s
+ end do
+ end if
end subroutine info
diff --git a/src/fpm_backend.f90 b/src/fpm_backend.f90
index 74cef61..51861b4 100644
--- a/src/fpm_backend.f90
+++ b/src/fpm_backend.f90
@@ -1,28 +1,28 @@
!># Build backend
-!> Uses a list of `[[build_target_ptr]]` and a valid `[[fpm_model]]` instance
+!> Uses a list of `[[build_target_ptr]]` and a valid `[[fpm_model]]` instance
!> to schedule and execute the compilation and linking of package targets.
-!>
+!>
!> The package build process (`[[build_package]]`) comprises three steps:
!>
!> 1. __Target sorting:__ topological sort of the target dependency graph (`[[sort_target]]`)
!> 2. __Target scheduling:__ group targets into schedule regions based on the sorting (`[[schedule_targets]]`)
!> 3. __Target building:__ generate targets by compilation or linking
-!>
+!>
!> @note If compiled with OpenMP, targets will be build in parallel where possible.
!>
!>### Incremental compilation
-!> The backend process supports *incremental* compilation whereby targets are not
+!> The backend process supports *incremental* compilation whereby targets are not
!> re-compiled if their corresponding dependencies have not been modified.
-!>
+!>
!> - Source-based targets (*i.e.* objects) are not re-compiled if the corresponding source
!> file is unmodified AND all of the target dependencies are not marked for re-compilation
!>
-!> - Link targets (*i.e.* executables and libraries) are not re-compiled if the
+!> - Link targets (*i.e.* executables and libraries) are not re-compiled if the
!> target output file already exists AND all of the target dependencies are not marked for
!> re-compilation
!>
!> Source file modification is determined by a file digest (hash) which is calculated during
-!> the source parsing phase ([[fpm_source_parsing]]) and cached to disk after a target is
+!> the source parsing phase ([[fpm_source_parsing]]) and cached to disk after a target is
!> successfully generated.
!>
module fpm_backend
@@ -30,9 +30,8 @@ module fpm_backend
use fpm_environment, only: run
use fpm_filesystem, only: dirname, join_path, exists, mkdir
use fpm_model, only: fpm_model_t
-use fpm_targets, only: build_target_t, build_target_ptr, &
- FPM_TARGET_OBJECT, FPM_TARGET_ARCHIVE, FPM_TARGET_EXECUTABLE
-
+use fpm_targets, only: build_target_t, build_target_ptr, FPM_TARGET_OBJECT, &
+ FPM_TARGET_C_OBJECT, FPM_TARGET_ARCHIVE, FPM_TARGET_EXECUTABLE
use fpm_strings, only: string_cat
implicit none
@@ -58,9 +57,9 @@ subroutine build_package(targets,model)
! Perform depth-first topological sort of targets
do i=1,size(targets)
-
+
call sort_target(targets(i)%ptr)
-
+
end do
! Construct build schedule queue
@@ -78,20 +77,20 @@ subroutine build_package(targets,model)
end do
end do
-
+
end subroutine build_package
-!> Topologically sort a target for scheduling by
+!> Topologically sort a target for scheduling by
!> recursing over its dependencies.
-!>
+!>
!> Checks disk-cached source hashes to determine if objects are
!> up-to-date. Up-to-date sources are tagged as skipped.
!>
-!> On completion, `target` should either be marked as
+!> On completion, `target` should either be marked as
!> sorted (`target%sorted=.true.`) or skipped (`target%skip=.true.`)
!>
-!> If `target` is marked as sorted, `target%schedule` should be an
+!> If `target` is marked as sorted, `target%schedule` should be an
!> integer greater than zero indicating the region for scheduling
!>
recursive subroutine sort_target(target)
@@ -162,7 +161,7 @@ recursive subroutine sort_target(target)
end if
end do
-
+
! Mark flag as processed: either sorted or skipped
target%sorted = .not.target%skip
@@ -241,13 +240,17 @@ subroutine build_target(model,target)
call run(model%fortran_compiler//" -c " // target%source%file_name // target%compile_flags &
// " -o " // target%output_file)
+ case (FPM_TARGET_C_OBJECT)
+ call run(model%c_compiler//" -c " // target%source%file_name // target%compile_flags &
+ // " -o " // target%output_file)
+
case (FPM_TARGET_EXECUTABLE)
-
+
call run(model%fortran_compiler// " " // target%compile_flags &
//" "//target%link_flags// " -o " // target%output_file)
case (FPM_TARGET_ARCHIVE)
- call run("ar -rs " // target%output_file // " " // string_cat(target%link_objects," "))
+ call run(model%archiver // target%output_file // " " // string_cat(target%link_objects," "))
end select
diff --git a/src/fpm_command_line.f90 b/src/fpm_command_line.f90
index 9e9a572..2a2ecf5 100644
--- a/src/fpm_command_line.f90
+++ b/src/fpm_command_line.f90
@@ -25,7 +25,7 @@
module fpm_command_line
use fpm_environment, only : get_os_type, get_env, &
OS_UNKNOWN, OS_LINUX, OS_MACOS, OS_WINDOWS, &
- OS_CYGWIN, OS_SOLARIS, OS_FREEBSD
+ OS_CYGWIN, OS_SOLARIS, OS_FREEBSD, OS_OPENBSD
use M_CLI2, only : set_args, lget, sget, unnamed, remaining, specified
use fpm_strings, only : lower, split, fnv_1a
use fpm_filesystem, only : basename, canon_path, to_fortran_name
@@ -129,6 +129,7 @@ contains
case (OS_CYGWIN); os_type = "OS Type: Cygwin"
case (OS_SOLARIS); os_type = "OS Type: Solaris"
case (OS_FREEBSD); os_type = "OS Type: FreeBSD"
+ case (OS_OPENBSD); os_type = "OS Type: OpenBSD"
case (OS_UNKNOWN); os_type = "OS Type: Unknown"
case default ; os_type = "OS Type: UNKNOWN"
end select
diff --git a/src/fpm_compiler.f90 b/src/fpm_compiler.f90
index 51cda20..ff311f7 100644
--- a/src/fpm_compiler.f90
+++ b/src/fpm_compiler.f90
@@ -28,6 +28,15 @@
module fpm_compiler
use fpm_model, only: fpm_model_t
use fpm_filesystem, only: join_path, basename
+use fpm_environment, only: &
+ get_os_type, &
+ OS_LINUX, &
+ OS_MACOS, &
+ OS_WINDOWS, &
+ OS_CYGWIN, &
+ OS_SOLARIS, &
+ OS_FREEBSD, &
+ OS_OPENBSD
implicit none
public :: is_unknown_compiler
public :: get_module_flags
@@ -41,8 +50,13 @@ enum, bind(C)
id_gcc, &
id_f95, &
id_caf, &
- id_intel_classic, &
- id_intel_llvm, &
+ id_intel_classic_nix, &
+ id_intel_classic_mac, &
+ id_intel_classic_windows, &
+ id_intel_classic_unknown, &
+ id_intel_llvm_nix, &
+ id_intel_llvm_windows, &
+ id_intel_llvm_unknown, &
id_pgi, &
id_nvhpc, &
id_nag, &
@@ -78,7 +92,6 @@ subroutine get_release_compile_flags(id, flags)
select case(id)
case default
flags = ""
-
case(id_caf)
flags='&
& -O3&
@@ -109,16 +122,54 @@ subroutine get_release_compile_flags(id, flags)
flags = '&
& -Mbackslash&
&'
- case(id_intel_classic)
+ case(id_intel_classic_nix, id_intel_classic_unknown)
+ flags = '&
+ & -fp-model precise&
+ & -pc64&
+ & -align all&
+ & -error-limit 1&
+ & -reentrancy threaded&
+ & -nogen-interfaces&
+ & -assume byterecl&
+ &'
+ case(id_intel_classic_mac)
flags = '&
& -fp-model precise&
- & -pc 64&
+ & -pc64&
+ & -align all&
+ & -error-limit 1&
+ & -reentrancy threaded&
+ & -nogen-interfaces&
+ & -assume byterecl&
+ &'
+ case(id_intel_classic_windows)
+ flags = '&
+ & /fp:precise&
+ & /align:all&
+ & /error-limit:1&
+ & /reentrancy:threaded&
+ & /nogen-interfaces&
+ & /assume:byterecl&
+ &'
+ case(id_intel_llvm_nix, id_intel_llvm_unknown)
+ flags = '&
+ & -fp-model=precise&
+ & -pc64&
& -align all&
& -error-limit 1&
& -reentrancy threaded&
& -nogen-interfaces&
& -assume byterecl&
&'
+ case(id_intel_llvm_windows)
+ flags = '&
+ & /fp:precise&
+ & /align:all&
+ & /error-limit:1&
+ & /reentrancy:threaded&
+ & /nogen-interfaces&
+ & /assume:byterecl&
+ &'
case(id_nag)
flags = ' &
& -O4&
@@ -135,7 +186,6 @@ subroutine get_debug_compile_flags(id, flags)
select case(id)
case default
flags = ""
-
case(id_caf)
flags = '&
& -Wall&
@@ -147,7 +197,6 @@ subroutine get_debug_compile_flags(id, flags)
& -fcheck=array-temps&
& -fbacktrace&
&'
-
case(id_gcc)
flags = '&
& -Wall&
@@ -160,7 +209,6 @@ subroutine get_debug_compile_flags(id, flags)
& -fbacktrace&
& -fcoarray=single&
&'
-
case(id_f95)
flags = '&
& -Wall&
@@ -173,7 +221,6 @@ subroutine get_debug_compile_flags(id, flags)
& -Wno-maybe-uninitialized -Wno-uninitialized&
& -fbacktrace&
&'
-
case(id_nvhpc)
flags = '&
& -Minform=inform&
@@ -184,18 +231,59 @@ subroutine get_debug_compile_flags(id, flags)
& -Mchkstk&
& -traceback&
&'
-
- case(id_intel_classic)
+ case(id_intel_classic_nix, id_intel_classic_unknown)
flags = '&
& -warn all&
- & -check:all:noarg_temp_created&
+ & -check all&
& -error-limit 1&
& -O0&
& -g&
& -assume byterecl&
& -traceback&
+ & -coarray=single&
+ &'
+ case(id_intel_classic_mac)
+ flags = '&
+ & -warn all&
+ & -check all&
+ & -error-limit 1&
+ & -O0&
+ & -g&
+ & -assume byterecl&
+ & -traceback&
+ &'
+ case(id_intel_classic_windows)
+ flags = '&
+ & /warn:all&
+ & /check:all&
+ & /error-limit:1&
+ & /Od&
+ & /Z7&
+ & /assume:byterecl&
+ & /traceback&
+ & /Qcoarray:single&
+ &'
+ case(id_intel_llvm_nix, id_intel_llvm_unknown)
+ flags = '&
+ & -warn all&
+ & -check all&
+ & -error-limit 1&
+ & -O0&
+ & -g&
+ & -assume byterecl&
+ & -traceback&
+ & -coarray=single&
+ &'
+ case(id_intel_llvm_windows)
+ flags = '&
+ & /warn:all&
+ & /check:all&
+ & /error-limit:1&
+ & /Od&
+ & /Z7&
+ & /assume:byterecl&
+ & /Qcoarray:single&
&'
-
case(id_nag)
flags = '&
& -g&
@@ -223,9 +311,15 @@ subroutine get_module_flags(compiler, modpath, flags)
case(id_caf, id_gcc, id_f95, id_cray)
flags=' -J '//modpath//' -I '//modpath
- case(id_intel_classic, id_intel_llvm, id_nvhpc, id_pgi, id_flang)
+ case(id_nvhpc, id_pgi, id_flang)
flags=' -module '//modpath//' -I '//modpath
+ case(id_intel_classic_nix, id_intel_classic_mac, id_intel_classic_unknown, id_intel_llvm_nix, id_intel_llvm_unknown)
+ flags=' -module '//modpath//' -I'//modpath
+
+ case(id_intel_classic_windows, id_intel_llvm_windows)
+ flags=' /module:'//modpath//' /I'//modpath
+
case(id_lahey)
flags=' -M '//modpath//' -I '//modpath
@@ -239,6 +333,34 @@ subroutine get_module_flags(compiler, modpath, flags)
end subroutine get_module_flags
+subroutine get_default_c_compiler(f_compiler, c_compiler)
+ character(len=*), intent(in) :: f_compiler
+ character(len=:), allocatable, intent(out) :: c_compiler
+ integer(compiler_enum) :: id
+
+ id = get_compiler_id(f_compiler)
+
+ select case(id)
+
+ case(id_intel_classic_nix, id_intel_classic_mac, id_intel_classic_windows, id_intel_classic_unknown)
+ c_compiler = 'icc'
+
+ case(id_intel_llvm_nix,id_intel_llvm_windows, id_intel_llvm_unknown)
+ c_compiler = 'icx'
+
+ case(id_flang)
+ c_compiler='clang'
+
+ case(id_ibmxl)
+ c_compiler='xlc'
+
+ case default
+ ! Fall-back to using Fortran compiler
+ c_compiler = f_compiler
+ end select
+
+end subroutine get_default_c_compiler
+
function get_compiler_id(compiler) result(id)
character(len=*), intent(in) :: compiler
integer(kind=compiler_enum) :: id
@@ -259,12 +381,28 @@ function get_compiler_id(compiler) result(id)
end if
if (check_compiler(compiler, "ifort")) then
- id = id_intel_classic
+ select case (get_os_type())
+ case (OS_LINUX, OS_SOLARIS, OS_FREEBSD)
+ id = id_intel_classic_nix
+ case (OS_MACOS)
+ id = id_intel_classic_mac
+ case (OS_WINDOWS, OS_CYGWIN)
+ id = id_intel_classic_windows
+ case default
+ id = id_intel_classic_unknown
+ end select
return
end if
if (check_compiler(compiler, "ifx")) then
- id = id_intel_llvm
+ select case (get_os_type())
+ case (OS_LINUX, OS_SOLARIS, OS_FREEBSD)
+ id = id_intel_llvm_nix
+ case (OS_WINDOWS, OS_CYGWIN)
+ id = id_intel_llvm_windows
+ case default
+ id = id_intel_llvm_unknown
+ end select
return
end if
diff --git a/src/fpm_environment.f90 b/src/fpm_environment.f90
index 0408ec4..345f6ab 100644
--- a/src/fpm_environment.f90
+++ b/src/fpm_environment.f90
@@ -1,5 +1,5 @@
!> This module contains procedures that interact with the programming environment.
-!!
+!!
!! * [get_os_type] -- Determine the OS type
!! * [get_env] -- return the value of an environment variable
module fpm_environment
@@ -9,6 +9,7 @@ module fpm_environment
public :: os_is_unix
public :: run
public :: get_env
+ public :: get_archiver
integer, parameter, public :: OS_UNKNOWN = 0
integer, parameter, public :: OS_LINUX = 1
@@ -17,12 +18,13 @@ module fpm_environment
integer, parameter, public :: OS_CYGWIN = 4
integer, parameter, public :: OS_SOLARIS = 5
integer, parameter, public :: OS_FREEBSD = 6
+ integer, parameter, public :: OS_OPENBSD = 7
contains
!> Determine the OS type
integer function get_os_type() result(r)
!!
!! Returns one of OS_UNKNOWN, OS_LINUX, OS_MACOS, OS_WINDOWS, OS_CYGWIN,
- !! OS_SOLARIS, OS_FREEBSD.
+ !! OS_SOLARIS, OS_FREEBSD, OS_OPENBSD.
!!
!! At first, the environment variable `OS` is checked, which is usually
!! found on Windows. Then, `OSTYPE` is read in and compared with common
@@ -83,6 +85,12 @@ contains
r = OS_FREEBSD
return
end if
+
+ ! OpenBSD
+ if (index(val, 'OpenBSD') > 0 .or. index(val, 'openbsd') > 0) then
+ r = OS_OPENBSD
+ return
+ end if
end if
! Linux
@@ -110,7 +118,7 @@ contains
end if
end function get_os_type
- !> Compare the output of [[get_os_type]] or the optional
+ !> Compare the output of [[get_os_type]] or the optional
!! passed INTEGER value to the value for OS_WINDOWS
!! and return .TRUE. if they match and .FALSE. otherwise
logical function os_is_unix(os) result(unix)
@@ -150,7 +158,7 @@ contains
function get_env(NAME,DEFAULT) result(VALUE)
implicit none
!> name of environment variable to get the value of
- character(len=*),intent(in) :: NAME
+ character(len=*),intent(in) :: NAME
!> default value to return if the requested value is undefined or blank
character(len=*),intent(in),optional :: DEFAULT
!> the returned value
@@ -182,4 +190,24 @@ contains
if(VALUE.eq.''.and.present(DEFAULT))VALUE=DEFAULT
end function get_env
+ function get_archiver() result(archiver)
+ character(:), allocatable :: archiver
+
+ associate(os_type => get_os_type())
+ if (os_type /= OS_WINDOWS .and. os_type /= OS_UNKNOWN) then
+ archiver = "ar -rs "
+ else
+ block
+ integer :: estat
+
+ call execute_command_line("ar --version", exitstat=estat)
+ if (estat /= 0) then
+ archiver = "lib /OUT:"
+ else
+ archiver = "ar -rs "
+ end if
+ end block
+ end if
+ end associate
+ end function
end module fpm_environment
diff --git a/src/fpm_filesystem.f90 b/src/fpm_filesystem.f90
index 6acd383..28c3b33 100644
--- a/src/fpm_filesystem.f90
+++ b/src/fpm_filesystem.f90
@@ -4,7 +4,7 @@ module fpm_filesystem
use,intrinsic :: iso_fortran_env, only : stdin=>input_unit, stdout=>output_unit, stderr=>error_unit
use fpm_environment, only: get_os_type, &
OS_UNKNOWN, OS_LINUX, OS_MACOS, OS_WINDOWS, &
- OS_CYGWIN, OS_SOLARIS, OS_FREEBSD
+ OS_CYGWIN, OS_SOLARIS, OS_FREEBSD, OS_OPENBSD
use fpm_strings, only: f_string, replace, string_t, split
implicit none
private
@@ -192,7 +192,7 @@ logical function is_dir(dir)
select case (get_os_type())
- case (OS_UNKNOWN, OS_LINUX, OS_MACOS, OS_CYGWIN, OS_SOLARIS, OS_FREEBSD)
+ case (OS_UNKNOWN, OS_LINUX, OS_MACOS, OS_CYGWIN, OS_SOLARIS, OS_FREEBSD, OS_OPENBSD)
call execute_command_line("test -d " // dir , exitstat=stat)
case (OS_WINDOWS)
@@ -214,7 +214,7 @@ function join_path(a1,a2,a3,a4,a5) result(path)
character(len=1) :: filesep
select case (get_os_type())
- case (OS_UNKNOWN, OS_LINUX, OS_MACOS, OS_CYGWIN, OS_SOLARIS, OS_FREEBSD)
+ case (OS_UNKNOWN, OS_LINUX, OS_MACOS, OS_CYGWIN, OS_SOLARIS, OS_FREEBSD, OS_OPENBSD)
filesep = '/'
case (OS_WINDOWS)
filesep = '\'
@@ -283,7 +283,7 @@ subroutine mkdir(dir)
if (is_dir(dir)) return
select case (get_os_type())
- case (OS_UNKNOWN, OS_LINUX, OS_MACOS, OS_CYGWIN, OS_SOLARIS, OS_FREEBSD)
+ case (OS_UNKNOWN, OS_LINUX, OS_MACOS, OS_CYGWIN, OS_SOLARIS, OS_FREEBSD, OS_OPENBSD)
call execute_command_line('mkdir -p ' // dir, exitstat=stat)
write (*, '(" + ",2a)') 'mkdir -p ' // dir
@@ -322,7 +322,7 @@ recursive subroutine list_files(dir, files, recurse)
allocate (temp_file, source=get_temp_filename())
select case (get_os_type())
- case (OS_UNKNOWN, OS_LINUX, OS_MACOS, OS_CYGWIN, OS_SOLARIS, OS_FREEBSD)
+ case (OS_UNKNOWN, OS_LINUX, OS_MACOS, OS_CYGWIN, OS_SOLARIS, OS_FREEBSD, OS_OPENBSD)
call execute_command_line('ls -A ' // dir // ' > ' // temp_file, &
exitstat=stat)
case (OS_WINDOWS)
diff --git a/src/fpm_model.f90 b/src/fpm_model.f90
index bfb0115..9746e5f 100644
--- a/src/fpm_model.f90
+++ b/src/fpm_model.f90
@@ -1,6 +1,6 @@
!># The fpm package model
!>
-!> Defines the fpm model data types which encapsulate all information
+!> 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
@@ -117,6 +117,12 @@ type :: fpm_model_t
!> Command line name to invoke fortran compiler
character(:), allocatable :: fortran_compiler
+ !> Command line to invoke for creating static library
+ character(:), allocatable :: archiver
+
+ !> Command line name to invoke c compiler
+ character(:), allocatable :: c_compiler
+
!> Command line flags passed to fortran for compilation
character(:), allocatable :: fortran_compile_flags
@@ -128,7 +134,10 @@ type :: fpm_model_t
!> Native libraries to link against
type(string_t), allocatable :: link_libraries(:)
-
+
+ !> External modules used
+ type(string_t), allocatable :: external_modules(:)
+
!> Project dependencies
type(dependency_tree_t) :: deps
@@ -276,6 +285,13 @@ function info_model(model) result(s)
if (i < size(model%link_libraries)) s = s // ", "
end do
s = s // "]"
+ ! type(string_t), allocatable :: external_modules(:)
+ s = s // ", external_modules=["
+ do i = 1, size(model%external_modules)
+ s = s // '"' // model%external_modules(i)%s // '"'
+ if (i < size(model%external_modules)) s = s // ", "
+ end do
+ s = s // "]"
! type(dependency_tree_t) :: deps
! TODO: print `dependency_tree_t` properly, which should become part of the
! model, not imported from another file
diff --git a/src/fpm_targets.f90 b/src/fpm_targets.f90
index 02bb600..c247232 100644
--- a/src/fpm_targets.f90
+++ b/src/fpm_targets.f90
@@ -35,7 +35,8 @@ implicit none
private
public FPM_TARGET_UNKNOWN, FPM_TARGET_EXECUTABLE, &
- FPM_TARGET_ARCHIVE, FPM_TARGET_OBJECT
+ FPM_TARGET_ARCHIVE, FPM_TARGET_OBJECT, &
+ FPM_TARGET_C_OBJECT
public build_target_t, build_target_ptr
public targets_from_sources, resolve_module_dependencies
public resolve_target_linking, add_target, add_dependency
@@ -50,7 +51,8 @@ integer, parameter :: FPM_TARGET_EXECUTABLE = 1
integer, parameter :: FPM_TARGET_ARCHIVE = 2
!> Target type is compiled object
integer, parameter :: FPM_TARGET_OBJECT = 3
-
+!> Target type is c compiled object
+integer, parameter :: FPM_TARGET_C_OBJECT = 4
!> Wrapper type for constructing arrays of `[[build_target_t]]` pointers
type build_target_ptr
@@ -121,7 +123,7 @@ subroutine targets_from_sources(targets,model,error)
call build_target_list(targets,model)
- call resolve_module_dependencies(targets,error)
+ call resolve_module_dependencies(targets,model%external_modules,error)
if (allocated(error)) return
call resolve_target_linking(targets,model)
@@ -194,7 +196,8 @@ subroutine build_target_list(targets,model)
case (FPM_UNIT_MODULE,FPM_UNIT_SUBMODULE,FPM_UNIT_SUBPROGRAM,FPM_UNIT_CSOURCE)
call add_target(targets,source = sources(i), &
- type = FPM_TARGET_OBJECT,&
+ type = merge(FPM_TARGET_C_OBJECT,FPM_TARGET_OBJECT,&
+ sources(i)%unit_type==FPM_UNIT_CSOURCE), &
output_file = get_object_name(sources(i)))
if (with_lib .and. sources(i)%unit_scope == FPM_SCOPE_LIB) then
@@ -345,8 +348,9 @@ end subroutine add_dependency
!> a source file in the package of the correct scope, then a __fatal error__
!> is returned by the procedure and model construction fails.
!>
-subroutine resolve_module_dependencies(targets,error)
+subroutine resolve_module_dependencies(targets,external_modules,error)
type(build_target_ptr), intent(inout), target :: targets(:)
+ type(string_t), intent(in) :: external_modules(:)
type(error_t), allocatable, intent(out) :: error
type(build_target_ptr) :: dep
@@ -364,6 +368,11 @@ subroutine resolve_module_dependencies(targets,error)
cycle
end if
+ if (targets(i)%ptr%source%modules_used(j)%s .in. external_modules) then
+ ! Dependency satisfied in system-installed module
+ cycle
+ end if
+
if (any(targets(i)%ptr%source%unit_scope == &
[FPM_SCOPE_APP, FPM_SCOPE_EXAMPLE, FPM_SCOPE_TEST])) then
dep%ptr => &
@@ -442,7 +451,7 @@ subroutine resolve_target_linking(targets, model)
integer :: i
character(:), allocatable :: global_link_flags
- character(:), allocatable :: global_compile_flags
+ character(:), allocatable :: global_include_flags
if (size(targets) == 0) return
@@ -452,17 +461,16 @@ subroutine resolve_target_linking(targets, model)
allocate(character(0) :: global_link_flags)
end if
- global_compile_flags = model%fortran_compile_flags
-
if (allocated(model%link_libraries)) then
if (size(model%link_libraries) > 0) then
global_link_flags = global_link_flags // " -l" // string_cat(model%link_libraries," -l")
end if
end if
+ allocate(character(0) :: global_include_flags)
if (allocated(model%include_dirs)) then
if (size(model%include_dirs) > 0) then
- global_compile_flags = global_compile_flags // &
+ global_include_flags = global_include_flags // &
& " -I" // string_cat(model%include_dirs," -I")
end if
end if
@@ -471,7 +479,11 @@ subroutine resolve_target_linking(targets, model)
associate(target => targets(i)%ptr)
- target%compile_flags = global_compile_flags
+ if (target%target_type /= FPM_TARGET_C_OBJECT) then
+ target%compile_flags = model%fortran_compile_flags//" "//global_include_flags
+ else
+ target%compile_flags = global_include_flags
+ end if
allocate(target%link_objects(0))
diff --git a/test/fpm_test/test_module_dependencies.f90 b/test/fpm_test/test_module_dependencies.f90
index f193646..992f227 100644
--- a/test/fpm_test/test_module_dependencies.f90
+++ b/test/fpm_test/test_module_dependencies.f90
@@ -67,6 +67,7 @@ contains
type(build_target_ptr), allocatable :: targets(:)
model%output_directory = ''
+ allocate(model%external_modules(0))
allocate(model%packages(1))
allocate(model%packages(1)%sources(2))
@@ -137,6 +138,7 @@ contains
character(:), allocatable :: scope_str
model%output_directory = ''
+ allocate(model%external_modules(0))
allocate(model%packages(1))
allocate(model%packages(1)%sources(2))
@@ -196,6 +198,7 @@ contains
type(build_target_ptr), allocatable :: targets(:)
model%output_directory = ''
+ allocate(model%external_modules(0))
allocate(model%packages(1))
allocate(model%packages(1)%sources(1))
@@ -249,6 +252,7 @@ contains
character(:), allocatable :: scope_str
model%output_directory = ''
+ allocate(model%external_modules(0))
allocate(model%packages(1))
allocate(model%packages(1)%sources(3))
@@ -308,6 +312,7 @@ contains
type(build_target_ptr), allocatable :: targets(:)
model%output_directory = ''
+ allocate(model%external_modules(0))
allocate(model%packages(1))
allocate(model%packages(1)%sources(2))
@@ -335,6 +340,7 @@ contains
type(build_target_ptr), allocatable :: targets(:)
model%output_directory = ''
+ allocate(model%external_modules(0))
allocate(model%packages(1))
allocate(model%packages(1)%sources(2))
@@ -361,6 +367,7 @@ contains
type(build_target_ptr), allocatable :: targets(:)
model%output_directory = ''
+ allocate(model%external_modules(0))
allocate(model%packages(1))
allocate(model%packages(1)%sources(2))
@@ -388,6 +395,7 @@ contains
type(build_target_ptr), allocatable :: targets(:)
model%output_directory = ''
+ allocate(model%external_modules(0))
allocate(model%packages(1))
allocate(model%packages(1)%sources(2))
@@ -507,6 +515,7 @@ contains
type(build_target_ptr), allocatable :: targets(:)
model%output_directory = ''
+ allocate(model%external_modules(0))
allocate(model%packages(1))
allocate(model%packages(1)%sources(2))
diff --git a/test/new_test/new_test.f90 b/test/new_test/new_test.f90
index 3c8c453..a6c859b 100644
--- a/test/new_test/new_test.f90
+++ b/test/new_test/new_test.f90
@@ -4,7 +4,7 @@ use fpm_filesystem, only : is_dir, list_files, exists, windows_path, join_path,
dirname
use fpm_strings, only : string_t, operator(.in.)
use fpm_environment, only : run, get_os_type
-use fpm_environment, only : OS_UNKNOWN, OS_LINUX, OS_MACOS, OS_CYGWIN, OS_SOLARIS, OS_FREEBSD, OS_WINDOWS
+use fpm_environment, only : OS_UNKNOWN, OS_LINUX, OS_MACOS, OS_CYGWIN, OS_SOLARIS, OS_FREEBSD, OS_OPENBSD, OS_WINDOWS
implicit none
type(string_t), allocatable :: file_names(:)
integer :: i, j, k
@@ -49,7 +49,7 @@ logical :: IS_OS_WINDOWS
!! o DOS versus POSIX filenames
is_os_windows=.false.
select case (get_os_type())
- case (OS_UNKNOWN, OS_LINUX, OS_MACOS, OS_CYGWIN, OS_SOLARIS, OS_FREEBSD)
+ case (OS_UNKNOWN, OS_LINUX, OS_MACOS, OS_CYGWIN, OS_SOLARIS, OS_FREEBSD, OS_OPENBSD)
call execute_command_line('rm -rf fpm_scratch_*',exitstat=estat,cmdstat=cstat,cmdmsg=message)
path=cmdpath
case (OS_WINDOWS)
@@ -145,7 +145,7 @@ logical :: IS_OS_WINDOWS
! clean up scratch files; might want an option to leave them for inspection
select case (get_os_type())
- case (OS_UNKNOWN, OS_LINUX, OS_MACOS, OS_CYGWIN, OS_SOLARIS, OS_FREEBSD)
+ case (OS_UNKNOWN, OS_LINUX, OS_MACOS, OS_CYGWIN, OS_SOLARIS, OS_FREEBSD, OS_OPENBSD)
call execute_command_line('rm -rf fpm_scratch_*',exitstat=estat,cmdstat=cstat,cmdmsg=message)
case (OS_WINDOWS)
call execute_command_line('rmdir fpm_scratch_* /s /q',exitstat=estat,cmdstat=cstat,cmdmsg=message)