Skip to content

Commit 1d77188

Browse files
committed
Introspect BLAS compiler flags
1 parent 199ef86 commit 1d77188

File tree

1 file changed

+35
-15
lines changed

1 file changed

+35
-15
lines changed

src/metapackage/fpm_meta_blas.f90

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module fpm_meta_blas
22
use fpm_compiler, only: compiler_t, get_include_flag
3-
use fpm_environment, only: get_os_type, OS_MACOS
3+
use fpm_environment, only: get_os_type, OS_MACOS, OS_WINDOWS
44
use fpm_meta_base, only: metapackage_t, destroy
55
use fpm_meta_util, only: add_pkg_config_compile_options
66
use fpm_pkg_config, only: assert_pkg_config, pkgcfg_has_package
@@ -36,24 +36,22 @@ subroutine init_blas(this, compiler, error)
3636
this%has_external_modules = .false.
3737

3838
if (get_os_type() == OS_MACOS) then
39-
this%flags = string_t("-framework Accelerate")
40-
this%has_build_flags = .true.
41-
this%link_flags = string_t("-framework Accelerate")
42-
this%has_link_flags = .true.
43-
return
39+
if (compile_and_link_flags_supported(this, compiler, "-framework Accelerate")) then
40+
call set_compile_and_link_flags(this, compiler, "-framework Accelerate")
41+
return
42+
end if
4443
end if
4544

4645
if (compiler%is_intel()) then
47-
if (get_os_type() == OS_WINDOWS) then
48-
this%flags = string_t("/Qmkl")
49-
this%link_flags = string_t("/Qmkl")
50-
else
51-
this%flags = string_t("-qmkl")
52-
this%link_flags = string_t("-qmkl")
46+
if (get_os_type() == OS_WINDOWS) then
47+
if (compile_and_link_flags_supported(this, compiler, "/Qmkl")) then
48+
call set_compile_and_link_flags(this, compiler, "/Qmkl")
49+
return
50+
end if
51+
else if (compile_and_link_flags_supported(this, compiler, "-qmkl")) then
52+
call set_compile_and_link_flags(this, compiler, "-Qmkl")
53+
return
5354
endif
54-
this%has_build_flags = .true.
55-
this%has_link_flags = .true.
56-
return
5755
end if
5856

5957
!> Assert pkg-config is installed
@@ -73,4 +71,26 @@ subroutine init_blas(this, compiler, error)
7371

7472
call fatal_error(error, 'pkg-config could not find a suitable blas package.')
7573
end subroutine init_blas
74+
75+
function compile_and_link_flags_supported(this, compiler, flags) result(is_supported)
76+
class(metapackage_t), intent(in) :: this
77+
type(compiler_t), intent(in) :: compiler
78+
character(len=*), intent(in) :: flags
79+
logical :: is_supported
80+
81+
is_supported = compiler%check_flags_supported( &
82+
compile_flags=flags, &
83+
link_flags=flags)
84+
end function compile_and_link_flags_supported
85+
86+
subroutine set_compile_and_link_flags(this, compiler, flags)
87+
class(metapackage_t), intent(inout) :: this
88+
type(compiler_t), intent(in) :: compiler
89+
character(len=*), intent(in) :: flags
90+
91+
this%flags = string_t(flags)
92+
this%link_flags = string_t(flags)
93+
this%has_build_flags = .true.
94+
this%has_link_flags = .true.
95+
end subroutine set_compile_and_link_flags
7696
end module fpm_meta_blas

0 commit comments

Comments
 (0)