From b5a4e93c9f12c9f9ce23c3c4c17b26c7960cbfc2 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 15 Nov 2022 22:29:23 +0800 Subject: improve to find_cl --- xmake/modules/detect/tools/find_cl.lua | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/xmake/modules/detect/tools/find_cl.lua b/xmake/modules/detect/tools/find_cl.lua index 4ee7108c6..350f15c86 100644 --- a/xmake/modules/detect/tools/find_cl.lua +++ b/xmake/modules/detect/tools/find_cl.lua @@ -38,7 +38,18 @@ function main(opt) -- init options opt = opt or {} - opt.check = opt.check or function (program) os.runv(program, {}, {envs = opt.envs}) end + opt.check = opt.check or function (program) + local ok = try { function () os.runv(program, {}, {envs = opt.envs}); return true end } + if not ok then + -- @see https://github.com/xmake-io/xmake/issues/3057 + local objectfile = os.tmpfile() .. ".obj" + local sourcefile = os.tmpfile() .. ".c" + io.writefile(sourcefile, "int main(int argc, char** argv)\n{return 0;}") + os.runv(program, {"-c", "-Fo" .. objectfile, sourcefile}, {envs = opt.envs}) + os.rm(objectfile) + os.rm(sourcefile) + end + end -- find program local program = find_program(opt.program or "cl.exe", opt) -- cgit v1.3.1