diff --git a/src/fpm_compiler.f90 b/src/fpm_compiler.f90 index a499bb9e18..ec6557125b 100644 --- a/src/fpm_compiler.f90 +++ b/src/fpm_compiler.f90 @@ -35,7 +35,10 @@ module fpm_compiler OS_WINDOWS, & OS_CYGWIN, & OS_SOLARIS, & - OS_FREEBSD + OS_FREEBSD, & + os_is_unix, & + get_env +use fpm_strings, only : split implicit none public :: is_unknown_compiler public :: get_module_flags @@ -310,6 +313,8 @@ subroutine get_module_flags(compiler, modpath, flags) case(id_caf, id_gcc, id_f95, id_cray) flags=' -J '//modpath//' -I '//modpath + call append_cpath(flags) + case(id_nvhpc, id_pgi, id_flang) flags=' -module '//modpath//' -I '//modpath @@ -439,4 +444,20 @@ function is_unknown_compiler(compiler) result(is_unknown) is_unknown = get_compiler_id(compiler) == id_unknown end function is_unknown_compiler +subroutine append_cpath(flags) + character(len=:), allocatable, intent(inout) :: flags + character(len=:), allocatable :: cpath, dirs(:) + integer :: i + cpath = get_env('CPATH') + if (len(cpath) > 0) then + call split(cpath, dirs, delimiters=merge(":", ";", os_is_unix())) + do i = 1, size(dirs) + ! dir can be an empty string for leading or trailing delimiters + if (len_trim(dirs(i)) > 0) then + flags = flags // ' -I ' // trim(dirs(i)) + end if + end do + end if +end subroutine append_cpath + end module fpm_compiler diff --git a/src/fpm_environment.f90 b/src/fpm_environment.f90 index 0408ec4ec4..1b1ea0affb 100644 --- a/src/fpm_environment.f90 +++ b/src/fpm_environment.f90 @@ -121,7 +121,7 @@ logical function os_is_unix(os) result(unix) else build_os = get_os_type() end if - unix = os /= OS_WINDOWS + unix = build_os /= OS_WINDOWS end function os_is_unix !> echo command string and pass it to the system for execution