summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstar9029 <[email protected]>2024-08-29 16:50:29 +0800
committerstar9029 <[email protected]>2024-08-29 16:50:29 +0800
commit94829508d57ac49bcd0cecc3a6de6f5afcdf921c (patch)
treee8805e499a0b4117627324c7d319f5454b49bd71
parent87630c8cf33105cc8c000e73cb7b67a2decfe02d (diff)
Support multiple targets for package
-rw-r--r--xmake/modules/package/tools/cmake.lua60
-rw-r--r--xmake/modules/package/tools/ninja.lua40
-rw-r--r--xmake/modules/package/tools/xmake.lua10
3 files changed, 52 insertions, 58 deletions
diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua
index 99dfe0436..c9cfc8c2a 100644
--- a/xmake/modules/package/tools/cmake.lua
+++ b/xmake/modules/package/tools/cmake.lua
@@ -1002,12 +1002,13 @@ end
-- do build for make
function _build_for_make(package, configs, opt)
local argv = {}
- if opt.target then
- table.insert(argv, opt.target)
+ local target = table.wrap(opt.target)
+ if #target ~= 0 then
+ table.join2(argv, target)
end
local jobs = _get_parallel_njobs(opt)
table.insert(argv, "-j" .. jobs)
- if option.get("diagnosis") then
+ if option.get("verbose") then
table.insert(argv, "VERBOSE=1")
end
if is_host("bsd") then
@@ -1047,9 +1048,19 @@ function _build_for_cmakebuild(package, configs, opt)
table.insert(argv, "--config")
table.insert(argv, opt.config)
end
- if opt.target then
+ local target = table.wrap(opt.target)
+ if #target ~= 0 then
table.insert(argv, "--target")
- table.insert(argv, opt.target)
+ if #target > 1 then
+ -- https://stackoverflow.com/questions/47553569/how-can-i-build-multiple-targets-using-cmake-build
+ if _get_cmake_version():ge("3.15") then
+ table.join2(argv, target)
+ else
+ raise("Build multiple targets need cmake >=3.15")
+ end
+ else
+ table.insert(argv, target[1])
+ end
end
os.vrunv(cmake.program, argv, {envs = opt.envs or buildenvs(package)})
end
@@ -1082,7 +1093,7 @@ end
function _install_for_make(package, configs, opt)
local jobs = _get_parallel_njobs(opt)
local argv = {"-j" .. jobs}
- if option.get("diagnosis") then
+ if option.get("verbose") then
table.insert(argv, "VERBOSE=1")
end
if is_host("bsd") then
@@ -1160,10 +1171,8 @@ function _get_cmake_generator(package, opt)
return cmake_generator
end
--- build package
-function build(package, configs, opt)
+function configure(package, configs, opt)
opt = opt or {}
- local cmake_generator = _get_cmake_generator(package, opt)
-- enter build directory
local buildir = opt.buildir or package:buildir()
@@ -1188,6 +1197,15 @@ function build(package, configs, opt)
local cmake = assert(find_tool("cmake"), "cmake not found!")
os.vrunv(cmake.program, argv, {envs = opt.envs or buildenvs(package, opt)})
+ return oldir
+end
+
+-- build package
+function build(package, configs, opt)
+ opt = opt or {}
+ local cmake_generator = _get_cmake_generator(package, opt)
+ local oldir = configure(package, configs, opt)
+
-- do build
if opt.cmake_build then
_build_for_cmakebuild(package, configs, opt)
@@ -1215,29 +1233,7 @@ end
function install(package, configs, opt)
opt = opt or {}
local cmake_generator = _get_cmake_generator(package, opt)
-
- -- enter build directory
- local buildir = opt.buildir or package:buildir()
- os.mkdir(path.join(buildir, "install"))
- local oldir = os.cd(buildir)
-
- -- pass configurations
- local argv = {}
- for name, value in pairs(_get_configs(package, configs, opt)) do
- value = tostring(value):trim()
- if type(name) == "number" then
- if value ~= "" then
- table.insert(argv, value)
- end
- else
- table.insert(argv, "-D" .. name .. "=" .. value)
- end
- end
- table.insert(argv, oldir)
-
- -- generate build file
- local cmake = assert(find_tool("cmake"), "cmake not found!")
- os.vrunv(cmake.program, argv, {envs = opt.envs or buildenvs(package, opt)})
+ local oldir = configure(package, configs, opt)
-- do build and install
if opt.cmake_build then
diff --git a/xmake/modules/package/tools/ninja.lua b/xmake/modules/package/tools/ninja.lua
index 42dc73ed6..f900a8d1f 100644
--- a/xmake/modules/package/tools/ninja.lua
+++ b/xmake/modules/package/tools/ninja.lua
@@ -22,19 +22,19 @@
import("core.base.option")
import("lib.detect.find_tool")
--- build package
-function build(package, configs, opt)
+function _default_argv(package, configs, opt)
opt = opt or {}
local buildir = opt.buildir or os.curdir()
local njob = opt.jobs or option.get("jobs") or tostring(os.default_njob())
- local ninja = assert(find_tool("ninja"), "ninja not found!")
+
local argv = {}
- if opt.target then
- table.insert(argv, opt.target)
+ local target = table.wrap(opt.target)
+ if #target ~= 0 then
+ table.join2(argv, target)
end
table.insert(argv, "-C")
table.insert(argv, buildir)
- if option.get("diagnosis") then
+ if option.get("verbose") then
table.insert(argv, "-v")
end
table.insert(argv, "-j")
@@ -42,28 +42,24 @@ function build(package, configs, opt)
if configs then
table.join2(argv, configs)
end
+
+ return argv
+end
+
+-- build package
+function build(package, configs, opt)
+ opt = opt or {}
+ local argv = {}
+ local ninja = assert(find_tool("ninja"), "ninja not found!")
+ table.join2(argv, _default_argv(package, configs, opt))
os.vrunv(ninja.program, argv, {envs = opt.envs})
end
-- install package
function install(package, configs, opt)
opt = opt or {}
- local buildir = opt.buildir or os.curdir()
- local njob = opt.jobs or option.get("jobs") or tostring(os.default_njob())
- local ninja = assert(find_tool("ninja"), "ninja not found!")
local argv = {"install"}
- if opt.target then
- table.insert(argv, opt.target)
- end
- table.insert(argv, "-C")
- table.insert(argv, buildir)
- if option.get("verbose") then
- table.insert(argv, "-v")
- end
- table.insert(argv, "-j")
- table.insert(argv, njob)
- if configs then
- table.join2(argv, configs)
- end
+ local ninja = assert(find_tool("ninja"), "ninja not found!")
+ table.join2(argv, _default_argv(package, configs, opt))
os.vrunv(ninja.program, argv, {envs = opt.envs})
end
diff --git a/xmake/modules/package/tools/xmake.lua b/xmake/modules/package/tools/xmake.lua
index dbe417a80..b9cf605ce 100644
--- a/xmake/modules/package/tools/xmake.lua
+++ b/xmake/modules/package/tools/xmake.lua
@@ -517,16 +517,18 @@ function install(package, configs, opt)
if njob then
table.insert(argv, "--jobs=" .. njob)
end
- if opt.target then
- table.insert(argv, opt.target)
+ local target = table.wrap(opt.target)
+ if #target ~= 0 then
+ table.join2(argv, target)
end
os.vrunv(os.programfile(), argv, {envs = envs})
-- do install
argv = {"install", "-y", "--nopkgs", "-o", package:installdir()}
_set_builtin_argv(package, argv)
- if opt.target then
- table.insert(argv, opt.target)
+ local target = table.wrap(opt.target)
+ if #target ~= 0 then
+ table.join2(argv, target)
end
os.vrunv(os.programfile(), argv, {envs = envs})
end