Skip to content

Commit 5f82869

Browse files
committed
fix cmd_install for allocatable structures
1 parent ee812cf commit 5f82869

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/fpm/cmd/install.f90

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ subroutine cmd_install(settings)
2929
type(build_target_ptr), allocatable :: targets(:), libraries(:)
3030
type(installer_t) :: installer
3131
type(string_t), allocatable :: list(:)
32-
logical :: installable
32+
logical :: installable, has_install_config, install_library, install_tests
33+
logical :: has_library, has_executables
34+
character(len=:), allocatable :: module_dir
3335
integer :: ntargets,i
3436

3537
call get_package_data(package, "fpm.toml", error, apply_defaults=.true.)
@@ -38,8 +40,19 @@ subroutine cmd_install(settings)
3840
call build_model(model, settings, package, error)
3941
call handle_error(error)
4042

43+
! Set up logical variables to avoid repetitive conditions
44+
has_install_config = allocated(package%install)
45+
install_library = has_install_config .and. package%install%library
46+
install_tests = has_install_config .and. package%install%test
47+
has_library = allocated(package%library)
48+
has_executables = allocated(package%executable)
49+
50+
! Set module directory (or leave unallocated because `optional`)
51+
if (has_install_config .and. allocated(package%install%module_dir)) &
52+
module_dir = package%install%module_dir
53+
4154
! ifx bug: does not resolve allocatable -> optional
42-
if (allocated(package%library)) then
55+
if (has_library) then
4356
call targets_from_sources(targets, model, settings%prune, package%library, error)
4457
else
4558
call targets_from_sources(targets, model, settings%prune, error=error)
@@ -49,8 +62,7 @@ subroutine cmd_install(settings)
4962
call install_info(output_unit, settings%list, targets, ntargets)
5063
if (settings%list) return
5164

52-
installable = (allocated(package%library) .and. package%install%library) &
53-
.or. allocated(package%executable) .or. ntargets>0
65+
installable = (has_library .and. install_library) .or. has_executables .or. ntargets>0
5466

5567
if (.not.installable) then
5668
call fatal_error(error, "Project does not contain any installable targets")
@@ -63,10 +75,10 @@ subroutine cmd_install(settings)
6375

6476
call new_installer(installer, prefix=settings%prefix, &
6577
bindir=settings%bindir, libdir=settings%libdir, testdir=settings%testdir, &
66-
includedir=settings%includedir, moduledir=package%install%module_dir, &
78+
includedir=settings%includedir, moduledir=module_dir, &
6779
verbosity=merge(2, 1, settings%verbose))
6880

69-
if (allocated(package%library) .and. package%install%library) then
81+
if (has_library .and. install_library) then
7082
call filter_library_targets(targets, libraries)
7183

7284
if (size(libraries) > 0) then
@@ -80,12 +92,12 @@ subroutine cmd_install(settings)
8092
end if
8193
end if
8294

83-
if (allocated(package%executable) .or. ntargets>0) then
95+
if (has_executables .or. ntargets>0) then
8496
call install_executables(installer, targets, error)
8597
call handle_error(error)
8698
end if
8799

88-
if (allocated(package%test) .and. (package%install%test .or. model%include_tests)) then
100+
if (allocated(package%test) .and. (install_tests .or. model%include_tests)) then
89101

90102
call install_tests(installer, targets, error)
91103
call handle_error(error)

0 commit comments

Comments
 (0)