@@ -119,6 +119,10 @@ module fpm_compiler
119119 procedure :: serializable_is_same = > compiler_is_same
120120 procedure :: dump_to_toml = > compiler_dump
121121 procedure :: load_from_toml = > compiler_load
122+ ! > Fortran feature support
123+ procedure :: check_fortran_source_runs
124+ procedure :: with_xdp
125+ procedure :: with_qp
122126 ! > Return compiler name
123127 procedure :: name = > compiler_name
124128
@@ -1034,6 +1038,7 @@ subroutine new_compiler(self, fc, cc, cxx, echo, verbose)
10341038 else
10351039 call get_default_cxx_compiler(self% fc, self% cxx)
10361040 end if
1041+
10371042end subroutine new_compiler
10381043
10391044
@@ -1424,6 +1429,69 @@ pure function compiler_name(self) result(name)
14241429 end select
14251430end function compiler_name
14261431
1432+ ! > Run a single-source Fortran program using the current compiler
1433+ ! > Compile a Fortran object
1434+ logical function check_fortran_source_runs (self , input ) result(success)
1435+ ! > Instance of the compiler object
1436+ class(compiler_t), intent (in ) :: self
1437+ ! > Program Source
1438+ character (len=* ), intent (in ) :: input
1439+
1440+ integer :: stat,unit
1441+ character (:), allocatable :: source,object,logf,exe
1442+
1443+ success = .false.
1444+
1445+ ! > Create temporary source file
1446+ exe = get_temp_filename()
1447+ source = exe// ' .f90'
1448+ object = exe// ' .o'
1449+ logf = exe// ' .log'
1450+ open (newunit= unit, file= source, action= ' readwrite' , iostat= stat)
1451+ if (stat/= 0 ) return
1452+
1453+ ! > Write contents
1454+ write (unit,* ) input
1455+ close (unit)
1456+
1457+ ! > Compile and link program
1458+ call self% compile_fortran(source, object, self% get_default_flags(release= .false. ), logf, stat)
1459+ if (stat== 0 ) &
1460+ call self% link(exe, self% get_default_flags(release= .false. )// " " // object, logf, stat)
1461+
1462+ ! > Run and retrieve exit code
1463+ if (stat== 0 ) &
1464+ call run(exe,echo= .false. , exitstat= stat, verbose= .false. , redirect= logf)
1465+
1466+ ! > Successful exit on 0 exit code
1467+ success = stat== 0
1468+
1469+ ! > Delete files
1470+ open (newunit= unit, file= source, action= ' readwrite' , iostat= stat)
1471+ close (unit,status= ' delete' )
1472+ open (newunit= unit, file= object, action= ' readwrite' , iostat= stat)
1473+ close (unit,status= ' delete' )
1474+ open (newunit= unit, file= logf, action= ' readwrite' , iostat= stat)
1475+ close (unit,status= ' delete' )
1476+ open (newunit= unit, file= exe, action= ' readwrite' , iostat= stat)
1477+ close (unit,status= ' delete' )
1478+
1479+ end function check_fortran_source_runs
1480+
1481+ ! > Check if the current compiler supports 128-bit real precision
1482+ logical function with_qp (self )
1483+ ! > Instance of the compiler object
1484+ class(compiler_t), intent (in ) :: self
1485+ with_qp = self% check_fortran_source_runs &
1486+ (' if (selected_real_kind(33) == -1) stop 1; end' )
1487+ end function with_qp
14271488
1489+ ! > Check if the current compiler supports 80-bit "extended" real precision
1490+ logical function with_xdp (self )
1491+ ! > Instance of the compiler object
1492+ class(compiler_t), intent (in ) :: self
1493+ with_xdp = self% check_fortran_source_runs &
1494+ (' if (any(selected_real_kind(18) == [-1, selected_real_kind(33)])) stop 1; end' )
1495+ end function with_xdp
14281496
14291497end module fpm_compiler
0 commit comments