summaryrefslogtreecommitdiff
path: root/xmake/core/project/option.lua
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 /xmake/core/project/option.lua
parent721ea838ab717b2a4b477cc239e09b2a5de51878 (diff)
improve to check function
Diffstat (limited to 'xmake/core/project/option.lua')
-rw-r--r--xmake/core/project/option.lua58
1 files changed, 45 insertions, 13 deletions
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