Skip to content

Commit 9e4f3d7

Browse files
committed
try use ninja for mingw
1 parent 3fbd469 commit 9e4f3d7

File tree

1 file changed

+39
-44
lines changed

1 file changed

+39
-44
lines changed

xmake/modules/package/tools/cmake.lua

+39-44
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,33 @@ function _get_cmake_system_processor(package)
355355
return package:arch()
356356
end
357357

358+
-- get mingw32 make
359+
function _get_mingw32_make(package)
360+
local mingw = assert(package:build_getenv("mingw") or package:build_getenv("sdk"), "mingw not found!")
361+
return _translate_bin_path(path.join(mingw, "bin", "mingw32-make.exe"))
362+
end
363+
364+
-- https://github.com/xmake-io/xmake-repo/pull/1096
365+
function _fix_cxx_compiler_cmake(package, envs)
366+
local cxx = envs.CMAKE_CXX_COMPILER
367+
if cxx and package:has_tool("cxx", "clang", "gcc") then
368+
local dir = path.directory(cxx)
369+
local name = path.filename(cxx)
370+
name = name:gsub("clang$", "clang++")
371+
name = name:gsub("clang%-", "clang++-")
372+
name = name:gsub("clang%.", "clang++.")
373+
name = name:gsub("gcc$", "g++")
374+
name = name:gsub("gcc%-", "g++-")
375+
name = name:gsub("gcc%.", "g++.")
376+
if dir and dir ~= "." then
377+
cxx = path.join(dir, name)
378+
else
379+
cxx = name
380+
end
381+
envs.CMAKE_CXX_COMPILER = _translate_bin_path(cxx)
382+
end
383+
end
384+
358385
-- insert configs from envs
359386
function _insert_configs_from_envs(configs, envs, opt)
360387
opt = opt or {}
@@ -552,12 +579,12 @@ function _get_configs_for_mingw(package, configs, opt)
552579
envs.HAVE_FLAG_SEARCH_PATHS_FIRST = "0"
553580
-- CMAKE_MAKE_PROGRAM may be required for some CMakeLists.txt (libcurl)
554581
if is_subhost("windows") and opt.cmake_generator ~= "Ninja" then
555-
local mingw = assert(package:build_getenv("mingw") or package:build_getenv("sdk"), "mingw not found!")
556-
envs.CMAKE_MAKE_PROGRAM = _translate_bin_path(path.join(mingw, "bin", "mingw32-make.exe"))
582+
envs.CMAKE_MAKE_PROGRAM = _get_mingw32_make(package)
557583
end
558584
if opt.cmake_generator == "Ninja" then
559585
envs.CMAKE_MAKE_PROGRAM = "ninja"
560586
end
587+
_fix_cxx_compiler_cmake(package, envs)
561588
_insert_configs_from_envs(configs, envs, opt)
562589
end
563590

@@ -570,8 +597,7 @@ function _get_configs_for_wasm(package, configs, opt)
570597
assert(emscripten_cmakefile, "Emscripten.cmake not found!")
571598
table.insert(configs, "-DCMAKE_TOOLCHAIN_FILE=" .. emscripten_cmakefile)
572599
if is_subhost("windows") and opt.cmake_generator ~= "Ninja" then
573-
local mingw = assert(package:build_getenv("mingw") or package:build_getenv("sdk"), "mingw32-make not found!")
574-
table.insert(configs, "-DCMAKE_MAKE_PROGRAM=" .. _translate_paths(path.join(mingw, "bin", "mingw32-make.exe")))
600+
table.insert(configs, "-DCMAKE_MAKE_PROGRAM=" .. _get_mingw32_make(package))
575601
end
576602
_get_configs_for_generic(package, configs, opt)
577603
end
@@ -586,24 +612,7 @@ function _get_configs_for_cross(package, configs, opt)
586612
envs.CMAKE_CXX_COMPILER = _translate_bin_path(package:build_getenv("cxx"))
587613
envs.CMAKE_ASM_COMPILER = _translate_bin_path(package:build_getenv("as"))
588614
envs.CMAKE_AR = _translate_bin_path(package:build_getenv("ar"))
589-
-- https://github.com/xmake-io/xmake-repo/pull/1096
590-
local cxx = envs.CMAKE_CXX_COMPILER
591-
if cxx and package:has_tool("cxx", "clang", "gcc") then
592-
local dir = path.directory(cxx)
593-
local name = path.filename(cxx)
594-
name = name:gsub("clang$", "clang++")
595-
name = name:gsub("clang%-", "clang++-") -- clang-xx
596-
name = name:gsub("clang%.", "clang++.") -- clang.exe
597-
name = name:gsub("gcc$", "g++")
598-
name = name:gsub("gcc%-", "g++-")
599-
name = name:gsub("gcc%.", "g++.")
600-
if dir and dir ~= "." then
601-
cxx = path.join(dir, name)
602-
else
603-
cxx = name
604-
end
605-
envs.CMAKE_CXX_COMPILER = _translate_bin_path(cxx)
606-
end
615+
_fix_cxx_compiler_cmake(package, envs)
607616
-- @note The link command line is set in Modules/CMake{C,CXX,Fortran}Information.cmake and defaults to using the compiler, not CMAKE_LINKER,
608617
-- so we need to set CMAKE_CXX_LINK_EXECUTABLE to use CMAKE_LINKER as linker.
609618
--
@@ -662,24 +671,7 @@ function _get_configs_for_host_toolchain(package, configs, opt)
662671
envs.CMAKE_ASM_COMPILER = _translate_bin_path(package:build_getenv("as"))
663672
envs.CMAKE_RC_COMPILER = _translate_bin_path(package:build_getenv("mrc"))
664673
envs.CMAKE_AR = _translate_bin_path(package:build_getenv("ar"))
665-
-- https://github.com/xmake-io/xmake-repo/pull/1096
666-
local cxx = envs.CMAKE_CXX_COMPILER
667-
if cxx and package:has_tool("cxx", "clang", "gcc") then
668-
local dir = path.directory(cxx)
669-
local name = path.filename(cxx)
670-
name = name:gsub("clang$", "clang++")
671-
name = name:gsub("clang%-", "clang++-")
672-
name = name:gsub("clang%.", "clang++.")
673-
name = name:gsub("gcc$", "g++")
674-
name = name:gsub("gcc%-", "g++-")
675-
name = name:gsub("gcc%.", "g++.")
676-
if dir and dir ~= "." then
677-
cxx = path.join(dir, name)
678-
else
679-
cxx = name
680-
end
681-
envs.CMAKE_CXX_COMPILER = _translate_bin_path(cxx)
682-
end
674+
_fix_cxx_compiler_cmake(package, envs)
683675
-- @note The link command line is set in Modules/CMake{C,CXX,Fortran}Information.cmake and defaults to using the compiler, not CMAKE_LINKER,
684676
-- so we need set CMAKE_CXX_LINK_EXECUTABLE to use CMAKE_LINKER as linker.
685677
--
@@ -1012,8 +1004,7 @@ function _build_for_make(package, configs, opt)
10121004
if is_host("bsd") then
10131005
os.vrunv("gmake", argv)
10141006
elseif is_subhost("windows") and package:is_plat("mingw") then
1015-
local mingw = assert(package:build_getenv("mingw") or package:build_getenv("sdk"), "mingw not found!")
1016-
local mingw_make = path.join(mingw, "bin", "mingw32-make.exe")
1007+
local mingw_make = _get_mingw32_make(package)
10171008
os.vrunv(mingw_make, argv)
10181009
elseif package:is_plat("android") and is_host("windows") then
10191010
local make
@@ -1088,8 +1079,7 @@ function _install_for_make(package, configs, opt)
10881079
os.vrunv("gmake", argv)
10891080
os.vrunv("gmake", {"install"})
10901081
elseif is_subhost("windows") and package:is_plat("mingw", "wasm") then
1091-
local mingw = assert(package:build_getenv("mingw") or package:build_getenv("sdk"), "mingw not found!")
1092-
local mingw_make = path.join(mingw, "bin", "mingw32-make.exe")
1082+
local mingw_make = _get_mingw32_make(package)
10931083
os.vrunv(mingw_make, argv)
10941084
os.vrunv(mingw_make, {"install"})
10951085
elseif package:is_plat("android") and is_host("windows") then
@@ -1142,6 +1132,11 @@ function _get_cmake_generator(package, opt)
11421132
if not cmake_generator then
11431133
if package:has_tool("cc", "clang_cl") or package:has_tool("cxx", "clang_cl") then
11441134
cmake_generator = "Ninja"
1135+
elseif is_subhost("windows") and package:is_plat("mingw") then
1136+
local mingw_make = _get_mingw32_make(package)
1137+
if not os.isfile(mingw_make) and find_tool("ninja") then
1138+
cmake_generator = "Ninja"
1139+
end
11451140
end
11461141
end
11471142
local cmake_generator_env = os.getenv("CMAKE_GENERATOR")

0 commit comments

Comments
 (0)