summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-06-29 22:50:02 +0800
committerruki <[email protected]>2021-06-29 22:50:02 +0800
commitb115e1612528899fecb16f453ec559d17a54219b (patch)
treeccc56398172b1815fe4f18021bdc87c9fe57590f
parent3cc1a70d719794fe629552a52a00e0d8095efc17 (diff)
add linkjobs for tools/cmake
-rw-r--r--xmake/actions/build/xmake.lua3
-rw-r--r--xmake/actions/require/xmake.lua3
-rw-r--r--xmake/modules/package/tools/cmake.lua9
-rw-r--r--xmake/modules/private/xrepo/action/install.lua8
4 files changed, 19 insertions, 4 deletions
diff --git a/xmake/actions/build/xmake.lua b/xmake/actions/build/xmake.lua
index c92e7fb39..3323ac5b1 100644
--- a/xmake/actions/build/xmake.lua
+++ b/xmake/actions/build/xmake.lua
@@ -48,7 +48,8 @@ task("build")
, {}
, {'j', "jobs", "kv", tostring(math.ceil(os.cpuinfo().ncpu * 3 / 2)),
- "Specifies the number of jobs to build simultaneously." }
+ "Set the number of parallel compilation jobs." }
+ , {nil, "linkjobs", "kv", nil, "Set the number of parallel link jobs." }
, {'w', "warning", "k", false , "Enable the warnings output." }
, {nil, "files", "kv", nil , "Build the given source files.",
"e.g. ",
diff --git a/xmake/actions/require/xmake.lua b/xmake/actions/require/xmake.lua
index a534fb99c..a9d4db32c 100644
--- a/xmake/actions/require/xmake.lua
+++ b/xmake/actions/require/xmake.lua
@@ -47,7 +47,8 @@ task("require")
" $ xmake require --clean zlib tbox pcr*" }
, {'f', "force", "k", nil, "Force to reinstall all package dependencies." }
, {'j', "jobs", "kv", tostring(math.ceil(os.cpuinfo().ncpu * 3 / 2)),
- "Specifies the number of jobs to build simultaneously." }
+ "Set the number of parallel compilation jobs." }
+ , {nil, "linkjobs", "kv", nil, "Set the number of parallel link jobs." }
, {nil, "shallow", "k", nil, "Does not install dependent packages." }
, {nil, "build", "k", nil, "Always build and install packages from source." }
, {'l', "list", "k", nil, "List all package dependencies in project.",
diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua
index 097069bf2..680d29a9b 100644
--- a/xmake/modules/package/tools/cmake.lua
+++ b/xmake/modules/package/tools/cmake.lua
@@ -425,6 +425,15 @@ function _get_configs_for_generator(package, configs, opt)
end
table.insert(configs, "-G")
table.insert(configs, cmake_generator)
+ if cmake_generator:find("Ninja", 1, true) then
+ local jobs = opt.jobs or option.get("jobs") or tostring(math.ceil(os.cpuinfo().ncpu * 3 / 2))
+ local linkjobs = opt.linkjobs or option.get("linkjobs")
+ if linkjobs then
+ table.insert(configs, "-DCMAKE_JOB_POOL_COMPILE:STRING=compile")
+ table.insert(configs, "-DCMAKE_JOB_POOL_LINK:STRING=link")
+ table.insert(configs, ("-DCMAKE_JOB_POOLS:STRING=compile=%s;link=%s"):format(jobs, linkjobs))
+ end
+ end
elseif package:is_plat("mingw") and is_subhost("msys") then
table.insert(configs, "-G")
table.insert(configs, "MSYS Makefiles")
diff --git a/xmake/modules/private/xrepo/action/install.lua b/xmake/modules/private/xrepo/action/install.lua
index cfbd19b92..ccd14c839 100644
--- a/xmake/modules/private/xrepo/action/install.lua
+++ b/xmake/modules/private/xrepo/action/install.lua
@@ -40,8 +40,9 @@ function menu_options()
"e.g.",
" - xrepo install -f \"vs_runtime=MD\" zlib",
" - xrepo install -f \"regex=true,thread=true\" boost"},
- {'j', "jobs", "kv", tostring(math.ceil(os.cpuinfo().ncpu * 3 / 2)),
- "Specifies the number of jobs to build simultaneously."},
+ {'j', "jobs", "kv", tostring(math.ceil(os.cpuinfo().ncpu * 3 / 2)),
+ "Set the number of parallel compilation jobs."},
+ {nil, "linkjobs", "kv", nil, "Set the number of parallel link jobs."},
{nil, "includes", "kv", nil, "Includes extra lua configuration files.",
"e.g.",
" -- xrepo install -p cross --toolchain=mytool --includes='toolchain1.lua" .. path.envsep() .. "toolchain2.lua'"},
@@ -188,6 +189,9 @@ function _install_packages(packages)
table.insert(require_argv, "-j")
table.insert(require_argv, option.get("jobs"))
end
+ if option.get("linkjobs") then
+ table.insert(require_argv, "--linkjobs=" .. option.get("linkjobs"))
+ end
if option.get("force") then
table.insert(require_argv, "--force")
end