diff options
| author | ruki <[email protected]> | 2024-07-17 22:55:38 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-07-17 22:55:38 +0800 |
| commit | e1590a09bb6fb17bc25b35d871e9eaec8f894050 (patch) | |
| tree | 802e14aeae436ebac53d2e595a2f70ef969f7c75 | |
| parent | 5f5164528ab628cbd688782b9057e898f9a27cfe (diff) | |
fix rpath
| -rw-r--r-- | tests/actions/install/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/target/action/install/main.lua | 16 | ||||
| -rw-r--r-- | xmake/modules/utils/binary/rpath.lua | 4 |
3 files changed, 15 insertions, 7 deletions
diff --git a/tests/actions/install/xmake.lua b/tests/actions/install/xmake.lua index 84f567239..814ce51a5 100644 --- a/tests/actions/install/xmake.lua +++ b/tests/actions/install/xmake.lua @@ -11,12 +11,12 @@ target("foo") add_headerfiles("src/foo.h", {public = true}) add_installfiles("src/foo.txt", {prefixdir = "assets", public = true}) set_prefixdir("/", {bindir = "foo_bin", libdir = "foo_lib"}) + add_rpathdirs("@loader_path/../../foo_lib", {installonly = true, public = true}) target("app") set_kind("binary") add_deps("foo") add_files("src/main.cpp") - add_rpathdirs("@loader_path/../lib", {installonly = true}) set_prefixdir("app") includes("@builtin/xpack") diff --git a/xmake/modules/target/action/install/main.lua b/xmake/modules/target/action/install/main.lua index 0b5ac126e..9e5e0c54c 100644 --- a/xmake/modules/target/action/install/main.lua +++ b/xmake/modules/target/action/install/main.lua @@ -29,12 +29,13 @@ function _get_target_package_libfiles(target, opt) return {} end local libfiles = {} + local bindir = target:is_plat("windows", "mingw") and target:bindir() or target:libdir() for _, pkg in ipairs(target:orderpkgs(opt)) do if pkg:enabled() and pkg:get("libfiles") then for _, libfile in ipairs(table.wrap(pkg:get("libfiles"))) do local filename = path.filename(libfile) if filename:endswith(".dll") or filename:endswith(".so") or filename:find("%.so%.%d+$") or filename:endswith(".dylib") then - table.insert(libfiles, libfile) + table.insert(libfiles, path.joinenv({libfile, bindir})) end end end @@ -47,7 +48,10 @@ function _get_target_package_libfiles(target, opt) for _, libfile in ipairs(depend_libraries) do depends:insert(path.filename(libfile)) end - table.remove_if(libfiles, function (_, libfile) return not depends:has(path.filename(libfile)) end) + table.remove_if(libfiles, function (_, libfile) + libfile = path.splitenv(libfile)[1] + return not depends:has(path.filename(libfile)) + end) end return libfiles end @@ -104,15 +108,15 @@ end -- install shared libraries function _install_shared_libraries(target, opt) - local bindir = target:is_plat("windows", "mingw") and target:bindir() or target:libdir() -- get all dependent shared libraries local libfiles = {} for _, dep in ipairs(target:orderdeps()) do + local bindir = dep:is_plat("windows", "mingw") and dep:bindir() or dep:libdir() if dep:kind() == "shared" then local depfile = dep:targetfile() if os.isfile(depfile) then - table.insert(libfiles, depfile) + table.insert(libfiles, path.joinenv({depfile, bindir})) end end table.join2(libfiles, _get_target_package_libfiles(dep, {interface = true})) @@ -124,6 +128,10 @@ function _install_shared_libraries(target, opt) -- do install for _, libfile in ipairs(libfiles) do + local splitinfo = path.splitenv(libfile) + libfile = splitinfo[1] + local bindir = splitinfo[2] + assert(libfile and bindir) local filename = path.filename(libfile) local filepath = path.join(bindir, filename) if os.isfile(filepath) and hash.sha256(filepath) ~= hash.sha256(libfile) then diff --git a/xmake/modules/utils/binary/rpath.lua b/xmake/modules/utils/binary/rpath.lua index cdf87d580..674a9edf0 100644 --- a/xmake/modules/utils/binary/rpath.lua +++ b/xmake/modules/utils/binary/rpath.lua @@ -26,10 +26,10 @@ function _replace_rpath_vars(rpath, opt) local plat = opt.plat or os.host() local arch = opt.arch or os.arch() if plat == "macosx" or plat == "iphoneos" or plat == "appletvos" or plat == "watchos" then + rpath = rpath:gsub("%$ORIGIN", "@loader_path") + else rpath = rpath:gsub("@loader_path", "$ORIGIN") rpath = rpath:gsub("@executable_path", "$ORIGIN") - else - rpath = rpath:gsub("%$ORIGIN", "@loader_path") end return rpath end |
