Skip to content

Commit 7336c8a

Browse files
authored
Merge pull request #5534 from Chi-EEE/windows-wasm
fix windows wasm compilation with packages
2 parents d2476ab + e432b35 commit 7336c8a

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

xmake/modules/package/tools/cmake.lua

+23-15
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,14 @@ function _get_mingw32_make(package)
366366
end
367367
end
368368

369+
-- get ninja
370+
function _get_ninja(package)
371+
local ninja = find_tool("ninja")
372+
if ninja then
373+
return ninja.program
374+
end
375+
end
376+
369377
-- https://github.com/xmake-io/xmake-repo/pull/1096
370378
function _fix_cxx_compiler_cmake(package, envs)
371379
local cxx = envs.CMAKE_CXX_COMPILER
@@ -601,10 +609,17 @@ function _get_configs_for_wasm(package, configs, opt)
601609
local emscripten_cmakefile = find_file("Emscripten.cmake", path.join(emsdk.emscripten, "cmake/Modules/Platform"))
602610
assert(emscripten_cmakefile, "Emscripten.cmake not found!")
603611
table.insert(configs, "-DCMAKE_TOOLCHAIN_FILE=" .. emscripten_cmakefile)
604-
if is_subhost("windows") and opt.cmake_generator ~= "Ninja" then
605-
local mingw_make = _get_mingw32_make(package)
606-
if mingw_make then
607-
table.insert(configs, "-DCMAKE_MAKE_PROGRAM=" .. mingw_make)
612+
if is_subhost("windows") then
613+
if opt.cmake_generator == "Ninja" then
614+
local ninja = _get_ninja(package)
615+
if ninja then
616+
table.insert(configs, "-DCMAKE_MAKE_PROGRAM=" .. ninja)
617+
end
618+
else
619+
local mingw_make = _get_mingw32_make(package)
620+
if mingw_make then
621+
table.insert(configs, "-DCMAKE_MAKE_PROGRAM=" .. mingw_make)
622+
end
608623
end
609624
end
610625
_get_configs_for_generic(package, configs, opt)
@@ -757,15 +772,8 @@ function _get_configs_for_generator(package, configs, opt)
757772
table.insert(configs, "-G")
758773
table.insert(configs, _get_cmake_generator_for_msvc(package))
759774
elseif package:is_plat("wasm") and is_subhost("windows") then
760-
-- we attempt to use ninja if it exist
761-
-- @see https://github.com/xmake-io/xmake/issues/3771
762775
table.insert(configs, "-G")
763-
if find_tool("ninja") then
764-
table.insert(configs, "Ninja")
765-
opt.cmake_generator = "Ninja"
766-
else
767-
table.insert(configs, "MinGW Makefiles")
768-
end
776+
table.insert(configs, "MinGW Makefiles")
769777
else
770778
table.insert(configs, "-G")
771779
table.insert(configs, "Unix Makefiles")
@@ -1142,9 +1150,9 @@ function _get_cmake_generator(package, opt)
11421150
if not cmake_generator then
11431151
if package:has_tool("cc", "clang_cl") or package:has_tool("cxx", "clang_cl") then
11441152
cmake_generator = "Ninja"
1145-
elseif is_subhost("windows") and package:is_plat("mingw") then
1146-
local mingw_make = _get_mingw32_make(package)
1147-
if not mingw_make and find_tool("ninja") then
1153+
elseif is_subhost("windows") and package:is_plat("mingw", "wasm") then
1154+
local ninja = _get_ninja(package)
1155+
if ninja then
11481156
cmake_generator = "Ninja"
11491157
end
11501158
end

0 commit comments

Comments
 (0)