@@ -125,6 +125,7 @@ module fpm_compiler
125
125
procedure :: load_from_toml = > compiler_load
126
126
! > Fortran feature support
127
127
procedure :: check_fortran_source_runs
128
+ procedure :: check_flags_supported
128
129
procedure :: with_xdp
129
130
procedure :: with_qp
130
131
! > Return compiler name
@@ -1452,14 +1453,16 @@ end function compiler_name
1452
1453
1453
1454
! > Run a single-source Fortran program using the current compiler
1454
1455
! > Compile a Fortran object
1455
- logical function check_fortran_source_runs (self , input ) result(success)
1456
+ logical function check_fortran_source_runs (self , input , compile_flags , link_flags ) result(success)
1456
1457
! > Instance of the compiler object
1457
1458
class(compiler_t), intent (in ) :: self
1458
1459
! > Program Source
1459
1460
character (len=* ), intent (in ) :: input
1461
+ ! > Optional build and link flags
1462
+ character (len=* ), optional , intent (in ) :: compile_flags, link_flags
1460
1463
1461
1464
integer :: stat,unit
1462
- character (:), allocatable :: source,object,logf,exe
1465
+ character (:), allocatable :: source,object,logf,exe,flags,ldflags
1463
1466
1464
1467
success = .false.
1465
1468
@@ -1475,10 +1478,17 @@ logical function check_fortran_source_runs(self, input) result(success)
1475
1478
write (unit,* ) input
1476
1479
close (unit)
1477
1480
1481
+ ! > Get flags
1482
+ flags = self% get_default_flags(release= .false. )
1483
+ ldflags = self% get_default_flags(release= .false. )
1484
+
1485
+ if (present (compile_flags)) flags = flags// " " // compile_flags
1486
+ if (present (link_flags)) ldflags = ldflags// " " // link_flags
1487
+
1478
1488
! > Compile and link program
1479
- call self% compile_fortran(source, object, self % get_default_flags(release = .false. ) , logf, stat)
1489
+ call self% compile_fortran(source, object, flags , logf, stat)
1480
1490
if (stat== 0 ) &
1481
- call self% link(exe, self % get_default_flags(release = .false. ) // " " // object, logf, stat)
1491
+ call self% link(exe, ldflags // " " // object, logf, stat)
1482
1492
1483
1493
! > Run and retrieve exit code
1484
1494
if (stat== 0 ) &
@@ -1499,6 +1509,18 @@ logical function check_fortran_source_runs(self, input) result(success)
1499
1509
1500
1510
end function check_fortran_source_runs
1501
1511
1512
+ ! > Check if the given compile and/or link flags are accepted by the compiler
1513
+ logical function check_flags_supported (self , compile_flags , link_flags )
1514
+ class(compiler_t), intent (in ) :: self
1515
+ character (len=* ), optional , intent (in ) :: compile_flags, link_flags
1516
+
1517
+ ! Minimal program that always compiles
1518
+ character (len=* ), parameter :: hello_world = " print *, 'Hello, World!'; end"
1519
+
1520
+ check_flags_supported = self% check_fortran_source_runs(hello_world, compile_flags, link_flags)
1521
+
1522
+ end function check_flags_supported
1523
+
1502
1524
! > Check if the current compiler supports 128-bit real precision
1503
1525
logical function with_qp (self )
1504
1526
! > Instance of the compiler object
0 commit comments