summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2015-06-10 15:35:31 +0800
committerruki <[email protected]>2015-06-10 15:35:31 +0800
commit72faab4c7e6468d94364e2fec7c11614845d0c74 (patch)
tree2ba6d0eb659f14646a117aa19b808e1b44635afc
parent33ad09c9a126cb83ba45fb6f1f2c2898cfbb2dbb (diff)
add option switch for xmake.lua
-rw-r--r--tests/console/src/demo/xmake.lua5
-rw-r--r--xmake/scripts/base/project.lua41
2 files changed, 41 insertions, 5 deletions
diff --git a/tests/console/src/demo/xmake.lua b/tests/console/src/demo/xmake.lua
index cafc9b2a0..7415b2564 100644
--- a/tests/console/src/demo/xmake.lua
+++ b/tests/console/src/demo/xmake.lua
@@ -9,6 +9,10 @@ add_target("demo_c")
add_cflags("-DHELLO1")
if modes("release") then add_defines("NDEBUG") end
+ if option("option1") then add_defines("OPTION1") end
+ if option("option2") then add_defines("OPTION2") end
+ if option("option3") then add_defines("OPTION3") end
+ if option("option4") then add_defines("OPTION4") end
add_target("demo_cpp")
set_kind("binary")
@@ -19,6 +23,7 @@ add_target("demo_cpp")
add_includedirs("$(buildir)")
add_undefines("HELLO2")
add_cxxflags("-DHELLO1")
+ add_options("option1", "option2", "option3", "option4")
if plats("macosx", "ios") then
diff --git a/xmake/scripts/base/project.lua b/xmake/scripts/base/project.lua
index a42028e29..6b1b7406b 100644
--- a/xmake/scripts/base/project.lua
+++ b/xmake/scripts/base/project.lua
@@ -74,6 +74,13 @@ function project._api_archs(env, ...)
end
end
+-- enable option?
+function project._api_option(env, opt)
+
+ -- enable?
+ return config.get(opt)
+end
+
-- add target
function project._api_add_target(env, name)
@@ -325,7 +332,7 @@ end
function project._make_targets(configs)
-- check
- assert(configs)
+ assert(configs and configs._TARGETS)
-- init
project._TARGETS = project._TARGETS or {}
@@ -373,16 +380,37 @@ function project._make_targets(configs)
end
end
+-- make option
+function project._make_option(name, opt)
+
+
+end
+
-- make options from the project file
function project._make_options(configs)
-- check
- assert(configs)
+ assert(configs and configs._OPTIONS)
- -- init
- project._OPTIONS = project._OPTIONS or {}
- local options = project._OPTIONS
+ -- make all options
+ for k, v in pairs(configs._OPTIONS) do
+ -- this option has not been enabled?
+ if not config.get(k) then
+
+ -- make option
+ local o = project._make_option(k, v)
+ if o then
+
+ -- enable this option
+ config.set(k, true)
+
+ -- save this option to configure
+ config.set("__" .. k, o)
+
+ end
+ end
+ end
end
-- only load options from the the project file
@@ -478,6 +506,7 @@ function project._load_targets(file)
newenv.modes = function (...) return project._api_modes(newenv, ...) end
newenv.plats = function (...) return project._api_plats(newenv, ...) end
newenv.archs = function (...) return project._api_archs(newenv, ...) end
+ newenv.option = function (...) return project._api_option(newenv, ...) end
-- register interfaces for the target
newenv.set_target = function (...) return project._api_add_target(newenv, ...) end
@@ -495,6 +524,7 @@ function project._load_targets(file)
, "configfile"
, "version"
, "strip"
+ , "options"
, "symbols"
, "warnings"
, "optimize"
@@ -519,6 +549,7 @@ function project._load_targets(file)
, "mxxflags"
, "ldflags"
, "shflags"
+ , "options"
, "defines"
, "undefines"
, "vectorexts"}