diff options
| author | ruki <[email protected]> | 2017-07-10 21:34:02 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-07-10 21:34:02 +0800 |
| commit | 03420ca44581f299a48935ca60af4824575cd9c1 (patch) | |
| tree | b4644e07c92e62b973d15f3f0d3e0ee41f95446e /xmake/modules/detect | |
| parent | def23a930fc3780e54b2a8a6fc60854d2e193000 (diff) | |
add has_features and features for compiler
Diffstat (limited to 'xmake/modules/detect')
| -rw-r--r-- | xmake/modules/detect/tools/gcc/features.lua | 7 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/gcc/has_flag.lua | 14 |
2 files changed, 16 insertions, 5 deletions
diff --git a/xmake/modules/detect/tools/gcc/features.lua b/xmake/modules/detect/tools/gcc/features.lua index 5047cb36c..da65e87a2 100644 --- a/xmake/modules/detect/tools/gcc/features.lua +++ b/xmake/modules/detect/tools/gcc/features.lua @@ -25,6 +25,7 @@ -- imports import("cfeatures") import("cxxfeatures") +import("core.language.language") -- get macro defines function _get_macro_defines(snippets, extension, opt) @@ -62,11 +63,11 @@ function _set_feature(feature, condition) local kind = feature:match("^(%w-)_") assert(kind, "unknown kind for the feature: %s", feature) - -- init language extensions - _g.extensions = _g.extensions or {c = ".c", cxx = ".cpp", objc = ".m", objcxx = ".mm"} + -- init maps for c, objc + local kinds = {c = "cc", m = "mm"} -- get extension - local extension = _g.extensions[kind] + local extension = table.wrap(language.sourcekinds()[kinds[kind] or kind])[1] assert(extension, "not supported kind for the feature: %s", feature) -- make snippet diff --git a/xmake/modules/detect/tools/gcc/has_flag.lua b/xmake/modules/detect/tools/gcc/has_flag.lua index abd0f5955..a8268f75b 100644 --- a/xmake/modules/detect/tools/gcc/has_flag.lua +++ b/xmake/modules/detect/tools/gcc/has_flag.lua @@ -24,6 +24,7 @@ -- imports import("lib.detect.cache") +import("core.language.language") -- is linker? function _islinker(flag, opt) @@ -83,8 +84,11 @@ function _check_try_running(flag, opt, islinker) -- check flag for linker if islinker then + -- get extension + local extension = table.wrap(language.sourcekinds()[opt.toolkind or "cc"])[1] or ".c" + -- make an stub source file - local sourcefile = path.join(os.tmpdir(), "detect", "gcc_has_flag.c") + local sourcefile = path.join(os.tmpdir(), "detect", "gcc_has_flag" .. extension) if not os.isfile(sourcefile) then io.writefile(sourcefile, "int main(int argc, char** argv)\n{return 0;}") end @@ -92,9 +96,15 @@ function _check_try_running(flag, opt, islinker) -- check it return try { function () os.runv(opt.program, {flag, "-o", os.nuldev(), sourcefile}); return true end } end + + -- get language + local lang = "c" + if opt.toolkind and (opt.toolkind == "cxx" or opt.toolkind == "mxx") then + lang = "c++" + end -- check flag for compiler - return try { function () os.runv(opt.program, {flag, "-S", "-o", os.nuldev(), "-xc", os.nuldev()}); return true end } + return try { function () os.runv(opt.program, {flag, "-S", "-o", os.nuldev(), "-x" .. lang, os.nuldev()}); return true end } end -- has_flag(flag)? |
