@@ -270,7 +270,7 @@ subroutine targets_from_sources(targets,model,prune,library,error)
270
270
should_prune = prune
271
271
if (present (library)) should_prune = should_prune .and. library% monolithic()
272
272
273
- if (should_prune) call prune_build_targets(targets,root_package = model% package_name)
273
+ call prune_build_targets(targets,model% package_name,should_prune )
274
274
275
275
call resolve_target_linking(targets,model,library,error)
276
276
if (allocated (error)) return
@@ -737,13 +737,16 @@ end function find_module_dependency
737
737
738
738
739
739
! > Perform tree-shaking to remove unused module targets
740
- subroutine prune_build_targets (targets , root_package )
740
+ subroutine prune_build_targets (targets , root_package , prune_unused_objects )
741
741
742
742
! > Build target list to prune
743
743
type (build_target_ptr), intent (inout ), allocatable :: targets(:)
744
744
745
745
! > Name of root package
746
746
character (* ), intent (in ) :: root_package
747
+
748
+ ! > Whether unused objects should be pruned
749
+ logical , intent (in ) :: prune_unused_objects
747
750
748
751
integer :: i, j, nexec
749
752
type (string_t), allocatable :: modules_used(:)
@@ -805,8 +808,8 @@ subroutine prune_build_targets(targets, root_package)
805
808
if (allocated (target % source)) then
806
809
if (target % source% unit_type == FPM_UNIT_MODULE) then
807
810
808
- exclude_target(i) = .true.
809
- target % skip = .true.
811
+ exclude_target(i) = prune_unused_objects
812
+ target % skip = prune_unused_objects
810
813
811
814
do j= 1 ,size (target % source% modules_provided)
812
815
@@ -822,8 +825,8 @@ subroutine prune_build_targets(targets, root_package)
822
825
elseif (target % source% unit_type == FPM_UNIT_SUBMODULE) then
823
826
! Remove submodules if their parents are not used
824
827
825
- exclude_target(i) = .true.
826
- target % skip = .true.
828
+ exclude_target(i) = prune_unused_objects
829
+ target % skip = prune_unused_objects
827
830
do j= 1 ,size (target % source% parent_modules)
828
831
829
832
if (target % source% parent_modules(j)% s .in . modules_used) then
@@ -1106,8 +1109,8 @@ subroutine resolve_target_linking(targets, model, library, error)
1106
1109
has_self_lib = .false.
1107
1110
find_self: do j= 1 ,size (targets)
1108
1111
associate(target_loop= >targets(j)% ptr)
1109
- if (target_loop% target_type== FPM_TARGET_SHARED .and. &
1110
- target_loop% package_name== target % package_name) then
1112
+ if (any ( target_loop% target_type==[ FPM_TARGET_SHARED,FPM_TARGET_ARCHIVE]) &
1113
+ .and. target_loop% package_name== target % package_name) then
1111
1114
has_self_lib = .true.
1112
1115
exit find_self
1113
1116
end if
0 commit comments