@@ -29,7 +29,7 @@ module fpm_targets
29
29
use fpm_model
30
30
use fpm_environment, only: get_os_type, OS_WINDOWS, OS_MACOS
31
31
use fpm_filesystem, only: dirname, join_path, canon_path
32
- use fpm_strings, only: string_t, operator (.in .), string_cat, fnv_1a, resize
32
+ use fpm_strings, only: string_t, operator (.in .), string_cat, fnv_1a, resize, lower, str_ends_with
33
33
use fpm_compiler, only: get_macros
34
34
implicit none
35
35
@@ -189,7 +189,7 @@ subroutine build_target_list(targets,model)
189
189
! > The package model from which to construct the target list
190
190
type (fpm_model_t), intent (inout ), target :: model
191
191
192
- integer :: i, j, n_source
192
+ integer :: i, j, n_source, exe_type
193
193
character (:), allocatable :: xsuffix, exe_dir
194
194
logical :: with_lib
195
195
@@ -268,7 +268,15 @@ subroutine build_target_list(targets,model)
268
268
269
269
case (FPM_UNIT_PROGRAM)
270
270
271
- call add_target(targets,package= model% packages(j)% name,type = FPM_TARGET_OBJECT,&
271
+ if (str_ends_with(lower(sources(i)% file_name), [" .c" ])) then
272
+ exe_type = FPM_TARGET_C_OBJECT
273
+ else if (str_ends_with(lower(sources(i)% file_name), [" .cpp" , " .cc " ])) then
274
+ exe_type = FPM_TARGET_CPP_OBJECT
275
+ else ! Default to a Fortran object
276
+ exe_type = FPM_TARGET_OBJECT
277
+ end if
278
+
279
+ call add_target(targets,package= model% packages(j)% name,type = exe_type,&
272
280
output_name = get_object_name(sources(i)), &
273
281
source = sources(i) &
274
282
)
0 commit comments