Skip to content

Commit 0e42c57

Browse files
committed
Minor fix: for packages with empty target lists
Header-only libraries may result in no compile targets.
1 parent c41c39e commit 0e42c57

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

fpm/src/fpm.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ subroutine build_model(model, settings, package, error)
141141
if (allocated(error)) exit
142142

143143
model%packages(i)%name = dependency%name
144+
if (.not.allocated(model%packages(i)%sources)) allocate(model%packages(i)%sources(0))
144145

145146
if (allocated(dependency%library)) then
146147

fpm/src/fpm_targets.f90

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,20 @@ subroutine build_target_list(targets,model)
156156
!> The package model from which to construct the target list
157157
type(fpm_model_t), intent(inout), target :: model
158158

159-
integer :: i, j
159+
integer :: i, j, n_source
160160
character(:), allocatable :: xsuffix, exe_dir
161161
type(build_target_t), pointer :: dep
162162
logical :: with_lib
163163

164+
! Check for empty build (e.g. header-only lib)
165+
n_source = sum([(size(model%packages(j)%sources), &
166+
j=1,size(model%packages))])
167+
168+
if (n_source < 1) then
169+
allocate(targets(0))
170+
return
171+
end if
172+
164173
if (get_os_type() == OS_WINDOWS) then
165174
xsuffix = '.exe'
166175
else
@@ -435,6 +444,8 @@ subroutine resolve_target_linking(targets, model)
435444
character(:), allocatable :: global_link_flags
436445
character(:), allocatable :: global_compile_flags
437446

447+
if (size(targets) == 0) return
448+
438449
if (targets(1)%ptr%target_type == FPM_TARGET_ARCHIVE) then
439450
global_link_flags = targets(1)%ptr%output_file
440451
else

0 commit comments

Comments
 (0)