Skip to content

Commit c39e51c

Browse files
authored
Merge pull request #6688 from xmake-io/install
improve to install targets
2 parents a9732fa + 5d22e5c commit c39e51c

File tree

6 files changed

+79
-49
lines changed

6 files changed

+79
-49
lines changed

xmake/actions/install/install.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
-- imports
2222
import("core.base.task")
23+
import("core.base.option")
2324
import("core.project.rule")
2425
import("core.project.project")
2526
import("target.action.install", {alias = "_do_install_target"})
@@ -42,7 +43,11 @@ function _on_install_target(target)
4243
if done then return end
4344

4445
-- do install
45-
_do_install_target(target)
46+
_do_install_target(target, {
47+
headers = option.get("headers"),
48+
binaries = option.get("binaries"),
49+
libraries = option.get("libraries"),
50+
packages = option.get("packages")})
4651
end
4752

4853
-- install the given target

xmake/actions/install/xmake.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ task("install")
3737
" xmake install -g test_*",
3838
" xmake install --group=benchmark/*" },
3939
{'a', "all", "k", nil , "Install all targets." },
40-
{nil, "nopkgs", "k", nil , "Only install targets without packages." },
40+
{nil, "binaries", "kv", true , "Enable or disable install binary files." },
41+
{nil, "headers", "kv", true , "Enable or disable install header files." },
42+
{nil, "libraries", "kv", true , "Enable or disable install library files." },
43+
{nil, "packages", "kv", true , "Enable or disable install package files." },
44+
{},
4145
{nil, "admin", "k", nil , "Try to request administrator permission to install"},
4246
{},
4347
{nil, "target", "v", nil , "The target name. It will install all default targets if this parameter is not specified.",

xmake/modules/package/tools/xmake.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ function install(package, configs, opt)
543543
os.vrunv(os.programfile(), argv, {envs = envs, curdir = opt.curdir})
544544

545545
-- do install
546-
argv = {"install", "-y", "--nopkgs", "-o", package:installdir()}
546+
argv = {"install", "-y", "--packages=n", "-o", package:installdir()}
547547
_set_builtin_argv(package, argv)
548548
local targets = table.wrap(opt.targets or opt.target)
549549
if #targets ~= 0 then

xmake/modules/target/action/install/main.lua

Lines changed: 67 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
--
2020

2121
-- imports
22-
import("core.base.option")
2322
import("core.base.hashset")
2423
import("core.project.project")
2524
import("utils.binary.deplibs", {alias = "get_depend_libraries"})
@@ -50,10 +49,10 @@ function _get_target_includedir(target, opt)
5049
end
5150

5251
function _get_target_package_libfiles(target, opt)
53-
if option.get("nopkgs") then
52+
opt = opt or {}
53+
if not opt.packages then
5454
return {}
5555
end
56-
opt = opt or {}
5756
local libfiles = {}
5857
for _, pkg in ipairs(target:orderpkgs(opt)) do
5958
if pkg:enabled() and pkg:get("libfiles") then
@@ -83,7 +82,7 @@ function _get_target_package_libfiles(target, opt)
8382
end
8483

8584
-- get target libraries
86-
function _get_target_libfiles(target, libfiles, binaryfile, refs)
85+
function _get_target_libfiles(target, libfiles, binaryfile, refs, opt)
8786
if not refs[target] then
8887
local plaindeps = target:get("deps")
8988
if plaindeps then
@@ -95,14 +94,14 @@ function _get_target_libfiles(target, libfiles, binaryfile, refs)
9594
if os.isfile(depfile) then
9695
table.insert(libfiles, depfile)
9796
end
98-
_get_target_libfiles(dep, libfiles, dep:targetfile(), refs)
97+
_get_target_libfiles(dep, libfiles, dep:targetfile(), refs, opt)
9998
elseif dep:is_library() then
100-
_get_target_libfiles(dep, libfiles, binaryfile, refs)
99+
_get_target_libfiles(dep, libfiles, binaryfile, refs, opt)
101100
end
102101
end
103102
end
104103
end
105-
table.join2(libfiles, _get_target_package_libfiles(target, {binaryfile = binaryfile}))
104+
table.join2(libfiles, _get_target_package_libfiles(target, table.join({binaryfile = binaryfile}, opt)))
106105
refs[target] = true
107106
end
108107
end
@@ -163,7 +162,7 @@ function _install_shared_libraries(target, opt)
163162

164163
-- get all dependent shared libraries
165164
local libfiles = {}
166-
_get_target_libfiles(target, libfiles, target:targetfile(), {})
165+
_get_target_libfiles(target, libfiles, target:targetfile(), {}, opt)
167166
libfiles = table.unique(libfiles)
168167

169168
-- do install
@@ -204,61 +203,89 @@ end
204203

205204
-- install binary
206205
function _install_binary(target, opt)
207-
local bindir = _get_target_bindir(target, opt)
208-
os.mkdir(bindir)
209-
os.vcp(target:targetfile(), bindir)
210-
os.trycp(target:symbolfile(), path.join(bindir, path.filename(target:symbolfile())))
211-
_install_shared_libraries(target, opt)
212-
_update_install_rpath(target, opt)
206+
if opt.libraries then
207+
_install_shared_libraries(target, opt)
208+
end
209+
if opt.binaries then
210+
local bindir = _get_target_bindir(target, opt)
211+
os.mkdir(bindir)
212+
os.vcp(target:targetfile(), bindir)
213+
os.trycp(target:symbolfile(), path.join(bindir, path.filename(target:symbolfile())))
214+
_update_install_rpath(target, opt)
215+
end
213216
end
214217

215218
-- install shared library
216219
function _install_shared(target, opt)
217-
local bindir = target:is_plat("windows", "mingw") and _get_target_bindir(target, opt) or _get_target_libdir(target, opt)
218-
os.mkdir(bindir)
219-
local targetfile = target:targetfile()
220+
if opt.libraries then
221+
local bindir = target:is_plat("windows", "mingw") and _get_target_bindir(target, opt) or _get_target_libdir(target, opt)
222+
os.mkdir(bindir)
223+
local targetfile = target:targetfile()
220224

221-
if target:is_plat("windows", "mingw") then
222-
-- install *.lib for shared/windows (*.dll) target
223-
-- @see https://github.com/xmake-io/xmake/issues/714
224-
os.vcp(target:targetfile(), bindir)
225-
local libdir = _get_target_libdir(target, opt)
226-
local implibfile = target:artifactfile("implib")
227-
if os.isfile(implibfile) then
228-
os.mkdir(libdir)
229-
os.vcp(implibfile, libdir)
225+
if target:is_plat("windows", "mingw") then
226+
-- install *.lib for shared/windows (*.dll) target
227+
-- @see https://github.com/xmake-io/xmake/issues/714
228+
os.vcp(target:targetfile(), bindir)
229+
local libdir = _get_target_libdir(target, opt)
230+
local implibfile = target:artifactfile("implib")
231+
if os.isfile(implibfile) then
232+
os.mkdir(libdir)
233+
os.vcp(implibfile, libdir)
234+
end
235+
else
236+
-- install target with soname and symlink
237+
_copy_file_with_symlinks(targetfile, bindir)
230238
end
231-
else
232-
-- install target with soname and symlink
233-
_copy_file_with_symlinks(targetfile, bindir)
239+
os.trycp(target:symbolfile(), path.join(bindir, path.filename(target:symbolfile())))
240+
_install_shared_libraries(target, opt)
241+
end
242+
if opt.headers then
243+
_install_headers(target, opt)
234244
end
235-
os.trycp(target:symbolfile(), path.join(bindir, path.filename(target:symbolfile())))
236-
237-
_install_headers(target, opt)
238-
_install_shared_libraries(target, opt)
239245
end
240246

241247
-- install static library
242248
function _install_static(target, opt)
243-
local libdir = _get_target_libdir(target, opt)
244-
os.mkdir(libdir)
245-
os.vcp(target:targetfile(), libdir)
246-
os.trycp(target:symbolfile(), path.join(libdir, path.filename(target:symbolfile())))
247-
_install_headers(target, opt)
249+
if opt.libraries then
250+
local libdir = _get_target_libdir(target, opt)
251+
os.mkdir(libdir)
252+
os.vcp(target:targetfile(), libdir)
253+
os.trycp(target:symbolfile(), path.join(libdir, path.filename(target:symbolfile())))
254+
end
255+
if opt.headers then
256+
_install_headers(target, opt)
257+
end
248258
end
249259

250260
-- install headeronly library
251261
function _install_headeronly(target, opt)
252-
_install_headers(target, opt)
262+
if opt.headers then
263+
_install_headers(target, opt)
264+
end
253265
end
254266

255267
-- install moduleonly library
256268
function _install_moduleonly(target, opt)
257-
_install_headers(target, opt)
269+
if opt.headers then
270+
_install_headers(target, opt)
271+
end
258272
end
259273

260274
function main(target, opt)
261275
opt = opt or {}
276+
if opt.headers == nil then
277+
opt.headers = true
278+
end
279+
if opt.binaries == nil then
280+
opt.binaries = true
281+
end
282+
if opt.libraries == nil then
283+
opt.libraries = true
284+
end
285+
if opt.packages == nil then
286+
opt.packages = true
287+
end
288+
262289
local installdir = opt.installdir or target:installdir()
263290
if not installdir then
264291
wprint("please use `xmake install -o installdir` or `set_installdir` to set install directory.")

xmake/modules/target/action/uninstall/main.lua

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ function _get_target_includedir(target, opt)
5050
end
5151

5252
function _get_target_package_libfiles(target, opt)
53-
if option.get("nopkgs") then
54-
return {}
55-
end
5653
opt = opt or {}
5754
local libfiles = {}
5855
for _, pkg in ipairs(target:orderpkgs(opt)) do

xmake/plugins/pack/batchcmds.lua

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ function _get_target_installdir(package, target)
6363
end
6464

6565
function _get_target_package_libfiles(target, opt)
66-
if option.get("nopkgs") then
67-
return {}
68-
end
6966
opt = opt or {}
7067
local libfiles = {}
7168
for _, pkg in ipairs(target:orderpkgs(opt)) do

0 commit comments

Comments
 (0)