Skip to content

Allow to find include files / modules in CPATH environment variable #444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/fpm_compiler.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/fpm_environment.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down