diff options
| author | ruki <[email protected]> | 2025-09-06 16:12:17 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-09-06 16:12:17 +0800 |
| commit | 34e28c383b48d1c4c0df70a25500fa07ea70dc99 (patch) | |
| tree | ceef4bdc8089a530d98ef99b5ebfcc4f2ee99c93 | |
| parent | 31d2273f44022b19870f2a0f05f644ffd56bb6b5 (diff) | |
| parent | 2119efbb9b5da3cca88840d1f8148c14284b611b (diff) | |
Merge pull request #6771 from xmake-io/clang
fix find gcc/gxx cache #6767
| -rw-r--r-- | xmake/modules/detect/tools/find_cc.lua | 13 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_clangxx.lua | 8 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_cxx.lua | 13 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_gcc.lua | 25 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_gxx.lua | 8 |
5 files changed, 25 insertions, 42 deletions
diff --git a/xmake/modules/detect/tools/find_cc.lua b/xmake/modules/detect/tools/find_cc.lua index ff58c16d3..6ad0f5bf3 100644 --- a/xmake/modules/detect/tools/find_cc.lua +++ b/xmake/modules/detect/tools/find_cc.lua @@ -21,6 +21,7 @@ -- imports import("lib.detect.find_program") import("lib.detect.find_programver") +import("detect.tools.find_gcc") -- find c++ -- @@ -35,15 +36,10 @@ import("lib.detect.find_programver") -- @endcode -- function main(opt) - - -- init options opt = opt or {} - -- find program - local program = find_program(opt.program or "cc", opt) - - -- find program version local version = nil + local program = find_program(opt.program or "cc", opt) if program and opt and opt.version then version = find_programver(program, opt) end @@ -51,10 +47,7 @@ function main(opt) -- is clang++ or c++ local is_clang = false if program then - local versioninfo = os.iorunv(program, {"--version"}) - if versioninfo and versioninfo:find("clang", 1, true) then - is_clang = true - end + is_clang = find_gcc.check_clang(program, opt) end return program, version, (is_clang and "clang" or "cc") end diff --git a/xmake/modules/detect/tools/find_clangxx.lua b/xmake/modules/detect/tools/find_clangxx.lua index 2edec2ca8..c6dba4d6a 100644 --- a/xmake/modules/detect/tools/find_clangxx.lua +++ b/xmake/modules/detect/tools/find_clangxx.lua @@ -36,19 +36,11 @@ import("lib.detect.find_programver") -- @endcode -- function main(opt) - - -- init options opt = opt or {} - - -- find program local program = find_program(opt.program or "clang++", opt) - - -- find program version local version = nil if program and opt and opt.version then version = find_programver(program, opt) end - - -- ok? return program, version end diff --git a/xmake/modules/detect/tools/find_cxx.lua b/xmake/modules/detect/tools/find_cxx.lua index 3d871e10c..26fc8a679 100644 --- a/xmake/modules/detect/tools/find_cxx.lua +++ b/xmake/modules/detect/tools/find_cxx.lua @@ -21,6 +21,7 @@ -- imports import("lib.detect.find_program") import("lib.detect.find_programver") +import("detect.tools.find_gcc") -- find c++ -- @@ -36,15 +37,10 @@ import("lib.detect.find_programver") -- @endcode -- function main(opt) - - -- init options opt = opt or {} - -- find program - local program = find_program(opt.program or "c++", opt) - - -- find program version local version = nil + local program = find_program(opt.program or "c++", opt) if program and opt and opt.version then version = find_programver(program, opt) end @@ -52,10 +48,7 @@ function main(opt) -- is clang++ or c++ local is_clang = false if program then - local versioninfo = os.iorunv(program, {"--version"}) - if versioninfo and versioninfo:find("clang", 1, true) then - is_clang = true - end + is_clang = find_gcc.check_clang(program, opt) end return program, version, (is_clang and "clangxx" or "cxx") end diff --git a/xmake/modules/detect/tools/find_gcc.lua b/xmake/modules/detect/tools/find_gcc.lua index 3ba82baff..d63c5d1b6 100644 --- a/xmake/modules/detect/tools/find_gcc.lua +++ b/xmake/modules/detect/tools/find_gcc.lua @@ -23,6 +23,21 @@ import("lib.detect.find_program") import("lib.detect.find_programver") import("core.cache.detectcache") +-- detect whether the current gcc compiler is clang +function check_clang(program, opt) + local is_clang = false + local cachekey = "find_gcc_versioninfo_" .. program + local versioninfo = detectcache:get(cachekey) + if versioninfo == nil then + versioninfo = os.iorunv(program, {"--version"}, {envs = opt.envs}) + detectcache:set(cachekey, versioninfo) + end + if versioninfo and versioninfo:find("clang", 1, true) then + is_clang = true + end + return is_clang +end + -- find gcc -- -- @param opt the argument options, e.g. {version = true} @@ -46,15 +61,7 @@ function main(opt) local is_clang = false if program and is_host("macosx") then - local cachekey = "find_gcc_versioninfo_" .. program - local versioninfo = detectcache:get(cachekey) - if versioninfo == nil then - versioninfo = os.iorunv(program, {"--version"}, {envs = opt.envs}) - detectcache:set(cachekey, versioninfo) - end - if versioninfo and versioninfo:find("clang", 1, true) then - is_clang = true - end + is_clang = check_clang(program, opt) end return program, version, (is_clang and "clang" or "gcc") end diff --git a/xmake/modules/detect/tools/find_gxx.lua b/xmake/modules/detect/tools/find_gxx.lua index bb9b089b8..f218dc415 100644 --- a/xmake/modules/detect/tools/find_gxx.lua +++ b/xmake/modules/detect/tools/find_gxx.lua @@ -21,6 +21,7 @@ -- imports import("lib.detect.find_program") import("lib.detect.find_programver") +import("detect.tools.find_gcc") -- find g++ -- @@ -46,11 +47,8 @@ function main(opt) -- is clang++ or g++ local is_clang = false - if program then - local versioninfo = os.iorunv(program, {"--version"}, {envs = opt.envs}) - if versioninfo and versioninfo:find("clang", 1, true) then - is_clang = true - end + if program and is_host("macosx") then + is_clang = find_gcc.check_clang(program, opt) end return program, version, (is_clang and "clangxx" or "gxx") end |
