public function is_cxx_gnu_based(self) result(is_gnu)
Check if C++ compiler is GNU-based by checking its version output
Arguments
Type |
Intent | Optional | Attributes |
|
Name |
|
class(compiler_t),
|
intent(in) |
|
|
:: |
self |
|
Return Value
logical
Variables
Type |
Visibility | Attributes |
|
Name |
| Initial | |
integer,
|
public |
|
:: |
io |
|
|
|
character(len=:),
|
public, |
allocatable
|
:: |
output_file |
|
|
|
integer,
|
public |
|
:: |
stat |
|
|
|
character(len=:),
|
public, |
allocatable
|
:: |
version_output |
|
|
|
Source Code
function is_cxx_gnu_based(self) result(is_gnu)
class(compiler_t), intent(in) :: self
logical :: is_gnu
character(len=:), allocatable :: output_file, version_output
integer :: stat, io
is_gnu = .false.
if (.not.allocated(self%cxx)) return
if (len_trim(self%cxx)<=0) return
! Get temporary file for compiler version output
output_file = get_temp_filename()
! Run compiler with --version to get version info
call run(self%cxx//" --version > "//output_file//" 2>&1", &
echo=.false., exitstat=stat)
if (stat == 0) then
! Read the version output
open(file=output_file, newunit=io, iostat=stat)
if (stat == 0) then
call getline(io, version_output, stat)
close(io, iostat=stat)
! Check if output contains GNU indicators
if (allocated(version_output)) then
is_gnu = index(version_output, 'gcc') > 0 .or. &
index(version_output, 'GCC') > 0 .or. &
index(version_output, 'GNU') > 0 .or. &
index(version_output, 'Free Software Foundation') > 0
end if
end if
end if
! Clean up temporary file
call run("rm -f "//output_file, echo=.false., exitstat=stat)
end function is_cxx_gnu_based