summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-07-27 09:52:52 +0800
committerruki <[email protected]>2017-07-27 09:52:52 +0800
commit84defbee206dd2d810070bfae7b7e269a3445896 (patch)
treee03f04e287b29689f570d308efd057230f355f16
parentcb26be417ab85228b8dcbbb11bda655eb714e07e (diff)
add set_config_header instead of set_config_h and set_config_h_prefix
-rw-r--r--CHANGELOG.md2
-rw-r--r--xmake/actions/config/configheader.lua20
-rw-r--r--xmake/core/base/interpreter.lua16
-rw-r--r--xmake/core/project/target.lua90
-rw-r--r--xmake/languages/c++/api.lua6
-rw-r--r--xmake/languages/objc++/api.lua6
6 files changed, 86 insertions, 54 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bc894321b..17a4a9efe 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -39,6 +39,7 @@
* Optimize `xmake rebuild` speed on windows
* Move `core.project.task` to `core.base.task`
* Move `echo` and `app2ipa` plugins to [xmake-plugins](https://github.com/tboox/xmake-plugins) repo.
+* Add new api `set_config_header("config.h", {prefix = ""})` instead of `set_config_h` and `set_config_h_prefix`
### Bugs fixed
@@ -354,6 +355,7 @@
* 优化`xmake rebuild`在windows上的构建速度
* 将`core.project.task`模块迁移至`core.base.task`
* 将`echo` 和 `app2ipa` 插件迁移到 [xmake-plugins](https://github.com/tboox/xmake-plugins) 仓库
+* 添加`set_config_header("config.h", {prefix = ""})` 代替 `set_config_h` 和 `set_config_h_prefix`
### Bugs修复
diff --git a/xmake/actions/config/configheader.lua b/xmake/actions/config/configheader.lua
index ccae5237d..3187b6c83 100644
--- a/xmake/actions/config/configheader.lua
+++ b/xmake/actions/config/configheader.lua
@@ -34,31 +34,31 @@ function _make_for_target(files, target)
local configheader = target:configheader()
if not configheader then return end
- -- the prefix
- local prefix = target:get("config_h_prefix") or (target:name():upper() .. "_CONFIG")
+ -- get the config prefix
+ local configprefix = target:configprefix()
-- open the file
local file = files[configheader] or io.open(configheader, "w")
-- make the head
if files[configheader] then file:print("") end
- file:print("#ifndef %s_H", prefix)
- file:print("#define %s_H", prefix)
+ file:print("#ifndef %s_H", configprefix)
+ file:print("#define %s_H", configprefix)
file:print("")
-- make version
local version = project.version()
if version then
file:print("// version")
- file:print("#define %s_VERSION \"%s\"", prefix, version)
+ file:print("#define %s_VERSION \"%s\"", configprefix, version)
local i = 1
local m = {"MAJOR", "MINOR", "ALTER"}
for v in version:gmatch("%d+") do
- file:print("#define %s_VERSION_%s %s", prefix, m[i], v)
+ file:print("#define %s_VERSION_%s %s", configprefix, m[i], v)
i = i + 1
if i > 3 then break end
end
- file:print("#define %s_VERSION_BUILD %s", prefix, os.date("%Y%m%d%H%M", os.time()))
+ file:print("#define %s_VERSION_BUILD %s", configprefix, os.date("%Y%m%d%H%M", os.time()))
file:print("")
end
@@ -85,9 +85,9 @@ function _make_for_target(files, target)
file:print("// defines")
for _, define in ipairs(defines) do
if define:find("=") then
- file:print("#define %s", define:gsub("=", " "):gsub("%$%((.-)%)", function (w) if w == "prefix" then return prefix end end))
+ file:print("#define %s", define:gsub("=", " "):gsub("%$%((.-)%)", function (w) if w == "prefix" then return configprefix end end))
else
- file:print("#define %s 1", define:gsub("%$%((.-)%)", function (w) if w == "prefix" then return prefix end end))
+ file:print("#define %s 1", define:gsub("%$%((.-)%)", function (w) if w == "prefix" then return configprefix end end))
end
end
file:print("")
@@ -97,7 +97,7 @@ function _make_for_target(files, target)
if #undefines ~= 0 then
file:print("// undefines")
for _, undefine in ipairs(undefines) do
- file:print("#undef %s", undefine:gsub("%$%((.-)%)", function (w) if w == "prefix" then return prefix end end))
+ file:print("#undef %s", undefine:gsub("%$%((.-)%)", function (w) if w == "prefix" then return configprefix end end))
end
file:print("")
end
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua
index 49592e082..5577b2a9a 100644
--- a/xmake/core/base/interpreter.lua
+++ b/xmake/core/base/interpreter.lua
@@ -333,15 +333,17 @@ function interpreter:_api_translate_pathes(...)
local curdir = path.directory(curfile)
assert(curdir)
- -- get all pathes
- local pathes = table.join(...)
-
-- translate the relative path
local results = {}
- for _, p in ipairs(pathes) do
- if not p:find("^%s-%$%(.-%)") and not path.is_absolute(p) then
- table.insert(results, path.relative(path.absolute(p, curdir), self._PRIVATE._ROOTDIR))
+ for _, p in ipairs({...}) do
+ if type(p) == "string" then
+ if not p:find("^%s-%$%(.-%)") and not path.is_absolute(p) then
+ table.insert(results, path.relative(path.absolute(p, curdir), self._PRIVATE._ROOTDIR))
+ else
+ table.insert(results, p)
+ end
else
+ -- @note do not translate non-string value, .e.g set_xxx("/xx/xx/xx", {arg = ""})
table.insert(results, p)
end
end
@@ -1092,7 +1094,6 @@ function interpreter:api_register_add_values(scope_kind, ...)
-- append values?
scope[name] = scope[name] or {}
table.join2(scope[name], ...)
-
end
-- register implementation
@@ -1111,7 +1112,6 @@ function interpreter:api_register_set_array(scope_kind, ...)
-- update array?
scope[name] = {}
table.insert(scope[name], {...})
-
end
-- register implementation
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index 971b85cd6..f001f1fa2 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -271,38 +271,6 @@ function target:headerdir()
return self:get("headerdir") or config.get("buildir")
end
--- get the config header files
-function target:configheader(outputdir)
-
- -- get config header
- local configheader = self:get("config_h")
- if not configheader then
- return
- end
-
- -- get the root directory
- local rootdir, count = configheader:gsub("|.*$", ""):gsub("%(.*%)$", "")
- if count == 0 then
- rootdir = nil
- end
-
- -- remove '(' and ')'
- configheader = configheader:gsub("[%(%)]", "")
-
- -- get the output header
- local outputheader = nil
- if outputdir then
- if rootdir then
- outputheader = path.absolute(path.relative(configheader, rootdir), outputdir)
- else
- outputheader = path.join(outputdir, path.filename(configheader))
- end
- end
-
- -- ok
- return configheader, outputheader
-end
-
-- get the source files
function target:sourcefiles()
@@ -693,5 +661,63 @@ function target:script(name, generic)
return generic
end
+-- get the config header prefix
+function target:configprefix()
+
+ -- get the config prefix
+ local configprefix = nil
+ local configheader = self:get("config_header")
+ if type(configheader) == "table" then
+ local opt = configheader[2]
+ if opt then
+ configprefix = opt.prefix
+ end
+ end
+ if not configprefix then
+ configprefix = self:get("config_h_prefix") or (self:name():upper() .. "_CONFIG")
+ end
+
+ -- ok?
+ return configprefix
+end
+
+-- get the config header files
+function target:configheader(outputdir)
+
+ -- get config header
+ local configheader = self:get("config_header") -- set_config_header("/xxx/config.h", {prefix = XX_CONFIG})
+ if type(configheader) == "table" then
+ configheader = configheader[1]
+ end
+ if not configheader then
+ configheader = self:get("config_h")
+ end
+ if not configheader then
+ return
+ end
+
+ -- get the root directory
+ local rootdir, count = configheader:gsub("|.*$", ""):gsub("%(.*%)$", "")
+ if count == 0 then
+ rootdir = nil
+ end
+
+ -- remove '(' and ')'
+ configheader = configheader:gsub("[%(%)]", "")
+
+ -- get the output header
+ local outputheader = nil
+ if outputdir then
+ if rootdir then
+ outputheader = path.absolute(path.relative(configheader, rootdir), outputdir)
+ else
+ outputheader = path.join(outputdir, path.filename(configheader))
+ end
+ end
+
+ -- ok
+ return configheader, outputheader
+end
+
-- return module
return target
diff --git a/xmake/languages/c++/api.lua b/xmake/languages/c++/api.lua
index 4af3147f5..78f89ac6f 100644
--- a/xmake/languages/c++/api.lua
+++ b/xmake/languages/c++/api.lua
@@ -164,7 +164,7 @@ function apis()
_g.values =
{
-- target.set_xxx
- "target.set_config_h_prefix"
+ "target.set_config_h_prefix" -- deprecated
-- target.add_xxx
, "target.add_links"
, "target.add_cflags"
@@ -206,7 +206,9 @@ function apis()
{
-- target.set_xxx
"target.set_headerdir"
- , "target.set_config_h"
+ , "target.set_config_h" -- deprecated
+ , "target.set_config_header"
+ , "target.set_precompiled_header"
-- target.add_xxx
, "target.add_headers"
, "target.add_linkdirs"
diff --git a/xmake/languages/objc++/api.lua b/xmake/languages/objc++/api.lua
index 4c6d8fc75..63e311c33 100644
--- a/xmake/languages/objc++/api.lua
+++ b/xmake/languages/objc++/api.lua
@@ -29,7 +29,7 @@ function apis()
_g.values =
{
-- target.set_xxx
- "target.set_config_h_prefix"
+ "target.set_config_h_prefix" -- deprecated
-- target.add_xxx
, "target.add_links"
, "target.add_mflags"
@@ -69,7 +69,9 @@ function apis()
{
-- target.set_xxx
"target.set_headerdir"
- , "target.set_config_h"
+ , "target.set_config_h" -- deprecated
+ , "target.set_config_header"
+ , "target.set_precompiled_header"
-- target.add_xxx
, "target.add_headers"
, "target.add_linkdirs"