@@ -268,7 +268,7 @@ subroutine targets_from_sources(targets,model,prune,library,error)
268
268
if (present (library)) should_prune = should_prune .and. (library% lib_type/= " " )
269
269
if (should_prune) call prune_build_targets(targets,root_package= model% package_name)
270
270
271
- call resolve_target_linking(targets,model,error)
271
+ call resolve_target_linking(targets,model,library, error)
272
272
if (allocated (error)) return
273
273
274
274
end subroutine targets_from_sources
@@ -306,7 +306,7 @@ subroutine build_target_list(targets,model,library)
306
306
307
307
integer :: i, j, k, n_source, exe_type
308
308
character (:), allocatable :: exe_dir, compile_flags, lib_name
309
- logical :: with_lib, monolithic, shared_lib
309
+ logical :: with_lib, monolithic, shared_lib, static_lib
310
310
311
311
! Initialize targets
312
312
allocate (targets(0 ))
@@ -321,16 +321,14 @@ subroutine build_target_list(targets,model,library)
321
321
i= 1 ,size (model% packages(j)% sources)), &
322
322
j= 1 ,size (model% packages))])
323
323
324
- if (with_lib) then
325
- if (present (library)) then
326
- shared_lib = library% shared()
327
- else
328
- shared_lib = .false.
329
- end if
330
- monolithic = .not. shared_lib
324
+ if (with_lib .and. present (library)) then
325
+ shared_lib = library% shared()
326
+ static_lib = library% static()
327
+ monolithic = library% monolithic()
331
328
else
332
- monolithic = .false.
329
+ monolithic = with_lib
333
330
shared_lib = .false.
331
+ static_lib = .false.
334
332
end if
335
333
336
334
! For a static object archive, everything from this package or all its dependencies is
@@ -339,19 +337,19 @@ subroutine build_target_list(targets,model,library)
339
337
if (monolithic) then
340
338
341
339
lib_name = join_path(model% package_name, &
342
- library_filename(model% packages(1 )% name,shared_lib ,.false. ,get_os_type()))
340
+ library_filename(model% packages(1 )% name,.false. ,.false. ,get_os_type()))
343
341
344
342
call add_target(targets,package= model% package_name, &
345
343
type = FPM_TARGET_ARCHIVE,output_name = lib_name)
346
344
347
- elseif (shared_lib) then
348
- ! Shared libraries go to the same path as the `.mod` files (consistent linking directories)
345
+ elseif (shared_lib .or. static_lib ) then
346
+ ! Package libraries go to the same path as the `.mod` files (consistent linking directories)
349
347
do j= 1 ,size (model% packages)
350
348
351
349
lib_name = library_filename(model% packages(j)% name,shared_lib,.false. ,get_os_type())
352
350
353
351
call add_target(targets,package= model% packages(j)% name, &
354
- type = FPM_TARGET_SHARED,output_name = lib_name)
352
+ type = merge ( FPM_TARGET_SHARED,FPM_TARGET_ARCHIVE,shared_lib) ,output_name = lib_name)
355
353
end do
356
354
357
355
endif
@@ -380,7 +378,7 @@ subroutine build_target_list(targets,model,library)
380
378
381
379
if (with_lib .and. sources(i)% unit_scope == FPM_SCOPE_LIB) then
382
380
! Archive depends on object
383
- call add_dependency(targets(merge (j, 1 ,shared_lib ))% ptr, targets(size (targets))% ptr)
381
+ call add_dependency(targets(merge (1 ,j,monolithic ))% ptr, targets(size (targets))% ptr)
384
382
end if
385
383
386
384
case (FPM_UNIT_CPPSOURCE)
@@ -393,7 +391,7 @@ subroutine build_target_list(targets,model,library)
393
391
394
392
if (with_lib .and. sources(i)% unit_scope == FPM_SCOPE_LIB) then
395
393
! Archive depends on object
396
- call add_dependency(targets(merge (j, 1 ,shared_lib ))% ptr, targets(size (targets))% ptr)
394
+ call add_dependency(targets(merge (1 ,j,monolithic ))% ptr, targets(size (targets))% ptr)
397
395
end if
398
396
399
397
! > Add stdc++ as a linker flag. If not already there.
@@ -460,7 +458,7 @@ subroutine build_target_list(targets,model,library)
460
458
461
459
if (with_lib) then
462
460
! Executable depends on library file(s)
463
- do k= 1 ,merge (size (model% packages),1 ,shared_lib )
461
+ do k= 1 ,merge (1 , size (model% packages),monolithic )
464
462
call add_dependency(target , targets(k)% ptr)
465
463
end do
466
464
end if
@@ -944,13 +942,14 @@ end subroutine prune_build_targets
944
942
! > Construct the linker flags string for each target
945
943
! > `target%link_flags` includes non-library objects and library flags
946
944
! >
947
- subroutine resolve_target_linking (targets , model , error )
945
+ subroutine resolve_target_linking (targets , model , library , error )
948
946
type (build_target_ptr), intent (inout ), target :: targets(:)
949
947
type (fpm_model_t), intent (in ) :: model
948
+ type (library_config_t), intent (in ), optional :: library
950
949
type (error_t), allocatable , intent (out ) :: error
951
950
952
951
integer :: i,j
953
- logical :: shared,has_self_lib
952
+ logical :: shared,static,monolithic, has_self_lib
954
953
integer , allocatable :: package_deps(:)
955
954
character (:), allocatable :: global_link_flags, local_link_flags
956
955
character (:), allocatable :: global_include_flags, shared_lib_paths
@@ -963,7 +962,7 @@ subroutine resolve_target_linking(targets, model, error)
963
962
global_link_flags = model% compiler% enumerate_libraries(global_link_flags, model% link_libraries)
964
963
end if
965
964
end if
966
-
965
+
967
966
allocate (character (0 ) :: global_include_flags)
968
967
if (allocated (model% include_dirs)) then
969
968
if (size (model% include_dirs) > 0 ) then
@@ -972,7 +971,16 @@ subroutine resolve_target_linking(targets, model, error)
972
971
end if
973
972
end if
974
973
975
- shared = .false.
974
+ if (present (library)) then
975
+ shared = library% shared()
976
+ static = library% static()
977
+ monolithic = library% monolithic()
978
+ else
979
+ shared = .false.
980
+ static = .false.
981
+ monolithic = .true.
982
+ end if
983
+
976
984
do i= 1 ,size (targets)
977
985
978
986
associate(target = > targets(i)% ptr)
@@ -1024,7 +1032,8 @@ subroutine resolve_target_linking(targets, model, error)
1024
1032
select case (target % target_type)
1025
1033
case (FPM_TARGET_ARCHIVE)
1026
1034
1027
- global_link_flags = target % output_file // global_link_flags
1035
+ ! This adds the monolithic archive to the link flags
1036
+ if (monolithic) global_link_flags = " " // target % output_file // global_link_flags
1028
1037
1029
1038
call get_link_objects(target % link_objects,target ,is_exe= .false. )
1030
1039
@@ -1041,7 +1050,7 @@ subroutine resolve_target_linking(targets, model, error)
1041
1050
target % link_flags = target % link_flags // shared_lib_paths
1042
1051
1043
1052
! Add dependencies' shared libraries (excluding self)
1044
- target % link_flags = model% get_shared_libraries_link (target % package_name, &
1053
+ target % link_flags = model% get_package_libraries_link (target % package_name, &
1045
1054
target % link_flags, &
1046
1055
exclude_self= .true. , &
1047
1056
dep_IDs= package_deps, &
@@ -1077,7 +1086,7 @@ subroutine resolve_target_linking(targets, model, error)
1077
1086
target % link_flags = model% link_flags// " " // string_cat(target % link_objects," " )
1078
1087
1079
1088
! Add shared libs
1080
- if (shared ) then
1089
+ if (.not. monolithic ) then
1081
1090
1082
1091
target % link_flags = target % link_flags // shared_lib_paths
1083
1092
@@ -1095,7 +1104,7 @@ subroutine resolve_target_linking(targets, model, error)
1095
1104
end do find_self
1096
1105
1097
1106
! Add dependencies' shared libraries (including self if there is a library)
1098
- target % link_flags = model% get_shared_libraries_link (target % package_name, &
1107
+ target % link_flags = model% get_package_libraries_link (target % package_name, &
1099
1108
target % link_flags, &
1100
1109
error= error, &
1101
1110
exclude_self= .not. has_self_lib)
@@ -1109,7 +1118,7 @@ subroutine resolve_target_linking(targets, model, error)
1109
1118
end if
1110
1119
1111
1120
target % link_flags = target % link_flags// " " // global_link_flags
1112
-
1121
+
1113
1122
end select
1114
1123
1115
1124
end associate
@@ -1208,7 +1217,7 @@ subroutine get_library_dirs(model, targets, shared_lib_dirs)
1208
1217
1209
1218
do i = 1 , size (targets)
1210
1219
associate(target = > targets(i)% ptr)
1211
- if (target % target_type /= FPM_TARGET_SHARED) cycle
1220
+ if (all ( target % target_type /= [ FPM_TARGET_SHARED,FPM_TARGET_ARCHIVE]) ) cycle
1212
1221
if (target % output_dir .in . shared_lib_dirs) cycle
1213
1222
temp = string_t(target % output_dir)
1214
1223
shared_lib_dirs = [shared_lib_dirs, temp]
0 commit comments