195
195
function _get_llvm_rootdir (self )
196
196
local llvm_rootdir = _g ._LLVM_ROOTDIR
197
197
if llvm_rootdir == nil then
198
- local outdata = try { function () return os .iorun (self :program () .. " -print-resource-dir" ) end }
198
+ local outdata = try { function () return os .iorunv (self :program (), { " -print-resource-dir" }, { envs = self : runenvs ()} ) end }
199
199
if outdata then
200
200
llvm_rootdir = path .normalize (path .join (outdata :trim (), " .." , " .." , " .." ))
201
201
if not os .isdir (llvm_rootdir ) then
@@ -207,6 +207,19 @@ function _get_llvm_rootdir(self)
207
207
return llvm_rootdir or nil
208
208
end
209
209
210
+ -- get llvm target triple
211
+ function _get_llvm_target_triple (self )
212
+ local llvm_targettriple = _g ._LLVM_TARGETTRIPLE
213
+ if llvm_targettriple == nil then
214
+ local outdata = try { function () return os .iorunv (self :program (), {" -print-target-triple" }, {envs = self :runenvs ()}) end }
215
+ if outdata then
216
+ llvm_targettriple = outdata :trim ()
217
+ end
218
+ _g ._LLVM_TARGETTRIPLE = llvm_targettriple or false
219
+ end
220
+ return llvm_targettriple or nil
221
+ end
222
+
210
223
-- make the runtime flag
211
224
-- @see https://github.com/xmake-io/xmake/issues/3546
212
225
function nf_runtime (self , runtime , opt )
@@ -267,8 +280,25 @@ function nf_runtime(self, runtime, opt)
267
280
llvm_rootdir = _get_llvm_rootdir (self )
268
281
end
269
282
if llvm_rootdir then
270
- maps [" c++_static" ] = table .join (maps [" c++_static" ], " -L" .. path .join (llvm_rootdir , " lib" ))
271
- maps [" c++_shared" ] = table .join (maps [" c++_shared" ], " -L" .. path .join (llvm_rootdir , " lib" ))
283
+ local libdir = path .absolute (path .join (llvm_rootdir , " lib" ))
284
+ maps [" c++_static" ] = table .join (maps [" c++_static" ], " -L" .. libdir )
285
+ maps [" c++_shared" ] = table .join (maps [" c++_shared" ], " -L" .. libdir )
286
+ -- sometimes llvm runtimes are located in a target-triple subfolder
287
+ local target_triple = _get_llvm_target_triple (self )
288
+ local triple_libdir = (target_triple and os .isdir (path .join (libdir , target_triple ))) and path .join (libdir , target_triple )
289
+ if triple_libdir then
290
+ maps [" c++_static" ] = table .join (maps [" c++_static" ], " -L" .. triple_libdir )
291
+ maps [" c++_shared" ] = table .join (maps [" c++_shared" ], " -L" .. triple_libdir )
292
+ end
293
+ -- add rpath to avoid the user need to set LD_LIBRARY_PATH by hand
294
+ maps [" c++_shared" ] = table .join (maps [" c++_shared" ], nf_rpathdir (self , libdir ))
295
+ if triple_libdir then
296
+ maps [" c++_shared" ] = table .join (maps [" c++_shared" ], nf_rpathdir (self , triple_libdir ))
297
+ end
298
+ if target :is_shared () and self :is_plat (" macosx" , " iphoneos" , " watchos" ) then
299
+ maps [" c++_shared" ] = table .join (maps [" c++_shared" ], " -install_name" )
300
+ maps [" c++_shared" ] = table .join (maps [" c++_shared" ], " @rpath/" .. target :filename ())
301
+ end
272
302
end
273
303
if runtime :endswith (" _static" ) and _has_static_libstdcxx (self ) then
274
304
maps [" c++_static" ] = table .join (maps [" c++_static" ], " -static-libstdc++" )
0 commit comments