diff options
| author | ruki <[email protected]> | 2015-06-17 10:00:20 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-06-17 10:00:20 +0800 |
| commit | 95798306093295a45c8f8671ca2f18edb16f796e (patch) | |
| tree | 50fb9cda7beb32f206d0984561d1678a58c165db /xmake/scripts/base | |
| parent | 12fca34edc350acfa1688bccb3a9e954b71283b0 (diff) | |
check c and c++ types
Diffstat (limited to 'xmake/scripts/base')
| -rw-r--r-- | xmake/scripts/base/compiler.lua | 99 | ||||
| -rw-r--r-- | xmake/scripts/base/project.lua | 60 |
2 files changed, 121 insertions, 38 deletions
diff --git a/xmake/scripts/base/compiler.lua b/xmake/scripts/base/compiler.lua index 0b7c5115d..3bb42cb81 100644 --- a/xmake/scripts/base/compiler.lua +++ b/xmake/scripts/base/compiler.lua @@ -387,6 +387,33 @@ function compiler._kind(srcfile) return kind end +-- make the compile command for option +function compiler._make_for_option(module, opt, srcfile, objfile, logfile) + + -- check + assert(module and opt) + + -- the flag names + local flagnames = compiler._flagnames(module._KIND) + assert(flagnames) + + -- add flags from the compiler + local flags = {} + compiler._addflags_from_compiler(module, flags, flagnames) + + -- add flags from the platform + compiler._addflags_from_platform(module, flags, flagnames) + + -- add flags from the option + compiler._addflags_from_option(module, flags, flagnames, opt) + + -- add flags from the configure + compiler._addflags_from_config(module, flags, flagnames) + + -- execute the compile command + return module:command_compile(srcfile, objfile, table.concat(flags, " "):trim(), logfile) +end + -- get the compiler from the given source file function compiler.get(srcfile) @@ -470,25 +497,8 @@ function compiler.check_include(opt, include, srcpath, objpath) local module = compiler.get(srcpath) if not module then return end - -- the flag names - local flagnames = compiler._flagnames(module._KIND) - assert(flagnames) - - -- add flags from the compiler - local flags = {} - compiler._addflags_from_compiler(module, flags, flagnames) - - -- add flags from the platform - compiler._addflags_from_platform(module, flags, flagnames) - - -- add flags from the option - compiler._addflags_from_option(module, flags, flagnames, opt) - - -- add flags from the configure - compiler._addflags_from_config(module, flags, flagnames) - -- execute the compile command - return module:main(module:command_compile(srcpath, objpath, table.concat(flags, " "):trim(), xmake._NULDEV)) + return module:main(compiler._make_for_option(module, opt, srcpath, objpath, xmake._NULDEV)) end -- check function for the project option @@ -531,25 +541,52 @@ function compiler.check_function(opt, interface, srcpath, objpath) -- exit this file srcfile:close() - -- the flag names - local flagnames = compiler._flagnames(module._KIND) - assert(flagnames) + -- execute the compile command + return module:main(compiler._make_for_option(module, opt, srcpath, objpath, xmake._NULDEV)) +end - -- add flags from the compiler - local flags = {} - compiler._addflags_from_compiler(module, flags, flagnames) +-- check typedef for the project option +function compiler.check_typedef(opt, typedef, srcpath, objpath) - -- add flags from the platform - compiler._addflags_from_platform(module, flags, flagnames) + -- check + assert(opt and typedef) - -- add flags from the option - compiler._addflags_from_option(module, flags, flagnames, opt) + -- open the checking source file + local srcfile = io.openmk(srcpath) + if not srcfile then return end - -- add flags from the configure - compiler._addflags_from_config(module, flags, flagnames) + -- get the compiler + local module = compiler.get(srcpath) + if not module then return end + + -- make includes + local includes = nil + if module._KIND == "cc" then includes = opt.cincludes + elseif module._KIND == "cxx" then includes = opt.cxxincludes + end + if includes then + for _, include in ipairs(utils.wrap(includes)) do + srcfile:write(string.format("#include <%s>\n", include)) + end + srcfile:write("\n") + end + + -- make the main function header + srcfile:write("int main(int argc, char** argv)\n") + srcfile:write("{\n") + + -- make interfaces + srcfile:write(string.format(" typedef %s __type_xxx;\n\n", typedef)) + + -- make the main function tailer + srcfile:write(" return 0;\n") + srcfile:write("}\n") + + -- exit this file + srcfile:close() -- execute the compile command - return module:main(module:command_compile(srcpath, objpath, table.concat(flags, " "):trim(), xmake._NULDEV)) + return module:main(compiler._make_for_option(module, opt, srcpath, objpath, xmake._NULDEV)) end -- return module: compiler diff --git a/xmake/scripts/base/project.lua b/xmake/scripts/base/project.lua index 9f6aaef38..41b754a45 100644 --- a/xmake/scripts/base/project.lua +++ b/xmake/scripts/base/project.lua @@ -644,6 +644,46 @@ function project._make_option_for_checking_cxxfuncs(opt, cxxfuncs, cxxfile, obje return true end +-- make option for checking ctypes +function project._make_option_for_checking_ctypes(opt, ctypes, cfile, objectfile, targetfile) + + -- done + for _, ctype in ipairs(utils.wrap(ctypes)) do + + -- check type + local ok = compiler.check_typedef(opt, ctype, cfile, objectfile) + + -- trace + utils.verbose("checking for the c type %s ... %s", ctype, utils.ifelse(ok, "ok", "no")) + + -- failed + if not ok then return false end + end + + -- ok + return true +end + +-- make option for checking cxxtypes +function project._make_option_for_checking_cxxtypes(opt, cxxtypes, cxxfile, objectfile, targetfile) + + -- done + for _, cxxtype in ipairs(utils.wrap(cxxtypes)) do + + -- check type + local ok = compiler.check_typedef(opt, cxxtype, cxxfile, objectfile) + + -- trace + utils.verbose("checking for the c++ type %s ... %s", cxxtype, utils.ifelse(ok, "ok", "no")) + + -- failed + if not ok then return false end + end + + -- ok + return true +end + -- make option function project._make_option(name, opt, cfile, cxxfile, objectfile, targetfile) @@ -664,24 +704,28 @@ function project._make_option(name, opt, cfile, cxxfile, objectfile, targetfile) end -- check links - if opt.links then - if not project._make_option_for_checking_links(opt, opt.links, cfile, objectfile, targetfile) then return end - end + if opt.links and not project._make_option_for_checking_links(opt, opt.links, cfile, objectfile, targetfile) then return end + + -- check ctypes + if opt.ctypes and not project._make_option_for_checking_ctypes(opt, opt.ctypes, cfile, objectfile, targetfile) then return end + + -- check cxxtypes + if opt.cxxtypes and not project._make_option_for_checking_cxxtypes(opt, opt.cxxtypes, cxxfile, objectfile, targetfile) then return end -- check includes and functions if opt.cincludes or opt.cxxincludes then -- check cincludes - if not project._make_option_for_checking_cincludes(opt, opt.cincludes, cfile, objectfile) then return end + if opt.cincludes and not project._make_option_for_checking_cincludes(opt, opt.cincludes, cfile, objectfile) then return end -- check cxxincludes - if not project._make_option_for_checking_cxxincludes(opt, opt.cxxincludes, cxxfile, objectfile) then return end + if opt.cxxincludes and not project._make_option_for_checking_cxxincludes(opt, opt.cxxincludes, cxxfile, objectfile) then return end -- check cfuncs - if not project._make_option_for_checking_cfuncs(opt, opt.cfuncs, cfile, objectfile, targetfile) then return end + if opt.cfuncs and not project._make_option_for_checking_cfuncs(opt, opt.cfuncs, cfile, objectfile, targetfile) then return end -- check cxxfuncs - if not project._make_option_for_checking_cxxfuncs(opt, opt.cxxfuncs, cxxfile, objectfile, targetfile) then return end + if opt.cxxfuncs and not project._make_option_for_checking_cxxfuncs(opt, opt.cxxfuncs, cxxfile, objectfile, targetfile) then return end end @@ -800,6 +844,8 @@ function project._load_options(file) , "cxxincludes" , "cfuncs" , "cxxfuncs" + , "ctypes" + , "cxxtypes" , "cflags" , "cxflags" , "cxxflags" |
