summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-02-20 00:32:16 +0800
committerruki <[email protected]>2020-02-19 21:13:37 +0800
commitcddd02bfe9ab6d77026134303baf41056862021a (patch)
treea179c290b28ab2b2576bff59c407c52a9f9c471c
parentd7507f0e845f4066975fce6e357a55d4cbb938d4 (diff)
add --tryconfigs= for trybuild
-rw-r--r--xmake/actions/config/xmake.lua8
-rw-r--r--xmake/modules/private/action/trybuild/autotools.lua22
-rw-r--r--xmake/modules/private/action/trybuild/cmake.lua32
-rw-r--r--xmake/modules/private/action/trybuild/meson.lua30
4 files changed, 64 insertions, 28 deletions
diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua
index 571daca36..04f8ad996 100644
--- a/xmake/actions/config/xmake.lua
+++ b/xmake/actions/config/xmake.lua
@@ -51,12 +51,14 @@ task("config")
return {"y: force to enable", "n: disable" }
end
end }
- , {nil, "trybuild", "kv", nil , "Try building and set the third-party buildsystem tool.",
+ , {nil, "trybuild", "kv", nil , "Enable try-build mode and set the third-party buildsystem tool.",
"e.g.",
" - xmake f --trybuild=auto; xmake",
" - xmake f --trybuild=autotools -p android --ndk=xxx; xmake"
- , values = {"auto", "make", "cmake", "autotools", "msbuild", "xcodebuild"}}
-
+ , values = {"auto", "make", "cmake", "meson", "autotools", "msbuild", "xcodebuild"}}
+ , {nil, "tryconfigs", "kv", nil , "Set the extra configurations of the third-party buildsystem for the try-build mode.",
+ "e.g.",
+ " - xmake f --trybuild=autotools --tryconfigs='--enable-shared=no'"}
, {category = "."}
, {'p', "plat", "kv", "$(subhost)" , "Compile for the given platform."
, values = function (complete, opt)
diff --git a/xmake/modules/private/action/trybuild/autotools.lua b/xmake/modules/private/action/trybuild/autotools.lua
index f22573053..89b41bc2f 100644
--- a/xmake/modules/private/action/trybuild/autotools.lua
+++ b/xmake/modules/private/action/trybuild/autotools.lua
@@ -19,6 +19,7 @@
--
-- imports
+import("core.base.cli")
import("core.base.option")
import("core.project.config")
import("core.platform.platform")
@@ -103,6 +104,14 @@ function _get_configs(artifacts_dir)
local configs = {}
table.insert(configs, "--prefix=" .. artifacts_dir)
+ -- add extra user configs
+ local tryconfigs = config.get("tryconfigs")
+ if tryconfigs then
+ for _, opt in ipairs(cli.parse(tryconfigs)) do
+ table.insert(configs, tostring(opt))
+ end
+ end
+
-- add host for cross-complation
if not is_plat(os.subhost()) then
if is_plat("iphoneos") then
@@ -181,18 +190,7 @@ function build()
-- do configure
local configfile = find_file("[mM]akefile", os.curdir())
if not configfile or os.mtime(config.filepath()) > os.mtime(configfile) then
- local argv = {}
- for name, value in pairs(_get_configs(artifacts_dir)) do
- value = tostring(value):trim()
- if value ~= "" then
- if type(name) == "number" then
- table.insert(argv, value)
- else
- table.insert(argv, "--" .. name .. "=" .. value)
- end
- end
- end
- os.vexecv("./configure", argv, {envs = _get_buildenvs()})
+ os.vexecv("./configure", _get_configs(artifacts_dir), {envs = _get_buildenvs()})
end
-- do build
diff --git a/xmake/modules/private/action/trybuild/cmake.lua b/xmake/modules/private/action/trybuild/cmake.lua
index 565f00fa7..94cfc9e3e 100644
--- a/xmake/modules/private/action/trybuild/cmake.lua
+++ b/xmake/modules/private/action/trybuild/cmake.lua
@@ -19,6 +19,7 @@
--
-- imports
+import("core.base.cli")
import("core.base.option")
import("core.project.config")
import("lib.detect.find_file")
@@ -34,6 +35,29 @@ function _get_artifacts_dir()
return path.absolute(path.join(_get_buildir(), "artifacts"))
end
+-- get configs
+function _get_configs(artifacts_dir)
+
+ -- add prefix
+ local configs = {"-DCMAKE_INSTALL_PREFIX=" .. artifacts_dir, "-DDCMAKE_INSTALL_LIBDIR=" .. path.join(artifacts_dir, "lib")}
+ if is_plat("windows") and is_arch("x64") then
+ table.insert(configs, "-A")
+ table.insert(configs, "x64")
+ end
+
+ -- add extra user configs
+ local tryconfigs = config.get("tryconfigs")
+ if tryconfigs then
+ for _, opt in ipairs(cli.parse(tryconfigs)) do
+ table.insert(configs, tostring(opt))
+ end
+ end
+
+ -- add build directory
+ table.insert(configs, '..')
+ return configs
+end
+
-- detect build-system and configuration file
function detect()
return find_file("CMakeLists.txt", os.curdir())
@@ -70,13 +94,7 @@ function build()
local cmake = assert(find_tool("cmake"), "cmake not found!")
local configfile = find_file("[mM]akefile", os.curdir()) or (is_plat("windows") and find_file("*.sln", os.curdir()))
if not configfile or os.mtime(config.filepath()) > os.mtime(configfile) then
- local argv = {"-DCMAKE_INSTALL_PREFIX=" .. artifacts_dir, "-DDCMAKE_INSTALL_LIBDIR=" .. path.join(artifacts_dir, "lib")}
- if is_plat("windows") and is_arch("x64") then
- table.insert(argv, "-A")
- table.insert(argv, "x64")
- end
- table.insert(argv, '..')
- os.vexecv(cmake.program, argv)
+ os.vexecv(cmake.program, _get_configs(artifacts_dir))
end
-- do build
diff --git a/xmake/modules/private/action/trybuild/meson.lua b/xmake/modules/private/action/trybuild/meson.lua
index a728e6063..80d1185bd 100644
--- a/xmake/modules/private/action/trybuild/meson.lua
+++ b/xmake/modules/private/action/trybuild/meson.lua
@@ -19,6 +19,7 @@
--
-- imports
+import("core.base.cli")
import("core.base.option")
import("core.project.config")
import("lib.detect.find_file")
@@ -34,6 +35,28 @@ function _get_artifacts_dir()
return path.absolute(path.join(_get_buildir(), "artifacts"))
end
+-- get configs
+function _get_configs(artifacts_dir, buildir)
+
+ -- add prefix
+ local configs = {"--prefix=" .. artifacts_dir}
+ if configfile then
+ table.insert(configs, "--reconfigure")
+ end
+
+ -- add extra user configs
+ local tryconfigs = config.get("tryconfigs")
+ if tryconfigs then
+ for _, opt in ipairs(cli.parse(tryconfigs)) do
+ table.insert(configs, tostring(opt))
+ end
+ end
+
+ -- add build directory
+ table.insert(configs, buildir)
+ return configs
+end
+
-- detect build-system and configuration file
function detect()
return find_file("meson.build", os.curdir())
@@ -74,12 +97,7 @@ function build()
local meson = assert(find_tool("meson"), "meson not found!")
local configfile = find_file("build.ninja", buildir)
if not configfile or os.mtime(config.filepath()) > os.mtime(configfile) then
- local argv = {"--prefix=" .. artifacts_dir}
- if configfile then
- table.insert(argv, "--reconfigure")
- end
- table.insert(argv, buildir)
- os.vexecv(meson.program, argv)
+ os.vexecv(meson.program, _get_configs(artifacts_dir, buildir))
end
-- do build