@@ -124,6 +124,7 @@ module fpm_compiler
124
124
procedure :: load_from_toml = > compiler_load
125
125
! > Fortran feature support
126
126
procedure :: check_fortran_source_runs
127
+ procedure :: check_flags_supported
127
128
procedure :: with_xdp
128
129
procedure :: with_qp
129
130
! > Return compiler name
@@ -1440,14 +1441,16 @@ end function compiler_name
1440
1441
1441
1442
! > Run a single-source Fortran program using the current compiler
1442
1443
! > Compile a Fortran object
1443
- logical function check_fortran_source_runs (self , input ) result(success)
1444
+ logical function check_fortran_source_runs (self , input , compile_flags , link_flags ) result(success)
1444
1445
! > Instance of the compiler object
1445
1446
class(compiler_t), intent (in ) :: self
1446
1447
! > Program Source
1447
1448
character (len=* ), intent (in ) :: input
1449
+ ! > Optional build and link flags
1450
+ character (len=* ), optional , intent (in ) :: compile_flags, link_flags
1448
1451
1449
1452
integer :: stat,unit
1450
- character (:), allocatable :: source,object,logf,exe
1453
+ character (:), allocatable :: source,object,logf,exe,flags,ldflags
1451
1454
1452
1455
success = .false.
1453
1456
@@ -1463,10 +1466,17 @@ logical function check_fortran_source_runs(self, input) result(success)
1463
1466
write (unit,* ) input
1464
1467
close (unit)
1465
1468
1469
+ ! > Get flags
1470
+ flags = self% get_default_flags(release= .false. )
1471
+ ldflags = self% get_default_flags(release= .false. )
1472
+
1473
+ if (present (compile_flags)) flags = flags// " " // compile_flags
1474
+ if (present (link_flags)) ldflags = ldflags// " " // link_flags
1475
+
1466
1476
! > Compile and link program
1467
- call self% compile_fortran(source, object, self % get_default_flags(release = .false. ) , logf, stat)
1477
+ call self% compile_fortran(source, object, flags , logf, stat)
1468
1478
if (stat== 0 ) &
1469
- call self% link(exe, self % get_default_flags(release = .false. ) // " " // object, logf, stat)
1479
+ call self% link(exe, ldflags // " " // object, logf, stat)
1470
1480
1471
1481
! > Run and retrieve exit code
1472
1482
if (stat== 0 ) &
@@ -1487,6 +1497,18 @@ logical function check_fortran_source_runs(self, input) result(success)
1487
1497
1488
1498
end function check_fortran_source_runs
1489
1499
1500
+ ! > Check if the given compile and/or link flags are accepted by the compiler
1501
+ logical function check_flags_supported (self , compile_flags , link_flags )
1502
+ class(compiler_t), intent (in ) :: self
1503
+ character (len=* ), optional , intent (in ) :: compile_flags, link_flags
1504
+
1505
+ ! Minimal program that always compiles
1506
+ character (len=* ), parameter :: hello_world = " print *, 'Hello, World!'; end"
1507
+
1508
+ check_flags_supported = self% check_fortran_source_runs(hello_world, compile_flags, link_flags)
1509
+
1510
+ end function check_flags_supported
1511
+
1490
1512
! > Check if the current compiler supports 128-bit real precision
1491
1513
logical function with_qp (self )
1492
1514
! > Instance of the compiler object
0 commit comments