19
19
--
20
20
21
21
-- imports
22
- import (" core.base.option" )
23
22
import (" core.base.hashset" )
24
23
import (" core.project.project" )
25
24
import (" utils.binary.deplibs" , {alias = " get_depend_libraries" })
@@ -50,10 +49,10 @@ function _get_target_includedir(target, opt)
50
49
end
51
50
52
51
function _get_target_package_libfiles (target , opt )
53
- if option .get (" nopkgs" ) then
52
+ opt = opt or {}
53
+ if not opt .packages then
54
54
return {}
55
55
end
56
- opt = opt or {}
57
56
local libfiles = {}
58
57
for _ , pkg in ipairs (target :orderpkgs (opt )) do
59
58
if pkg :enabled () and pkg :get (" libfiles" ) then
@@ -83,7 +82,7 @@ function _get_target_package_libfiles(target, opt)
83
82
end
84
83
85
84
-- get target libraries
86
- function _get_target_libfiles (target , libfiles , binaryfile , refs )
85
+ function _get_target_libfiles (target , libfiles , binaryfile , refs , opt )
87
86
if not refs [target ] then
88
87
local plaindeps = target :get (" deps" )
89
88
if plaindeps then
@@ -95,14 +94,14 @@ function _get_target_libfiles(target, libfiles, binaryfile, refs)
95
94
if os .isfile (depfile ) then
96
95
table.insert (libfiles , depfile )
97
96
end
98
- _get_target_libfiles (dep , libfiles , dep :targetfile (), refs )
97
+ _get_target_libfiles (dep , libfiles , dep :targetfile (), refs , opt )
99
98
elseif dep :is_library () then
100
- _get_target_libfiles (dep , libfiles , binaryfile , refs )
99
+ _get_target_libfiles (dep , libfiles , binaryfile , refs , opt )
101
100
end
102
101
end
103
102
end
104
103
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 ) ))
106
105
refs [target ] = true
107
106
end
108
107
end
@@ -163,7 +162,7 @@ function _install_shared_libraries(target, opt)
163
162
164
163
-- get all dependent shared libraries
165
164
local libfiles = {}
166
- _get_target_libfiles (target , libfiles , target :targetfile (), {})
165
+ _get_target_libfiles (target , libfiles , target :targetfile (), {}, opt )
167
166
libfiles = table .unique (libfiles )
168
167
169
168
-- do install
@@ -204,61 +203,89 @@ end
204
203
205
204
-- install binary
206
205
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
213
216
end
214
217
215
218
-- install shared library
216
219
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 ()
220
224
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 )
230
238
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 )
234
244
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 )
239
245
end
240
246
241
247
-- install static library
242
248
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
248
258
end
249
259
250
260
-- install headeronly library
251
261
function _install_headeronly (target , opt )
252
- _install_headers (target , opt )
262
+ if opt .headers then
263
+ _install_headers (target , opt )
264
+ end
253
265
end
254
266
255
267
-- install moduleonly library
256
268
function _install_moduleonly (target , opt )
257
- _install_headers (target , opt )
269
+ if opt .headers then
270
+ _install_headers (target , opt )
271
+ end
258
272
end
259
273
260
274
function main (target , opt )
261
275
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
+
262
289
local installdir = opt .installdir or target :installdir ()
263
290
if not installdir then
264
291
wprint (" please use `xmake install -o installdir` or `set_installdir` to set install directory." )
0 commit comments