diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index 99dfe0436a3..7d5550390e0 100644 --- a/xmake/modules/package/tools/cmake.lua +++ b/xmake/modules/package/tools/cmake.lua @@ -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 @@ -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) @@ -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") @@ -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