diff options
| author | ruki <[email protected]> | 2018-11-14 22:47:31 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-11-14 10:45:07 +0800 |
| commit | 5b853be10785785af89a382f666415e739445e0a (patch) | |
| tree | 70596d9288e3fb2323ff20f42af91bb74040456a | |
| parent | 2f4297339f80b749512f1cb9335abc236dd4c5d4 (diff) | |
improve to detect clang as gcc
| -rw-r--r-- | xmake/core/platform/platform.lua | 3 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_gcc.lua | 17 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_gxx.lua | 13 | ||||
| -rw-r--r-- | xmake/platforms/checker.lua | 3 |
4 files changed, 29 insertions, 7 deletions
diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index b5886dd42..88770c1ce 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -257,6 +257,7 @@ function platform.tool(toolkind) -- attempt to get program from config first local program = config.get(toolkind) + local toolname = config.get("__toolname_" .. toolkind) if program == nil then -- check it first @@ -267,10 +268,10 @@ function platform.tool(toolkind) -- get it again program = config.get(toolkind) + toolname = config.get("__toolname_" .. toolkind) end -- contain toolname? parse it, .e.g '[email protected]' - local toolname = nil if program then local pos = program:find('@', 1, true) if pos then diff --git a/xmake/modules/detect/tools/find_gcc.lua b/xmake/modules/detect/tools/find_gcc.lua index 5daa387a9..b17607e4b 100644 --- a/xmake/modules/detect/tools/find_gcc.lua +++ b/xmake/modules/detect/tools/find_gcc.lua @@ -35,7 +35,7 @@ import("lib.detect.find_programver") -- @code -- -- local gcc = find_gcc() --- local gcc, version = find_gcc({program = "xcrun -sdk macosx gcc", version = true}) +-- local gcc, version, hintname = find_gcc({program = "xcrun -sdk macosx gcc", version = true}) -- -- @endcode -- @@ -47,12 +47,21 @@ function main(opt) -- find program local program = find_program(opt.program or "gcc", opt) - -- find program version + -- find program version local version = nil - if program and opt and opt.version then + if program and opt.version then version = find_programver(program, opt) end + -- is clang or gcc + 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 + end + -- ok? - return program, version, ifelse(os.host() == "macosx", "clang", "gcc") + 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 b67e6168d..9970c8806 100644 --- a/xmake/modules/detect/tools/find_gxx.lua +++ b/xmake/modules/detect/tools/find_gxx.lua @@ -35,7 +35,7 @@ import("lib.detect.find_programver") -- @code -- -- local gxx = find_gxx() --- local gxx, version = find_gxx({program = "xcrun -sdk macosx g++", version = true}) +-- local gxx, version, hintname = find_gxx({program = "xcrun -sdk macosx g++", version = true}) -- -- @endcode -- @@ -53,6 +53,15 @@ function main(opt) version = find_programver(program, opt) end + -- is clang++ or g++ + 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 + end + -- ok? - return program, version + return program, version, (is_clang and "clangxx" or "gxx") end diff --git a/xmake/platforms/checker.lua b/xmake/platforms/checker.lua index ebfa25e48..927590d41 100644 --- a/xmake/platforms/checker.lua +++ b/xmake/platforms/checker.lua @@ -45,16 +45,19 @@ function _toolchain_check(config, toolkind, toolinfo) local cross = toolinfo.cross or "" -- attempt to check it + local toolname = nil if not program then local tool = find_tool(name, {program = cross .. name, pathes = config.get("bin"), check = toolinfo.check}) if tool then program = tool.program + toolname = tool.name end end -- check ok? if program then config.set(toolkind, program) + config.set("__toolname_" .. toolkind, toolname) end -- trace |
