Skip to content

Commit 7f93b47

Browse files
committed
bug: C preprocessor does not propagate directives to executables
Fixes #774
1 parent 80cdd61 commit 7f93b47

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/fpm_targets.f90

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module fpm_targets
2929
use fpm_model
3030
use fpm_environment, only: get_os_type, OS_WINDOWS, OS_MACOS
3131
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
3333
use fpm_compiler, only: get_macros
3434
implicit none
3535

@@ -189,7 +189,7 @@ subroutine build_target_list(targets,model)
189189
!> The package model from which to construct the target list
190190
type(fpm_model_t), intent(inout), target :: model
191191

192-
integer :: i, j, n_source
192+
integer :: i, j, n_source, exe_type
193193
character(:), allocatable :: xsuffix, exe_dir
194194
logical :: with_lib
195195

@@ -268,7 +268,15 @@ subroutine build_target_list(targets,model)
268268

269269
case (FPM_UNIT_PROGRAM)
270270

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,&
272280
output_name = get_object_name(sources(i)), &
273281
source = sources(i) &
274282
)

0 commit comments

Comments
 (0)