Skip to content

Commit ea6b7e6

Browse files
committed
[macOS] add room in the binary header for the @rpath entries
1 parent 1ea9c82 commit ea6b7e6

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/fpm_compiler.F90

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ module fpm_compiler
107107
procedure :: get_export_flags
108108
!> Get library install name flags
109109
procedure :: get_install_name_flags
110+
!> Generate header padding flags for macOS executables
111+
procedure :: get_headerpad_flags
110112
!> Compile a Fortran object
111113
procedure :: compile_fortran
112114
!> Compile a C object
@@ -1144,6 +1146,23 @@ function get_install_name_flags(self, target_dir, target_name) result(flags)
11441146

11451147
end function get_install_name_flags
11461148

1149+
!>
1150+
!> Generate header padding flags for install_name_tool compatibility on macOS
1151+
!>
1152+
function get_headerpad_flags(self) result(flags)
1153+
class(compiler_t), intent(in) :: self
1154+
character(len=:), allocatable :: flags
1155+
1156+
if (get_os_type() /= OS_MACOS) then
1157+
flags = ""
1158+
return
1159+
end if
1160+
1161+
! Reserve enough space in the Mach-O header to safely add two install_name or rpath later
1162+
flags = " -Wl,-headerpad,0x200"
1163+
1164+
end function get_headerpad_flags
1165+
11471166
!> Create new compiler instance
11481167
subroutine new_compiler(self, fc, cc, cxx, echo, verbose)
11491168
!> New instance of the compiler

src/fpm_targets.f90

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1181,7 +1181,12 @@ subroutine resolve_target_linking(targets, model, library, error)
11811181
target%link_flags = model%get_package_libraries_link(target%package_name, &
11821182
target%link_flags, &
11831183
error=error, &
1184-
exclude_self=.not.has_self_lib)
1184+
exclude_self=.not.has_self_lib)
1185+
1186+
1187+
! On macOS, add room for 2 install_name_tool paths
1188+
target%link_flags = target%link_flags // model%compiler%get_headerpad_flags()
1189+
11851190
end if
11861191

11871192
if (allocated(target%link_libraries)) then

0 commit comments

Comments
 (0)