Skip to content

Commit 9ef7a9e

Browse files
committed
always prune empty libraries
1 parent f434cb0 commit 9ef7a9e

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

bin/fpm

4.46 MB
Binary file not shown.

example_packages/static_app_only/fpm.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# App only, use shared lib from other folder
2-
name = "shared_app_only"
2+
name = "static_app_only"
33
library.type="static"
44
install.library=true
55
[dependencies]

src/fpm_targets.f90

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ subroutine targets_from_sources(targets,model,prune,library,error)
270270
should_prune = prune
271271
if (present(library)) should_prune = should_prune .and. library%monolithic()
272272

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)
274274

275275
call resolve_target_linking(targets,model,library,error)
276276
if (allocated(error)) return
@@ -737,13 +737,16 @@ end function find_module_dependency
737737

738738

739739
!> 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)
741741

742742
!> Build target list to prune
743743
type(build_target_ptr), intent(inout), allocatable :: targets(:)
744744

745745
!> Name of root package
746746
character(*), intent(in) :: root_package
747+
748+
!> Whether unused objects should be pruned
749+
logical, intent(in) :: prune_unused_objects
747750

748751
integer :: i, j, nexec
749752
type(string_t), allocatable :: modules_used(:)
@@ -805,8 +808,8 @@ subroutine prune_build_targets(targets, root_package)
805808
if (allocated(target%source)) then
806809
if (target%source%unit_type == FPM_UNIT_MODULE) then
807810

808-
exclude_target(i) = .true.
809-
target%skip = .true.
811+
exclude_target(i) = prune_unused_objects
812+
target%skip = prune_unused_objects
810813

811814
do j=1,size(target%source%modules_provided)
812815

@@ -822,8 +825,8 @@ subroutine prune_build_targets(targets, root_package)
822825
elseif (target%source%unit_type == FPM_UNIT_SUBMODULE) then
823826
! Remove submodules if their parents are not used
824827

825-
exclude_target(i) = .true.
826-
target%skip = .true.
828+
exclude_target(i) = prune_unused_objects
829+
target%skip = prune_unused_objects
827830
do j=1,size(target%source%parent_modules)
828831

829832
if (target%source%parent_modules(j)%s .in. modules_used) then
@@ -1106,8 +1109,8 @@ subroutine resolve_target_linking(targets, model, library, error)
11061109
has_self_lib = .false.
11071110
find_self: do j=1,size(targets)
11081111
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
11111114
has_self_lib = .true.
11121115
exit find_self
11131116
end if

0 commit comments

Comments
 (0)