diff options
| author | ruki <[email protected]> | 2019-12-08 11:32:54 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-12-08 11:32:54 +0800 |
| commit | f2973f2e1a57910f5c2056ae9f4522fbff6d7112 (patch) | |
| tree | a42acd0ce3d95320ccf5061b5c908e6a081b06b1 | |
| parent | ba6dd015de784b423df292176fbe7045371af261 (diff) | |
improve check flags
| -rw-r--r-- | xmake/modules/detect/tools/gcc/has_flags.lua | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/xmake/modules/detect/tools/gcc/has_flags.lua b/xmake/modules/detect/tools/gcc/has_flags.lua index 51bb93b51..7612dd845 100644 --- a/xmake/modules/detect/tools/gcc/has_flags.lua +++ b/xmake/modules/detect/tools/gcc/has_flags.lua @@ -41,6 +41,7 @@ function _try_running(...) local argv = {...} local errors = nil + print(argv) return try { function () os.runv(unpack(argv)); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors end @@ -86,31 +87,24 @@ end -- try running to check flags function _check_try_running(flags, opt, islinker) - -- check flags for linker - if islinker then - - -- get extension - -- @note we need detect extension for ndk/clang++.exe: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] - local extension = opt.program:endswith("++") and ".cpp" or (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_flags" .. extension) - if not os.isfile(sourcefile) then - io.writefile(sourcefile, "int main(int argc, char** argv)\n{return 0;}") - end + -- get extension + -- @note we need detect extension for ndk/clang++.exe: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] + local extension = opt.program:endswith("++") and ".cpp" or (table.wrap(language.sourcekinds()[opt.toolkind or "cc"])[1] or ".c") - -- check it - return _try_running(opt.program, table.join(flags, "-o", os.nuldev(), sourcefile)) + -- make an stub source file + local sourcefile = path.join(os.tmpdir(), "detect", "gcc_has_flags" .. extension) + if not os.isfile(sourcefile) then + io.writefile(sourcefile, "int main(int argc, char** argv)\n{return 0;}") end - -- get language - local lang = "c" - if opt.toolkind and (opt.toolkind == "cxx" or opt.toolkind == "mxx") then - lang = "c++" + -- check flags for linker + if islinker then + return _try_running(opt.program, table.join(flags, "-o", os.tmpfile(), sourcefile)) end - + -- check flags for compiler - return _try_running(opt.program, table.join(flags, "-S", "-o", os.nuldev(), "-x" .. lang, os.nuldev(true))) + -- @note we cannot use os.nuldev() as the output file, maybe run failed for some flags, e.g. --coverage + return _try_running(opt.program, table.join(flags, "-S", "-o", os.tmpfile(), sourcefile)) end -- has_flags(flags)? |
