summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-02-03 11:20:02 +0800
committerruki <[email protected]>2019-02-03 11:20:02 +0800
commite35595f73271cb14363c027694183dec3a32e910 (patch)
tree32b6efd9c4ec17781eab6a8e746e79e97bddd21c
parente7c2f6900a1aee4c065422ab5a252897f4c90b64 (diff)
attach option and configvars
-rw-r--r--tests/apis/add_configfiles/config.h.in4
-rw-r--r--tests/apis/add_configfiles/config2.h.in8
-rw-r--r--tests/apis/add_configfiles/xmake.lua9
-rw-r--r--xmake/actions/config/configfiles.lua20
-rw-r--r--xmake/core/project/option.lua5
5 files changed, 46 insertions, 0 deletions
diff --git a/tests/apis/add_configfiles/config.h.in b/tests/apis/add_configfiles/config.h.in
index e84840f70..3cbeb4135 100644
--- a/tests/apis/add_configfiles/config.h.in
+++ b/tests/apis/add_configfiles/config.h.in
@@ -4,3 +4,7 @@
${define FOO_ENABLE}
${define FOO_ENABLE2}
${define FOO_STRING}
+
+${define FOO2_ENABLE}
+${define FOO2_ENABLE2}
+${define FOO2_STRING}
diff --git a/tests/apis/add_configfiles/config2.h.in b/tests/apis/add_configfiles/config2.h.in
index 3e6f71384..eec2d90ac 100644
--- a/tests/apis/add_configfiles/config2.h.in
+++ b/tests/apis/add_configfiles/config2.h.in
@@ -1,2 +1,10 @@
#define HAVE_@module@_H
#define HELLO2 "@hello@ @ARCH@ @PLAT@"
+
+@define FOO_ENABLE@
+@define FOO_ENABLE2@
+@define FOO_STRING@
+
+@define FOO2_ENABLE@
+@define FOO2_ENABLE2@
+@define FOO2_STRING@
diff --git a/tests/apis/add_configfiles/xmake.lua b/tests/apis/add_configfiles/xmake.lua
index 2a5c091ec..6c4fcc588 100644
--- a/tests/apis/add_configfiles/xmake.lua
+++ b/tests/apis/add_configfiles/xmake.lua
@@ -13,6 +13,13 @@ if has_config("foo") then
set_configvar("FOO_STRING", get_config("foo"))
end
+option("foo2")
+ set_default(true)
+ set_description("Enable Foo2")
+ set_configvar("FOO2_ENABLE", true)
+ set_configvar("FOO2_STRING", "foo")
+option_end()
+
target("test")
set_kind("binary")
add_files("main.c")
@@ -35,3 +42,5 @@ target("test2")
add_configfiles("config2.h.in", {variables = {hello = "xmake2"}, pattern = "@(.-)@", prefixdir = "header"})
add_configfiles("*.man", {onlycopy = true, prefixdir = "man"})
add_includedirs("$(buildir)/config2/header")
+
+ add_options("foo2")
diff --git a/xmake/actions/config/configfiles.lua b/xmake/actions/config/configfiles.lua
index 94f3c1bd5..2020670e3 100644
--- a/xmake/actions/config/configfiles.lua
+++ b/xmake/actions/config/configfiles.lua
@@ -89,11 +89,31 @@ function _generate_configfile(srcfile, dstfile, fileinfo, targets)
-- get all variables
local variables = fileinfo.variables or {}
for _, target in ipairs(targets) do
+
+ -- get variables from the target
for name, value in pairs(target:get("configvar")) do
if variables[name] == nil then
variables[name] = table.unwrap(value)
end
end
+
+ -- get variables from the target.options
+ for _, opt in ipairs(target:orderopts()) do
+ for name, value in pairs(opt:get("configvar")) do
+ if variables[name] == nil then
+ variables[name] = table.unwrap(value)
+ end
+ end
+ end
+
+ -- get variables from the target.packages
+ for _, pkg in ipairs(target:orderpkgs()) do
+ for name, value in pairs(pkg:get("configvar")) do
+ if variables[name] == nil then
+ variables[name] = table.unwrap(value)
+ end
+ end
+ end
end
-- replace all variables
diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua
index 637327389..c6592796c 100644
--- a/xmake/core/project/option.lua
+++ b/xmake/core/project/option.lua
@@ -78,6 +78,11 @@ function option.apis()
, "option.add_vectorexts"
, "option.add_features"
}
+ , keyvalues =
+ {
+ -- option.set_xxx
+ "option.set_configvar"
+ }
, script =
{
-- option.before_xxx