@@ -809,8 +809,7 @@ function save_library_path() result(path)
809
809
case (OS_WINDOWS)
810
810
path = get_env(" PATH" , default= " " )
811
811
case (OS_MACOS)
812
- ! macOS does not use LD_LIBRARY_PATH by default for `.dylib`
813
- allocate (character (0 ) :: path)
812
+ path = get_env(" DYLD_LIBRARY_PATH" , default= " " )
814
813
case default ! UNIX/Linux
815
814
path = get_env(" LD_LIBRARY_PATH" , default= " " )
816
815
end select
@@ -823,7 +822,7 @@ subroutine set_library_path(model, targets, error)
823
822
type (error_t), allocatable , intent (out ) :: error
824
823
825
824
type (string_t), allocatable :: shared_lib_dirs(:)
826
- character (len= :), allocatable :: new_path, sep
825
+ character (len= :), allocatable :: new_path, sep, current
827
826
logical :: success
828
827
integer :: i
829
828
@@ -839,30 +838,32 @@ subroutine set_library_path(model, targets, error)
839
838
end select
840
839
841
840
! Join the directories into a path string
842
- ! Manually join paths
843
841
new_path = " "
844
842
do i = 1 , size (shared_lib_dirs)
845
843
if (i > 1 ) new_path = new_path // sep
846
844
new_path = new_path // shared_lib_dirs(i)% s
847
845
end do
846
+
847
+ ! Get current library path
848
+ current = save_library_path()
848
849
849
850
! Set the appropriate environment variable
850
851
select case (get_os_type())
851
852
case (OS_WINDOWS)
852
- success = set_env(" PATH" , new_path // sep // get_env( " PATH " , default = " " ) )
853
+ success = set_env(" PATH" , new_path // sep // current )
853
854
case (OS_MACOS)
854
- ! Typically not required for local .dylib use, noop or DYLD_LIBRARY_PATH if needed
855
- success = .true.
855
+ success = set_env(" DYLD_LIBRARY_PATH" , new_path // sep // current)
856
856
case default ! UNIX/Linux
857
- success = set_env(" LD_LIBRARY_PATH" , new_path // sep // get_env( " LD_LIBRARY_PATH " , default = " " ) )
857
+ success = set_env(" LD_LIBRARY_PATH" , new_path // sep // current )
858
858
end select
859
859
860
- if (.not. success) call fatal_error(error," Cannot set library path: " // new_path)
860
+ if (.not. success) call fatal_error(error," Cannot set library path: " // new_path)
861
861
862
862
end subroutine set_library_path
863
863
864
+
864
865
! > Restore a previously saved runtime library path
865
- subroutine restore_library_path (saved_path ,error )
866
+ subroutine restore_library_path (saved_path , error )
866
867
character (* ), intent (in ) :: saved_path
867
868
type (error_t), allocatable , intent (out ) :: error
868
869
logical :: success
@@ -871,16 +872,16 @@ subroutine restore_library_path(saved_path,error)
871
872
case (OS_WINDOWS)
872
873
success = set_env(" PATH" , saved_path)
873
874
case (OS_MACOS)
874
- ! noop
875
- success = .true.
875
+ success = set_env(" DYLD_LIBRARY_PATH" , saved_path)
876
876
case default ! UNIX/Linux
877
877
success = set_env(" LD_LIBRARY_PATH" , saved_path)
878
878
end select
879
879
880
- if (.not. success) call fatal_error(error, " Cannot restore library path " // saved_path)
880
+ if (.not. success) call fatal_error(error, " Cannot restore library path: " // saved_path)
881
881
882
882
end subroutine restore_library_path
883
883
884
884
885
885
886
+
886
887
end module fpm
0 commit comments