Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cmake): Set correct c++ compiler and detect ninja for MinGW #5520

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions xmake/modules/package/tools/cmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,15 @@ function _get_cmake_generator(package, opt)
if not cmake_generator then
if package:has_tool("cc", "clang_cl") or package:has_tool("cxx", "clang_cl") then
cmake_generator = "Ninja"
elseif is_subhost("windows") and package:is_plat("mingw") then
-- When we are using a standalone clang/gcc toolchain without mingw, try to detect ninja automatically.
-- see:https://github.com/xmake-io/xmake/issues/5518
local mingw = package:build_getenv("mingw") or package:build_getenv("sdk") or ""
mingw = find_tool(mingw, {paths = mingw})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

怪怪的,目前 xmake f -p mingw 的约定就是强制使用 mingw 工具链,如果 mingw 都找不到,应该直接 break 报错 mingw not found 。。压根到不了这。。

而且 find_tool 里串传 mingw path 。。怎么能 find 的到

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

主要是Windows用clang-cl和msvc,而cross又有好多包不支持,改包描述也是个大工程,就用了mingw平台

find_tool写错了,应该是mingw/bin下找mingw32-make.exe

if not mingw then
assert(find_tool("ninja"), "No mingw or ninja found!")
cmake_generator = "Ninja"
end
end
end
local cmake_generator_env = os.getenv("CMAKE_GENERATOR")
Expand Down
6 changes: 4 additions & 2 deletions xmake/toolchains/clang/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ toolchain("clang" .. suffix)
set_description("A C language family frontend for LLVM" .. (version and (" (" .. version .. ")") or ""))
set_runtimes("c++_static", "c++_shared", "stdc++_static", "stdc++_shared")

-- set clang++ first, then package:build_getenv("cxx") is always clang++ instead of clang
-- see:https://github.com/xmake-io/xmake/issues/5518
set_toolset("cc", "clang" .. suffix)
set_toolset("cxx", "clang" .. suffix, "clang++" .. suffix)
set_toolset("cxx", "clang++" .. suffix, "clang" .. suffix)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要改这。影响太大。。

set_toolset("ld", "clang++" .. suffix, "clang" .. suffix)
set_toolset("sh", "clang++" .. suffix, "clang" .. suffix)
set_toolset("ar", "ar", "llvm-ar")
set_toolset("strip", "strip", "llvm-strip")
set_toolset("ranlib", "ranlib", "llvm-ranlib")
set_toolset("objcopy", "objcopy", "llvm-objcopy")
set_toolset("mm", "clang" .. suffix)
set_toolset("mxx", "clang" .. suffix, "clang++" .. suffix)
set_toolset("mxx", "clang++" .. suffix, "clang" .. suffix)
set_toolset("as", "clang" .. suffix)
set_toolset("mrc", "llvm-rc")

Expand Down
6 changes: 4 additions & 2 deletions xmake/toolchains/gcc/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ toolchain("gcc" .. suffix)
set_description("GNU Compiler Collection" .. (version and (" (" .. version .. ")") or ""))
set_runtimes("stdc++_static", "stdc++_shared")

-- set g++ first, then package:build_getenv("cxx") is always g++ instead of gcc
-- see:https://github.com/xmake-io/xmake/issues/5518
set_toolset("cc", "gcc" .. suffix)
set_toolset("cxx", "gcc" .. suffix, "g++" .. suffix)
set_toolset("cxx", "g++" .. suffix, "gcc" .. suffix)
set_toolset("ld", "g++" .. suffix, "gcc" .. suffix)
set_toolset("sh", "g++" .. suffix, "gcc" .. suffix)
set_toolset("ar", "ar")
set_toolset("strip", "strip")
set_toolset("objcopy", "objcopy")
set_toolset("ranlib", "ranlib")
set_toolset("mm", "gcc" .. suffix)
set_toolset("mxx", "gcc" .. suffix, "g++" .. suffix)
set_toolset("mxx", "g++" .. suffix, "gcc" .. suffix)
set_toolset("as", "gcc" .. suffix)

on_check(function (toolchain)
Expand Down
Loading