From e288951c41b72f3ccf3cfed495417fea7dee1e79 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 15 Feb 2023 22:46:13 +0800 Subject: add snippet to has_flags --- xmake/modules/detect/tools/cl/has_flags.lua | 6 +++--- xmake/modules/detect/tools/gcc/has_flags.lua | 5 +++-- xmake/modules/detect/tools/nvcc/has_flags.lua | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/xmake/modules/detect/tools/cl/has_flags.lua b/xmake/modules/detect/tools/cl/has_flags.lua index fe57e38b0..e1e986303 100644 --- a/xmake/modules/detect/tools/cl/has_flags.lua +++ b/xmake/modules/detect/tools/cl/has_flags.lua @@ -54,10 +54,10 @@ end function _check_try_running(flags, opt) -- make an stub source file - local tmpdir = path.join(os.tmpdir(), "detect") - local sourcefile = path.join(tmpdir, "cl_has_flags" .. _get_extension(opt)) + local snippet = opt.snippet or "int main(int argc, char** argv)\n{return 0;}" + local sourcefile = os.tmpfile("cl_has_flags:" .. snippet) .. _get_extension(opt) if not os.isfile(sourcefile) then - io.writefile(sourcefile, "int main(int argc, char** argv)\n{return 0;}") + io.writefile(sourcefile, snippet) end -- check it diff --git a/xmake/modules/detect/tools/gcc/has_flags.lua b/xmake/modules/detect/tools/gcc/has_flags.lua index 64fa70df8..6ab7ce810 100644 --- a/xmake/modules/detect/tools/gcc/has_flags.lua +++ b/xmake/modules/detect/tools/gcc/has_flags.lua @@ -77,9 +77,10 @@ end function _check_try_running(flags, opt, islinker) -- make an stub source file - local sourcefile = path.join(os.tmpdir(), "detect", "gcc_has_flags" .. _get_extension(opt)) + local snippet = opt.snippet or "int main(int argc, char** argv)\n{return 0;}" + local sourcefile = os.tmpfile("gcc_has_flags:" .. snippet) .. _get_extension(opt) if not os.isfile(sourcefile) then - io.writefile(sourcefile, "int main(int argc, char** argv)\n{return 0;}") + io.writefile(sourcefile, snippet) end -- check flags for linker diff --git a/xmake/modules/detect/tools/nvcc/has_flags.lua b/xmake/modules/detect/tools/nvcc/has_flags.lua index d96ffdfe8..c75f6e114 100644 --- a/xmake/modules/detect/tools/nvcc/has_flags.lua +++ b/xmake/modules/detect/tools/nvcc/has_flags.lua @@ -101,13 +101,13 @@ end function _check_try_running(flags, opt, islinker) -- make an stub source file - local sourcefile = path.join(os.tmpdir(), "detect", "nvcc_has_flags.cu") + local snippet = opt.snippet or "int main(int argc, char** argv)\n{return 0;}" + local sourcefile = os.tmpfile("nvcc_has_flags:" .. snippet) .. ".cu" if not os.isfile(sourcefile) then - io.writefile(sourcefile, "int main(int argc, char** argv)\n{return 0;}") + io.writefile(sourcefile, snippet) end local args = table.join("-o", os.nuldev(), sourcefile) - if not islinker then table.insert(args, 1, "-c") end -- cgit v1.3.1