Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple targets for package #5537

Merged
merged 5 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 28 additions & 32 deletions xmake/modules/package/tools/cmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
star-hengxing marked this conversation as resolved.
Show resolved Hide resolved
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
star-hengxing marked this conversation as resolved.
Show resolved Hide resolved
table.insert(argv, "VERBOSE=1")
end
if is_host("bsd") then
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这块挪外面,不要放 configure 里


-- 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
Expand Down
40 changes: 18 additions & 22 deletions xmake/modules/package/tools/ninja.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,48 +22,44 @@
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
star-hengxing marked this conversation as resolved.
Show resolved Hide resolved
table.insert(argv, "-v")
end
table.insert(argv, "-j")
table.insert(argv, njob)
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
10 changes: 6 additions & 4 deletions xmake/modules/package/tools/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
star-hengxing marked this conversation as resolved.
Show resolved Hide resolved
if #target ~= 0 then
table.join2(argv, target)
end
os.vrunv(os.programfile(), argv, {envs = envs})
end
Loading