diff options
| author | ruki <[email protected]> | 2023-02-16 21:46:32 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-02-16 21:46:32 +0800 |
| commit | 0eccc6e924eeb8deb66191e23298fd168ee2e833 (patch) | |
| tree | b06dccd04f68cc6170c506ae2806e96956943a9d /xmake/modules/detect | |
| parent | 2c7cd309e27e2b15619ee5bf1e2a4098d7c729ec (diff) | |
| parent | 4b32e484b54f61f649e46a94823f99ee940c9ed3 (diff) | |
Merge pull request #3363 from xmake-io/stdmodules
improve clang (17.0) for stdmodules
Diffstat (limited to 'xmake/modules/detect')
| -rw-r--r-- | xmake/modules/detect/tools/cl/has_flags.lua | 6 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_clang_scan_deps.lua | 55 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/gcc/has_flags.lua | 5 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/nvcc/has_flags.lua | 6 |
4 files changed, 64 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/find_clang_scan_deps.lua b/xmake/modules/detect/tools/find_clang_scan_deps.lua new file mode 100644 index 000000000..f4b9cd87b --- /dev/null +++ b/xmake/modules/detect/tools/find_clang_scan_deps.lua @@ -0,0 +1,55 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_clang_scan_deps.lua +-- + +-- imports +import("lib.detect.find_program") +import("lib.detect.find_programver") + +-- find clang-scan-deps +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local clang_scan_deps = find_clang_scan_deps() +-- local clang_scan_deps, version = find_clang_scan_deps({program = "clang-scan-deps", version = true}) +-- +-- @endcode +-- +function main(opt) + opt = opt or {} + local program = find_program(opt.program or "clang-scan-deps", opt) + if not program and is_host("macosx") then + local llvm = try {function () return os.iorunv("brew", {"--prefix", "llvm"}) end} + if llvm then + opt.paths = opt.paths or {} + opt.force = true + table.insert(opt.paths, path.join(llvm:trim(), "bin")) + program = find_program(opt.program or "clang-scan-deps", opt) + end + end + local version = nil + if program and opt and opt.version then + version = find_programver(program, opt) + end + return program, version +end 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 |
