@@ -29,7 +29,9 @@ subroutine cmd_install(settings)
29
29
type (build_target_ptr), allocatable :: targets(:), libraries(:)
30
30
type (installer_t) :: installer
31
31
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
33
35
integer :: ntargets,i
34
36
35
37
call get_package_data(package, " fpm.toml" , error, apply_defaults= .true. )
@@ -38,8 +40,19 @@ subroutine cmd_install(settings)
38
40
call build_model(model, settings, package, error)
39
41
call handle_error(error)
40
42
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
+
41
54
! ifx bug: does not resolve allocatable -> optional
42
- if (allocated (package % library) ) then
55
+ if (has_library ) then
43
56
call targets_from_sources(targets, model, settings% prune, package% library, error)
44
57
else
45
58
call targets_from_sources(targets, model, settings% prune, error= error)
@@ -49,8 +62,7 @@ subroutine cmd_install(settings)
49
62
call install_info(output_unit, settings% list, targets, ntargets)
50
63
if (settings% list) return
51
64
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
54
66
55
67
if (.not. installable) then
56
68
call fatal_error(error, " Project does not contain any installable targets" )
@@ -63,10 +75,10 @@ subroutine cmd_install(settings)
63
75
64
76
call new_installer(installer, prefix= settings% prefix, &
65
77
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, &
67
79
verbosity= merge (2 , 1 , settings% verbose))
68
80
69
- if (allocated (package % library) .and. package % install % library ) then
81
+ if (has_library .and. install_library ) then
70
82
call filter_library_targets(targets, libraries)
71
83
72
84
if (size (libraries) > 0 ) then
@@ -80,12 +92,12 @@ subroutine cmd_install(settings)
80
92
end if
81
93
end if
82
94
83
- if (allocated (package % executable) .or. ntargets> 0 ) then
95
+ if (has_executables .or. ntargets> 0 ) then
84
96
call install_executables(installer, targets, error)
85
97
call handle_error(error)
86
98
end if
87
99
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
89
101
90
102
call install_tests(installer, targets, error)
91
103
call handle_error(error)
0 commit comments