summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-09-19 21:00:39 +0800
committerruki <[email protected]>2016-09-19 21:00:39 +0800
commit7ae0f53e70fe9909e3a42f8989fe1acc52168541 (patch)
treebb99d18b3c44dc95fe02bc709d528e0903e5a7fc
parent38002b01f85d2c58de18aed9c8ea16635f2357e5 (diff)
restore add_cfunc and add_cxxfunc for project
-rw-r--r--xmake/core/project/project.lua168
1 files changed, 98 insertions, 70 deletions
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index 3d5abb485..18524301e 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -127,99 +127,125 @@ function project._api_is_option(interp, ...)
end
end
--- add c functions
-function project._api_add_cfuncs(interp, module, links, includes, ...)
+-- add c function
+function project._api_add_cfunc(interp, module, alias, links, includes, checkinfo)
-- check
assert(interp)
- -- done
- for _, checkinfo in ipairs({...}) do
+ -- parse the check code
+ local checkname, checkcode = option.checkinfo(checkinfo)
+ assert(checkname and checkcode)
- -- 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, checkname)
+ else
+ name = string.format("__%s", checkname)
+ end
- -- make the option name
- local name = nil
- if module ~= nil then
- name = string.format("__%s_%s", module, checkname)
- else
- name = string.format("__%s", checkname)
- end
+ -- uses the alias name
+ if alias ~= nil then
+ checkname = alias
+ end
- -- make the option define
- local define = nil
- if module ~= nil then
- define = string.format("$(prefix)_%s_HAVE_%s", module:upper(), checkname:upper())
- else
- define = string.format("$(prefix)_HAVE_%s", checkname:upper())
- end
+ -- make the option define
+ local define = nil
+ if module ~= nil then
+ define = string.format("$(prefix)_%s_HAVE_%s", module:upper(), checkname:upper())
+ else
+ define = string.format("$(prefix)_HAVE_%s", checkname:upper())
+ end
- -- save the current scope
- local scope = interp:scope_save()
+ -- 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", 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)
+ -- check option
+ interp:api_call("option", name)
+ interp:api_call("set_category", "cfuncs")
+ 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)
- -- restore the current scope
- interp:scope_restore(scope)
+ -- restore the current scope
+ interp:scope_restore(scope)
- -- add this option
- interp:api_call("add_options", name)
- end
+ -- add this option
+ interp:api_call("add_options", name)
end
--- add c++ functions
-function project._api_add_cxxfuncs(interp, module, links, includes, ...)
+-- add c functions
+function project._api_add_cfuncs(interp, module, links, includes, ...)
-- check
- assert(interp and module)
+ assert(interp)
-- done
for _, checkinfo in ipairs({...}) do
+ project._api_add_cfunc(interp, module, nil, links, includes, checkinfo)
+ end
+end
- -- parse the check code
- local checkname, checkcode = option.checkinfo(checkinfo)
- assert(checkname and checkcode)
+-- add c++ function
+function project._api_add_cxxfunc(interp, module, alias, links, includes, checkinfo)
- -- make the option name
- local name = nil
- if module ~= nil then
- name = string.format("__%s_%s", module, checkname)
- else
- name = string.format("__%s", checkname)
- end
+ -- check
+ assert(interp and module)
- -- make the option define
- local define = nil
- if module ~= nil then
- define = string.format("$(prefix)_%s_HAVE_%s", module:upper(), checkname:upper())
- else
- define = string.format("$(prefix)_HAVE_%s", checkname:upper())
- end
+ -- 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, checkname)
+ else
+ name = string.format("__%s", checkname)
+ end
- -- save the current scope
- local scope = interp:scope_save()
+ -- uses the alias name
+ if alias ~= nil then
+ checkname = alias
+ end
+
+ -- make the option define
+ local define = nil
+ if module ~= nil then
+ define = string.format("$(prefix)_%s_HAVE_%s", module:upper(), checkname:upper())
+ else
+ define = string.format("$(prefix)_HAVE_%s", checkname:upper())
+ end
- -- check option
- interp:api_call("option", name)
- interp:api_call("set_category", "cxxfuncs")
- 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)
+ -- save the current scope
+ local scope = interp:scope_save()
- -- restore the current scope
- interp:scope_restore(scope)
+ -- check option
+ interp:api_call("option", name)
+ interp:api_call("set_category", "cxxfuncs")
+ 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)
- -- add this option
- interp:api_call("add_options", name)
+ -- 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, ...)
+
+ -- check
+ assert(interp and module)
+
+ -- done
+ for _, checkinfo in ipairs({...}) do
+ project._api_add_cxxfunc(interp, module, nil, links, includes, checkinfo)
end
end
@@ -379,10 +405,12 @@ function project._interpreter()
interp:api_register_add_pathes("option", "linkdirs"
, "includedirs")
- -- register api: add_cfuncs() to target
+ -- register api: add_cfunc() and add_cfuncs() to target
+ interp:api_register("target", "add_cfunc", project._api_add_cfunc)
interp:api_register("target", "add_cfuncs", project._api_add_cfuncs)
- -- register api: add_cxxfuncs() to target
+ -- register api: add_cxxfunc() and add_cxxfuncs() to target
+ interp:api_register("target", "add_cxxfunc", project._api_add_cxxfunc)
interp:api_register("target", "add_cxxfuncs", project._api_add_cxxfuncs)
-- register api: add_packages() to target