From 8d49fda3521f20b8d0e6d0b01d416f06e5f1239c Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 10 Aug 2025 22:13:07 +0800 Subject: improve to install targets --- xmake/actions/install/xmake.lua | 6 +- xmake/modules/package/tools/xmake.lua | 2 +- xmake/modules/target/action/install/main.lua | 81 +++++++++++++++----------- xmake/modules/target/action/uninstall/main.lua | 3 - xmake/plugins/pack/batchcmds.lua | 3 - 5 files changed, 54 insertions(+), 41 deletions(-) diff --git a/xmake/actions/install/xmake.lua b/xmake/actions/install/xmake.lua index 3fa870061..a18b11214 100644 --- a/xmake/actions/install/xmake.lua +++ b/xmake/actions/install/xmake.lua @@ -37,7 +37,11 @@ task("install") " xmake install -g test_*", " xmake install --group=benchmark/*" }, {'a', "all", "k", nil , "Install all targets." }, - {nil, "nopkgs", "k", nil , "Only install targets without packages." }, + {nil, "binaries", "kv", true , "Enable or disable install binary files." }, + {nil, "headers", "kv", true , "Enable or disable install header files." }, + {nil, "libraries", "kv", true , "Enable or disable install library files." }, + {nil, "packages", "kv", true , "Enable or disable install package files." }, + {}, {nil, "admin", "k", nil , "Try to request administrator permission to install"}, {}, {nil, "target", "v", nil , "The target name. It will install all default targets if this parameter is not specified.", diff --git a/xmake/modules/package/tools/xmake.lua b/xmake/modules/package/tools/xmake.lua index 17cf48a2e..b572c2fec 100644 --- a/xmake/modules/package/tools/xmake.lua +++ b/xmake/modules/package/tools/xmake.lua @@ -543,7 +543,7 @@ function install(package, configs, opt) os.vrunv(os.programfile(), argv, {envs = envs, curdir = opt.curdir}) -- do install - argv = {"install", "-y", "--nopkgs", "-o", package:installdir()} + argv = {"install", "-y", "--packages=n", "-o", package:installdir()} _set_builtin_argv(package, argv) local targets = table.wrap(opt.targets or opt.target) if #targets ~= 0 then diff --git a/xmake/modules/target/action/install/main.lua b/xmake/modules/target/action/install/main.lua index d9faa80ad..3e8e1e62e 100644 --- a/xmake/modules/target/action/install/main.lua +++ b/xmake/modules/target/action/install/main.lua @@ -50,7 +50,7 @@ function _get_target_includedir(target, opt) end function _get_target_package_libfiles(target, opt) - if option.get("nopkgs") then + if not option.get("packages") then return {} end opt = opt or {} @@ -204,57 +204,72 @@ end -- install binary function _install_binary(target, opt) - local bindir = _get_target_bindir(target, opt) - os.mkdir(bindir) - os.vcp(target:targetfile(), bindir) - os.trycp(target:symbolfile(), path.join(bindir, path.filename(target:symbolfile()))) - _install_shared_libraries(target, opt) - _update_install_rpath(target, opt) + if option.get("libraries") then + _install_shared_libraries(target, opt) + end + if option.get("binaries") then + local bindir = _get_target_bindir(target, opt) + os.mkdir(bindir) + os.vcp(target:targetfile(), bindir) + os.trycp(target:symbolfile(), path.join(bindir, path.filename(target:symbolfile()))) + _update_install_rpath(target, opt) + end end -- install shared library function _install_shared(target, opt) - local bindir = target:is_plat("windows", "mingw") and _get_target_bindir(target, opt) or _get_target_libdir(target, opt) - os.mkdir(bindir) - local targetfile = target:targetfile() + if option.get("libraries") then + local bindir = target:is_plat("windows", "mingw") and _get_target_bindir(target, opt) or _get_target_libdir(target, opt) + os.mkdir(bindir) + local targetfile = target:targetfile() - if target:is_plat("windows", "mingw") then - -- install *.lib for shared/windows (*.dll) target - -- @see https://github.com/xmake-io/xmake/issues/714 - os.vcp(target:targetfile(), bindir) - local libdir = _get_target_libdir(target, opt) - local implibfile = target:artifactfile("implib") - if os.isfile(implibfile) then - os.mkdir(libdir) - os.vcp(implibfile, libdir) + if target:is_plat("windows", "mingw") then + -- install *.lib for shared/windows (*.dll) target + -- @see https://github.com/xmake-io/xmake/issues/714 + os.vcp(target:targetfile(), bindir) + local libdir = _get_target_libdir(target, opt) + local implibfile = target:artifactfile("implib") + if os.isfile(implibfile) then + os.mkdir(libdir) + os.vcp(implibfile, libdir) + end + else + -- install target with soname and symlink + _copy_file_with_symlinks(targetfile, bindir) end - else - -- install target with soname and symlink - _copy_file_with_symlinks(targetfile, bindir) + os.trycp(target:symbolfile(), path.join(bindir, path.filename(target:symbolfile()))) + _install_shared_libraries(target, opt) + end + if option.get("headers") then + _install_headers(target, opt) end - os.trycp(target:symbolfile(), path.join(bindir, path.filename(target:symbolfile()))) - - _install_headers(target, opt) - _install_shared_libraries(target, opt) end -- install static library function _install_static(target, opt) - local libdir = _get_target_libdir(target, opt) - os.mkdir(libdir) - os.vcp(target:targetfile(), libdir) - os.trycp(target:symbolfile(), path.join(libdir, path.filename(target:symbolfile()))) - _install_headers(target, opt) + if option.get("libraries") then + local libdir = _get_target_libdir(target, opt) + os.mkdir(libdir) + os.vcp(target:targetfile(), libdir) + os.trycp(target:symbolfile(), path.join(libdir, path.filename(target:symbolfile()))) + end + if option.get("headers") then + _install_headers(target, opt) + end end -- install headeronly library function _install_headeronly(target, opt) - _install_headers(target, opt) + if option.get("headers") then + _install_headers(target, opt) + end end -- install moduleonly library function _install_moduleonly(target, opt) - _install_headers(target, opt) + if option.get("headers") then + _install_headers(target, opt) + end end function main(target, opt) diff --git a/xmake/modules/target/action/uninstall/main.lua b/xmake/modules/target/action/uninstall/main.lua index 2273ff76d..26ea33530 100644 --- a/xmake/modules/target/action/uninstall/main.lua +++ b/xmake/modules/target/action/uninstall/main.lua @@ -50,9 +50,6 @@ function _get_target_includedir(target, opt) end function _get_target_package_libfiles(target, opt) - if option.get("nopkgs") then - return {} - end opt = opt or {} local libfiles = {} for _, pkg in ipairs(target:orderpkgs(opt)) do diff --git a/xmake/plugins/pack/batchcmds.lua b/xmake/plugins/pack/batchcmds.lua index 2418f39ac..b67d66b5b 100644 --- a/xmake/plugins/pack/batchcmds.lua +++ b/xmake/plugins/pack/batchcmds.lua @@ -63,9 +63,6 @@ function _get_target_installdir(package, target) end function _get_target_package_libfiles(target, opt) - if option.get("nopkgs") then - return {} - end opt = opt or {} local libfiles = {} for _, pkg in ipairs(target:orderpkgs(opt)) do -- cgit v1.3.1 From 2f471daf1e23171b0397a3bcca6fd393ce4e8c8d Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 11 Aug 2025 22:48:32 +0800 Subject: fix install --- xmake/actions/install/install.lua | 7 ++++++- xmake/modules/target/action/install/main.lua | 26 +++++++++++++++----------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/xmake/actions/install/install.lua b/xmake/actions/install/install.lua index 973b7496f..232f4f9c0 100644 --- a/xmake/actions/install/install.lua +++ b/xmake/actions/install/install.lua @@ -20,6 +20,7 @@ -- imports import("core.base.task") +import("core.base.option") import("core.project.rule") import("core.project.project") import("target.action.install", {alias = "_do_install_target"}) @@ -42,7 +43,11 @@ function _on_install_target(target) if done then return end -- do install - _do_install_target(target) + _do_install_target(target, { + headers = option.get("headers"), + binaries = option.get("binaries"), + libraries = option.get("libraries"), + packages = option.get("packages")}) end -- install the given target diff --git a/xmake/modules/target/action/install/main.lua b/xmake/modules/target/action/install/main.lua index 3e8e1e62e..ab4e46dcc 100644 --- a/xmake/modules/target/action/install/main.lua +++ b/xmake/modules/target/action/install/main.lua @@ -19,7 +19,6 @@ -- -- imports -import("core.base.option") import("core.base.hashset") import("core.project.project") import("utils.binary.deplibs", {alias = "get_depend_libraries"}) @@ -50,10 +49,10 @@ function _get_target_includedir(target, opt) end function _get_target_package_libfiles(target, opt) - if not option.get("packages") then + opt = opt or {} + if not opt.packages then return {} end - opt = opt or {} local libfiles = {} for _, pkg in ipairs(target:orderpkgs(opt)) do if pkg:enabled() and pkg:get("libfiles") then @@ -204,10 +203,10 @@ end -- install binary function _install_binary(target, opt) - if option.get("libraries") then + if opt.libraries then _install_shared_libraries(target, opt) end - if option.get("binaries") then + if opt.binaries then local bindir = _get_target_bindir(target, opt) os.mkdir(bindir) os.vcp(target:targetfile(), bindir) @@ -218,7 +217,7 @@ end -- install shared library function _install_shared(target, opt) - if option.get("libraries") then + if opt.libraries then local bindir = target:is_plat("windows", "mingw") and _get_target_bindir(target, opt) or _get_target_libdir(target, opt) os.mkdir(bindir) local targetfile = target:targetfile() @@ -240,40 +239,45 @@ function _install_shared(target, opt) os.trycp(target:symbolfile(), path.join(bindir, path.filename(target:symbolfile()))) _install_shared_libraries(target, opt) end - if option.get("headers") then + if opt.headers then _install_headers(target, opt) end end -- install static library function _install_static(target, opt) - if option.get("libraries") then + if opt.libraries then local libdir = _get_target_libdir(target, opt) os.mkdir(libdir) os.vcp(target:targetfile(), libdir) os.trycp(target:symbolfile(), path.join(libdir, path.filename(target:symbolfile()))) end - if option.get("headers") then + if opt.headers then _install_headers(target, opt) end end -- install headeronly library function _install_headeronly(target, opt) - if option.get("headers") then + if opt.headers then _install_headers(target, opt) end end -- install moduleonly library function _install_moduleonly(target, opt) - if option.get("headers") then + if opt.headers then _install_headers(target, opt) end end function main(target, opt) opt = opt or {} + opt.headers = opt.headers or true + opt.binaries = opt.binaries or true + opt.libraries = opt.libraries or true + opt.packages = opt.packages or true + local installdir = opt.installdir or target:installdir() if not installdir then wprint("please use `xmake install -o installdir` or `set_installdir` to set install directory.") -- cgit v1.3.1 From 87ab617a9baffa4e6d4d8a8a7560fa683c9a3995 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 11 Aug 2025 22:48:45 +0800 Subject: fix install opt --- xmake/modules/target/action/install/main.lua | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/xmake/modules/target/action/install/main.lua b/xmake/modules/target/action/install/main.lua index ab4e46dcc..ac731a3a8 100644 --- a/xmake/modules/target/action/install/main.lua +++ b/xmake/modules/target/action/install/main.lua @@ -273,10 +273,18 @@ end function main(target, opt) opt = opt or {} - opt.headers = opt.headers or true - opt.binaries = opt.binaries or true - opt.libraries = opt.libraries or true - opt.packages = opt.packages or true + if opt.headers == nil then + opt.headers = true + end + if opt.binaries == nil then + opt.binaries = true + end + if opt.libraries == nil then + opt.libraries = true + end + if opt.packages == nil then + opt.packages = true + end local installdir = opt.installdir or target:installdir() if not installdir then -- cgit v1.3.1 From 5d22e5c5919dddcf298af07d5bfe98f0dd8790a3 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 11 Aug 2025 23:11:24 +0800 Subject: fix install for macos --- xmake/modules/target/action/install/main.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/xmake/modules/target/action/install/main.lua b/xmake/modules/target/action/install/main.lua index ac731a3a8..e4f48ddfa 100644 --- a/xmake/modules/target/action/install/main.lua +++ b/xmake/modules/target/action/install/main.lua @@ -82,7 +82,7 @@ function _get_target_package_libfiles(target, opt) end -- get target libraries -function _get_target_libfiles(target, libfiles, binaryfile, refs) +function _get_target_libfiles(target, libfiles, binaryfile, refs, opt) if not refs[target] then local plaindeps = target:get("deps") if plaindeps then @@ -94,14 +94,14 @@ function _get_target_libfiles(target, libfiles, binaryfile, refs) if os.isfile(depfile) then table.insert(libfiles, depfile) end - _get_target_libfiles(dep, libfiles, dep:targetfile(), refs) + _get_target_libfiles(dep, libfiles, dep:targetfile(), refs, opt) elseif dep:is_library() then - _get_target_libfiles(dep, libfiles, binaryfile, refs) + _get_target_libfiles(dep, libfiles, binaryfile, refs, opt) end end end end - table.join2(libfiles, _get_target_package_libfiles(target, {binaryfile = binaryfile})) + table.join2(libfiles, _get_target_package_libfiles(target, table.join({binaryfile = binaryfile}, opt))) refs[target] = true end end @@ -162,7 +162,7 @@ function _install_shared_libraries(target, opt) -- get all dependent shared libraries local libfiles = {} - _get_target_libfiles(target, libfiles, target:targetfile(), {}) + _get_target_libfiles(target, libfiles, target:targetfile(), {}, opt) libfiles = table.unique(libfiles) -- do install -- cgit v1.3.1