diff options
| author | ruki <[email protected]> | 2015-06-11 14:31:53 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-06-11 14:31:53 +0800 |
| commit | 2b17a555fd3a5b4711b36a5b5a85b98146e5fa12 (patch) | |
| tree | 86be7e1ae0fe0731f216f2d04287430b85014c66 /xmake/scripts/base/project.lua | |
| parent | f5b089a2170c000d4c0781eb08d6545894b14ab9 (diff) | |
make configure header file for options
Diffstat (limited to 'xmake/scripts/base/project.lua')
| -rw-r--r-- | xmake/scripts/base/project.lua | 53 |
1 files changed, 51 insertions, 2 deletions
diff --git a/xmake/scripts/base/project.lua b/xmake/scripts/base/project.lua index 85972c066..79a7007be 100644 --- a/xmake/scripts/base/project.lua +++ b/xmake/scripts/base/project.lua @@ -80,10 +80,13 @@ function project._api_archs(env, ...) end -- enable option? -function project._api_option(env, opt) +function project._api_option(env, name) + + -- check + assert(name) -- enable? - return config.get(opt) + return config.get(name) end -- add target @@ -297,6 +300,47 @@ function project._makeconf_for_target(target_name, target) file:write("\n") end + -- the options + if target.options then + for _, name in ipairs(utils.wrap(target.options)) do + + -- get option if be enabled + local opt = nil + if config.get(name) then opt = config.get("__" .. name) end + if nil ~= opt then + + -- get the option defines + local defines = {} + if opt.defines then table.join2(defines, opt.defines) end + if opt.defines_if_ok then table.join2(defines, opt.defines_if_ok) end + + -- get the option undefines + local undefines = {} + if opt.undefines then table.join2(undefines, opt.undefines) end + if opt.undefines_if_ok then table.join2(undefines, opt.undefines_if_ok) end + + -- make the defines for options + if #defines ~= 0 then + file:write(string.format("// defines for %s\n", name)) + for _, define in ipairs(defines) do + file:write(string.format("#define %s\n", define:gsub("=", " "))) + end + file:write("\n") + end + + -- make the undefines for options + if #undefines ~= 0 then + file:write(string.format("// undefines for %s\n", name)) + for _, undefine in ipairs(undefines) do + file:write(string.format("#undef %s\n", undefine)) + end + file:write("\n") + end + end + end + end + + -- make the tail file:write("#endif\n") @@ -534,6 +578,11 @@ function project._make_options(configs) -- trace utils.verbose("checking for the option %s ... %s", k, utils.ifelse(o, "ok", "no")) + + elseif nil == config.get("__" .. k) then + + -- save this option to configure + config.set("__" .. k, v) end end |
