Skip to content

Commit c957b27

Browse files
committed
Select c compiler based on fortran compiler id
1 parent f28ac3e commit c957b27

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

src/fpm.f90

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module fpm
99
use fpm_model, only: fpm_model_t, srcfile_t, show_model, &
1010
FPM_SCOPE_UNKNOWN, FPM_SCOPE_LIB, FPM_SCOPE_DEP, &
1111
FPM_SCOPE_APP, FPM_SCOPE_EXAMPLE, FPM_SCOPE_TEST
12-
use fpm_compiler, only: get_module_flags, is_unknown_compiler
12+
use fpm_compiler, only: get_module_flags, is_unknown_compiler, get_default_c_compiler
1313

1414

1515
use fpm_sources, only: add_executable_sources, add_sources_from_dir
@@ -62,6 +62,8 @@ subroutine build_model(model, settings, package, error)
6262
model%fortran_compiler = settings%compiler
6363
endif
6464

65+
call get_default_c_compiler(model%fortran_compiler, model%c_compiler)
66+
6567
if (is_unknown_compiler(model%fortran_compiler)) then
6668
write(*, '(*(a:,1x))') &
6769
"<WARN>", "Unknown compiler", model%fortran_compiler, "requested!", &
@@ -178,6 +180,7 @@ subroutine build_model(model, settings, package, error)
178180
if (settings%verbose) then
179181
write(*,*)'<INFO> BUILD_NAME: ',settings%build_name
180182
write(*,*)'<INFO> COMPILER: ',settings%compiler
183+
write(*,*)'<INFO> C COMPILER: ',model%c_compiler
181184
write(*,*)'<INFO> COMPILER OPTIONS: ', model%fortran_compile_flags
182185
write(*,*)'<INFO> INCLUDE DIRECTORIES: [', string_cat(model%include_dirs,','),']'
183186
end if

src/fpm_compiler.f90

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,33 @@ subroutine get_module_flags(compiler, modpath, flags)
336336

337337
end subroutine get_module_flags
338338

339+
subroutine get_default_c_compiler(f_compiler, c_compiler)
340+
character(len=*), intent(in) :: f_compiler
341+
character(len=:), allocatable, intent(out) :: c_compiler
342+
integer(compiler_enum) :: id
343+
344+
id = get_compiler_id(f_compiler)
345+
346+
select case(id)
347+
case default
348+
c_compiler = 'gcc'
349+
350+
case(id_intel_classic)
351+
c_compiler = 'icc'
352+
353+
case(id_intel_llvm)
354+
c_compiler = 'icx'
355+
356+
case(id_flang)
357+
c_compiler='clang'
358+
359+
case(id_ibmxl)
360+
c_compiler='xlc'
361+
362+
end select
363+
364+
end subroutine get_default_c_compiler
365+
339366
function get_compiler_id(compiler) result(id)
340367
character(len=*), intent(in) :: compiler
341368
integer(kind=compiler_enum) :: id

src/fpm_model.f90

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ module fpm_model
117117
!> Command line name to invoke fortran compiler
118118
character(:), allocatable :: fortran_compiler
119119

120+
!> Command line name to invoke c compiler
121+
character(:), allocatable :: c_compiler
122+
120123
!> Command line flags passed to fortran for compilation
121124
character(:), allocatable :: fortran_compile_flags
122125

0 commit comments

Comments
 (0)