summaryrefslogtreecommitdiff
path: root/xmake/modules
diff options
context:
space:
mode:
authorruki <[email protected]>2025-09-06 00:42:41 +0800
committerruki <[email protected]>2025-09-06 00:42:41 +0800
commit2119efbb9b5da3cca88840d1f8148c14284b611b (patch)
treee4e029408ee2781647b134122df068eb94f61fd1 /xmake/modules
parent9f6d91af31ffc4bbbc0d04533786a0954afee2bf (diff)
fix find gcc/gxx cache #6767
Diffstat (limited to 'xmake/modules')
-rw-r--r--xmake/modules/detect/tools/find_cc.lua13
-rw-r--r--xmake/modules/detect/tools/find_clangxx.lua8
-rw-r--r--xmake/modules/detect/tools/find_cxx.lua13
-rw-r--r--xmake/modules/detect/tools/find_gcc.lua25
-rw-r--r--xmake/modules/detect/tools/find_gxx.lua8
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