diff --git a/src/fpm.f90 b/src/fpm.f90 index c6703782bb..7d12bbe716 100644 --- a/src/fpm.f90 +++ b/src/fpm.f90 @@ -49,6 +49,7 @@ subroutine build_model(model, settings, package, error) type(string_t) :: include_dir model%package_name = package%name + model%implicit_none = package%implicit_none allocate(model%include_dirs(0)) allocate(model%link_libraries(0)) diff --git a/src/fpm/manifest/package.f90 b/src/fpm/manifest/package.f90 index 043076143b..85965843d1 100644 --- a/src/fpm/manifest/package.f90 +++ b/src/fpm/manifest/package.f90 @@ -61,6 +61,8 @@ module fpm_manifest_package !> Name of the package character(len=:), allocatable :: name + logical :: implicit_none + !> Package version type(version_t) :: version @@ -132,6 +134,8 @@ subroutine new_package(self, table, root, error) return end if + call get_value(table, "implicit_none", self%implicit_none, .false.) + if (len(self%name) <= 0) then call syntax_error(error, "Package name must be a non-empty string") return @@ -300,7 +304,7 @@ subroutine check(table, error) case("version", "license", "author", "maintainer", "copyright", & & "description", "keywords", "categories", "homepage", "build", & & "dependencies", "dev-dependencies", "test", "executable", & - & "example", "library", "install") + & "example", "library", "install", "implicit_none") continue end select diff --git a/src/fpm_backend.f90 b/src/fpm_backend.f90 index 8628ec45c6..09ae017d6b 100644 --- a/src/fpm_backend.f90 +++ b/src/fpm_backend.f90 @@ -257,7 +257,7 @@ subroutine build_target(model,target,stat) integer, intent(out) :: stat integer :: ilib, fh - character(:), allocatable :: link_flags + character(:), allocatable :: link_flags, implicit_flag if (.not.exists(dirname(target%output_file))) then call mkdir(dirname(target%output_file)) @@ -266,7 +266,12 @@ subroutine build_target(model,target,stat) select case(target%target_type) case (FPM_TARGET_OBJECT) - call run(model%fortran_compiler//" -c " // target%source%file_name // target%compile_flags & + if (model%implicit_none) then + implicit_flag = " -fimplicit-none" + else + implicit_flag = "" + end if + call run(model%fortran_compiler//" -c " // target%source%file_name // target%compile_flags // implicit_flag & // " -o " // target%output_file, echo=.true., exitstat=stat) case (FPM_TARGET_C_OBJECT) diff --git a/src/fpm_model.f90 b/src/fpm_model.f90 index 9746e5f031..e3993415ba 100644 --- a/src/fpm_model.f90 +++ b/src/fpm_model.f90 @@ -111,6 +111,9 @@ module fpm_model !> Name of root package character(:), allocatable :: package_name + !> Should "implicit none" be enforced by the compiler + logical :: implicit_none + !> Array of packages (including the root package) type(package_t), allocatable :: packages(:) @@ -259,12 +262,20 @@ end function info_srcfile_short function info_model(model) result(s) type(fpm_model_t), intent(in) :: model - character(:), allocatable :: s + character(:), allocatable :: s, tmp integer :: i !type :: fpm_model_t s = "fpm_model_t(" ! character(:), allocatable :: package_name s = s // 'package_name="' // model%package_name // '"' + + if (model%implicit_none) then + tmp = ".true." + else + tmp = ".false." + end if + s = s // ', implicit_none=' // tmp + ! type(srcfile_t), allocatable :: sources(:) s = s // ", packages=[" do i = 1, size(model%packages)