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 windows wasm compilation with packages #5534

Merged
merged 9 commits into from
Aug 29, 2024
38 changes: 23 additions & 15 deletions xmake/modules/package/tools/cmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,14 @@ function _get_mingw32_make(package)
end
end

-- get ninja
function _get_ninja(package)
local ninja = find_tool("ninja")
if ninja then
return ninja.program
end
end

-- https://github.com/xmake-io/xmake-repo/pull/1096
function _fix_cxx_compiler_cmake(package, envs)
local cxx = envs.CMAKE_CXX_COMPILER
Expand Down Expand Up @@ -601,10 +609,17 @@ function _get_configs_for_wasm(package, configs, opt)
local emscripten_cmakefile = find_file("Emscripten.cmake", path.join(emsdk.emscripten, "cmake/Modules/Platform"))
assert(emscripten_cmakefile, "Emscripten.cmake not found!")
table.insert(configs, "-DCMAKE_TOOLCHAIN_FILE=" .. emscripten_cmakefile)
if is_subhost("windows") and opt.cmake_generator ~= "Ninja" then
local mingw_make = _get_mingw32_make(package)
if mingw_make then
table.insert(configs, "-DCMAKE_MAKE_PROGRAM=" .. mingw_make)
if is_subhost("windows") then
if opt.cmake_generator == "Ninja" then
local ninja = _get_ninja(package)
if ninja then
table.insert(configs, "-DCMAKE_MAKE_PROGRAM=" .. ninja)
end
else
local mingw_make = _get_mingw32_make(package)
if mingw_make then
table.insert(configs, "-DCMAKE_MAKE_PROGRAM=" .. mingw_make)
end
end
end
_get_configs_for_generic(package, configs, opt)
Expand Down Expand Up @@ -757,15 +772,8 @@ function _get_configs_for_generator(package, configs, opt)
table.insert(configs, "-G")
table.insert(configs, _get_cmake_generator_for_msvc(package))
elseif package:is_plat("wasm") and is_subhost("windows") then
-- we attempt to use ninja if it exist
-- @see https://github.com/xmake-io/xmake/issues/3771
table.insert(configs, "-G")
if find_tool("ninja") then
table.insert(configs, "Ninja")
opt.cmake_generator = "Ninja"
else
table.insert(configs, "MinGW Makefiles")
end
table.insert(configs, "MinGW Makefiles")
else
table.insert(configs, "-G")
table.insert(configs, "Unix Makefiles")
Expand Down Expand Up @@ -1142,9 +1150,9 @@ 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
local mingw_make = _get_mingw32_make(package)
if not mingw_make and find_tool("ninja") then
elseif is_subhost("windows") and package:is_plat("mingw", "wasm") then
local ninja = _get_ninja(package)
if ninja then
cmake_generator = "Ninja"
end
end
Expand Down
Loading