summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-07-04 18:40:00 +0800
committerruki <[email protected]>2016-07-04 18:40:00 +0800
commit0bb5ee3e8b5ee719c1bada87be11baca81722afd (patch)
tree7336f2de4d15975a8902ee9ed86d424fad5b21cb
parent721ea838ab717b2a4b477cc239e09b2a5de51878 (diff)
improve to check function
-rw-r--r--CHANGELOG.md2
-rw-r--r--xmake/core/project/option.lua58
-rw-r--r--xmake/core/project/project.lua120
3 files changed, 65 insertions, 115 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 39205f92a..fc32318c1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,7 @@
* Change install and uninstall actions
* Update templates
+* Improve to check function
### Bugs fixed
@@ -105,6 +106,7 @@
* �޸İ�װ��ж�ص�action����
* ���¹���ģ��
+* ��ǿ�������
### Bugs�޸�
diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua
index b1b1e13fd..71226516f 100644
--- a/xmake/core/project/option.lua
+++ b/xmake/core/project/option.lua
@@ -104,10 +104,10 @@ function option:_check_include(include, srcpath, objpath)
end
-- check function
-function option:_check_function(interface, srcpath, objpath)
+function option:_check_function(checkcode, srcpath, objpath)
-- check
- assert(interface)
+ assert(checkcode)
-- open the checking source file
local srcfile = io.open(srcpath, "w")
@@ -137,10 +137,8 @@ function option:_check_function(interface, srcpath, objpath)
srcfile:print("int main(int argc, char** argv)")
srcfile:print("{")
- -- make interfaces
- srcfile:print("#ifndef %s\n", interface)
- srcfile:print(" volatile void* p%s = (void*)&%s;", interface, interface)
- srcfile:print("#endif")
+ -- make check code
+ srcfile:print(" %s;", checkcode)
-- make the main function tailer
srcfile:print(" return 0;")
@@ -305,16 +303,20 @@ end
function option:_check_cfuncs(cfile, objectfile, targetfile)
-- done
- for _, cfunc in ipairs(table.wrap(self:get("cfuncs"))) do
+ for _, checkinfo in ipairs(table.wrap(self:get("cfuncs"))) do
+ -- parse the check code
+ local checkname, checkcode = option.checkinfo(checkinfo)
+ assert(checkname and checkcode)
+
-- check function
- local ok = self:_check_function(cfunc, cfile, objectfile)
+ local ok = self:_check_function(checkcode, cfile, objectfile)
-- check link
if ok and self:get("links") then ok = self:_check_link(cfile, objectfile, targetfile) end
-- trace
- utils.printf("checking for the c function %s ... %s", cfunc, utils.ifelse(ok, "ok", "no"))
+ utils.printf("checking for the c function %s ... %s", checkname, utils.ifelse(ok, "ok", "no"))
-- failed
if not ok then return false end
@@ -328,16 +330,20 @@ end
function option:_check_cxxfuncs(cxxfile, objectfile, targetfile)
-- done
- for _, cxxfunc in ipairs(table.wrap(self:get("cxxfuncs"))) do
-
+ for _, checkinfo in ipairs(table.wrap(self:get("cxxfuncs"))) do
+
+ -- parse the check code
+ local checkname, checkcode = option.checkinfo(checkinfo)
+ assert(checkname and checkcode)
+
-- check function
- local ok = self:_check_function(cxxfunc, cxxfile, objectfile)
+ local ok = self:_check_function(checkcode, cxxfile, objectfile)
-- check link
if ok and self:get("links") then ok = self:_check_link(cxxfile, objectfile, targetfile) end
-- trace
- utils.printf("checking for the c++ function %s ... %s", cxxfunc, utils.ifelse(ok, "ok", "no"))
+ utils.printf("checking for the c++ function %s ... %s", checkname, utils.ifelse(ok, "ok", "no"))
-- failed
if not ok then return false end
@@ -546,5 +552,31 @@ function option:sourcekinds()
return {"cc", "cxx"}
end
+-- get function name and check code
+--
+-- sigsetjmp
+-- sigsetjmp((void*)0, 0)
+-- sigsetjmp{sigsetjmp((void*)0, 0);}
+-- sigsetjmp{int a = 0; sigsetjmp((void*)a, a);}
+--
+function option.checkinfo(checkinfo)
+
+ -- parse name and code
+ local name, code = string.match(checkinfo, "(.+){(.+)}")
+ if code == nil then
+ local pos = checkinfo:find("%(")
+ if pos then
+ name = checkinfo:sub(1, pos - 1)
+ code = checkinfo
+ else
+ name = checkinfo
+ code = string.format("volatile void* p%s = (void*)&%s;", name, name)
+ end
+ end
+
+ -- ok
+ return name:trim(), code
+end
+
-- return module
return option
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index c71ee45ac..9f9b80547 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -126,46 +126,6 @@ function project._api_is_option(interp, ...)
end
end
--- add c function
-function project._api_add_cfunc(interp, module, alias, links, includes, cfunc)
-
- -- check
- assert(interp and cfunc)
-
- -- make the option name
- local name = nil
- if module ~= nil then
- name = string.format("__%s_%s", module, cfunc)
- else
- name = string.format("__%s", cfunc)
- end
-
- -- make the option define
- local define = nil
- if module ~= nil then
- define = string.format("$(prefix)_%s_HAVE_%s", module:upper(), utils.ifelse(alias, alias, cfunc:upper()))
- else
- define = string.format("$(prefix)_HAVE_%s", utils.ifelse(alias, alias, cfunc:upper()))
- end
-
- -- save the current scope
- local scope = interp:scope_save()
-
- -- check option
- interp:api_call("option", name)
- interp:api_call("set_category", "cfuncs")
- interp:api_call("add_cfuncs", cfunc)
- if links then interp:api_call("add_links", links) end
- if includes then interp:api_call("add_cincludes", includes) end
- interp:api_call("add_defines_h_if_ok", define)
-
- -- restore the current scope
- interp:scope_restore(scope)
-
- -- add this option to the current scope
- interp:api_call("add_options", name)
-end
-
-- add c functions
function project._api_add_cfuncs(interp, module, links, includes, ...)
@@ -173,25 +133,26 @@ function project._api_add_cfuncs(interp, module, links, includes, ...)
assert(interp)
-- done
- for _, cfunc in ipairs({...}) do
+ for _, checkinfo in ipairs({...}) do
- -- check
- assert(cfunc)
+ -- parse the check code
+ local checkname, checkcode = option.checkinfo(checkinfo)
+ assert(checkname and checkcode)
-- make the option name
local name = nil
if module ~= nil then
- name = string.format("__%s_%s", module, cfunc)
+ name = string.format("__%s_%s", module, checkname)
else
- name = string.format("__%s", cfunc)
+ name = string.format("__%s", checkname)
end
-- make the option define
local define = nil
if module ~= nil then
- define = string.format("$(prefix)_%s_HAVE_%s", module:upper(), cfunc:upper())
+ define = string.format("$(prefix)_%s_HAVE_%s", module:upper(), checkname:upper())
else
- define = string.format("$(prefix)_HAVE_%s", cfunc:upper())
+ define = string.format("$(prefix)_HAVE_%s", checkname:upper())
end
-- save the current scope
@@ -200,7 +161,7 @@ function project._api_add_cfuncs(interp, module, links, includes, ...)
-- check option
interp:api_call("option", name)
interp:api_call("set_category", "cfuncs")
- interp:api_call("add_cfuncs", cfunc)
+ interp:api_call("add_cfuncs", checkinfo)
if links then interp:api_call("add_links", links) end
if includes then interp:api_call("add_cincludes", includes) end
interp:api_call("add_defines_h_if_ok", define)
@@ -213,46 +174,6 @@ function project._api_add_cfuncs(interp, module, links, includes, ...)
end
end
--- add c++ function
-function project._api_add_cxxfunc(interp, module, alias, links, includes, cxxfunc)
-
- -- check
- assert(interp and cxxfunc)
-
- -- make the option name
- local name = nil
- if module ~= nil then
- name = string.format("__%s_%s", module, cxxfunc)
- else
- name = string.format("__%s", cxxfunc)
- end
-
- -- make the option define
- local define = nil
- if module ~= nil then
- define = string.format("$(prefix)_%s_HAVE_%s", module:upper(), utils.ifelse(alias, alias, cxxfunc:upper()))
- else
- define = string.format("$(prefix)_HAVE_%s", utils.ifelse(alias, alias, cxxfunc:upper()))
- end
-
- -- save the current scope
- local scope = interp:scope_save()
-
- -- check option
- interp:api_call("option", name)
- interp:api_call("set_category", "cxxfuncs")
- interp:api_call("add_cxxfuncs", cxxfunc)
- if links then interp:api_call("add_links", links) end
- if includes then interp:api_call("add_cxxincludes", includes) end
- interp:api_call("add_defines_h_if_ok", define)
-
- -- restore the current scope
- interp:scope_restore(scope)
-
- -- add this option
- interp:api_call("add_options", name)
-end
-
-- add c++ functions
function project._api_add_cxxfuncs(interp, module, links, includes, ...)
@@ -260,25 +181,26 @@ function project._api_add_cxxfuncs(interp, module, links, includes, ...)
assert(interp and module)
-- done
- for _, cxxfunc in ipairs({...}) do
+ for _, checkinfo in ipairs({...}) do
- -- check
- assert(cxxfunc)
+ -- parse the check code
+ local checkname, checkcode = option.checkinfo(checkinfo)
+ assert(checkname and checkcode)
-- make the option name
local name = nil
if module ~= nil then
- name = string.format("__%s_%s", module, cxxfunc)
+ name = string.format("__%s_%s", module, checkname)
else
- name = string.format("__%s", cxxfunc)
+ name = string.format("__%s", checkname)
end
-- make the option define
local define = nil
if module ~= nil then
- define = string.format("$(prefix)_%s_HAVE_%s", module:upper(), cxxfunc:upper())
+ define = string.format("$(prefix)_%s_HAVE_%s", module:upper(), checkname:upper())
else
- define = string.format("$(prefix)_HAVE_%s", cxxfunc:upper())
+ define = string.format("$(prefix)_HAVE_%s", checkname:upper())
end
-- save the current scope
@@ -287,7 +209,7 @@ function project._api_add_cxxfuncs(interp, module, links, includes, ...)
-- check option
interp:api_call("option", name)
interp:api_call("set_category", "cxxfuncs")
- interp:api_call("add_cxxfuncs", cxxfunc)
+ interp:api_call("add_cxxfuncs", checkinfo)
if links then interp:api_call("add_links", links) end
if includes then interp:api_call("add_cxxincludes", includes) end
interp:api_call("add_defines_h_if_ok", define)
@@ -455,15 +377,9 @@ function project._interpreter()
interp:api_register_add_pathes("option", "linkdirs"
, "includedirs")
- -- register api: add_cfunc() to target
- interp:api_register("target", "add_cfunc", project._api_add_cfunc)
-
-- register api: add_cfuncs() to target
interp:api_register("target", "add_cfuncs", project._api_add_cfuncs)
- -- register api: add_cxxfunc() to target
- interp:api_register("target", "add_cxxfunc", project._api_add_cxxfunc)
-
-- register api: add_cxxfuncs() to target
interp:api_register("target", "add_cxxfuncs", project._api_add_cxxfuncs)