@@ -105,6 +105,8 @@ module fpm_compiler
105
105
procedure :: get_main_flags
106
106
! > Get library export flags
107
107
procedure :: get_export_flags
108
+ ! > Get library install name flags
109
+ procedure :: get_install_name_flags
108
110
! > Compile a Fortran object
109
111
procedure :: compile_fortran
110
112
! > Compile a C object
@@ -1117,6 +1119,28 @@ function get_export_flags(self, target_dir, target_name) result(export_flags)
1117
1119
1118
1120
end function get_export_flags
1119
1121
1122
+ ! >
1123
+ ! > Generate `install_name` flag for a shared library build on macOS
1124
+ ! >
1125
+ function get_install_name_flags (self , target_dir , target_name ) result(flags)
1126
+ class(compiler_t), intent (in ) :: self
1127
+ character (len=* ), intent (in ) :: target_dir, target_name
1128
+ character (len= :), allocatable :: flags
1129
+
1130
+ if (get_os_type() /= OS_MACOS) then
1131
+ flags = " "
1132
+ return
1133
+ end if
1134
+
1135
+ ! Shared library basename (e.g., libfoo.dylib)
1136
+ if (str_ends_with(target_name, " .dylib" )) then
1137
+ flags = " -Wl,-install_name,@rpath/" // target_name
1138
+ else
1139
+ flags = " -Wl,-install_name,@rpath/" // target_name // " .dylib"
1140
+ end if
1141
+
1142
+ end function get_install_name_flags
1143
+
1120
1144
! > Create new compiler instance
1121
1145
subroutine new_compiler (self , fc , cc , cxx , echo , verbose )
1122
1146
! > New instance of the compiler
0 commit comments