@@ -355,6 +355,38 @@ function _get_cmake_system_processor(package)
355
355
return package :arch ()
356
356
end
357
357
358
+ -- get mingw32 make
359
+ function _get_mingw32_make (package )
360
+ local mingw = package :build_getenv (" mingw" ) or package :build_getenv (" sdk" )
361
+ if mingw then
362
+ local mingw_make = _translate_bin_path (path .join (mingw , " bin" , " mingw32-make.exe" ))
363
+ if os .isfile (mingw_make ) then
364
+ return mingw_make
365
+ end
366
+ end
367
+ end
368
+
369
+ -- https://github.com/xmake-io/xmake-repo/pull/1096
370
+ function _fix_cxx_compiler_cmake (package , envs )
371
+ local cxx = envs .CMAKE_CXX_COMPILER
372
+ if cxx and package :has_tool (" cxx" , " clang" , " gcc" ) then
373
+ local dir = path .directory (cxx )
374
+ local name = path .filename (cxx )
375
+ name = name :gsub (" clang$" , " clang++" )
376
+ name = name :gsub (" clang%-" , " clang++-" )
377
+ name = name :gsub (" clang%." , " clang++." )
378
+ name = name :gsub (" gcc$" , " g++" )
379
+ name = name :gsub (" gcc%-" , " g++-" )
380
+ name = name :gsub (" gcc%." , " g++." )
381
+ if dir and dir ~= " ." then
382
+ cxx = path .join (dir , name )
383
+ else
384
+ cxx = name
385
+ end
386
+ envs .CMAKE_CXX_COMPILER = _translate_bin_path (cxx )
387
+ end
388
+ end
389
+
358
390
-- insert configs from envs
359
391
function _insert_configs_from_envs (configs , envs , opt )
360
392
opt = opt or {}
@@ -552,12 +584,12 @@ function _get_configs_for_mingw(package, configs, opt)
552
584
envs .HAVE_FLAG_SEARCH_PATHS_FIRST = " 0"
553
585
-- CMAKE_MAKE_PROGRAM may be required for some CMakeLists.txt (libcurl)
554
586
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" ))
587
+ envs .CMAKE_MAKE_PROGRAM = _get_mingw32_make (package )
557
588
end
558
589
if opt .cmake_generator == " Ninja" then
559
590
envs .CMAKE_MAKE_PROGRAM = " ninja"
560
591
end
592
+ _fix_cxx_compiler_cmake (package , envs )
561
593
_insert_configs_from_envs (configs , envs , opt )
562
594
end
563
595
@@ -570,8 +602,10 @@ function _get_configs_for_wasm(package, configs, opt)
570
602
assert (emscripten_cmakefile , " Emscripten.cmake not found!" )
571
603
table.insert (configs , " -DCMAKE_TOOLCHAIN_FILE=" .. emscripten_cmakefile )
572
604
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" )))
605
+ local mingw_make = _get_mingw32_make (package )
606
+ if mingw_make then
607
+ table.insert (configs , " -DCMAKE_MAKE_PROGRAM=" .. mingw_make )
608
+ end
575
609
end
576
610
_get_configs_for_generic (package , configs , opt )
577
611
end
@@ -586,24 +620,7 @@ function _get_configs_for_cross(package, configs, opt)
586
620
envs .CMAKE_CXX_COMPILER = _translate_bin_path (package :build_getenv (" cxx" ))
587
621
envs .CMAKE_ASM_COMPILER = _translate_bin_path (package :build_getenv (" as" ))
588
622
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
623
+ _fix_cxx_compiler_cmake (package , envs )
607
624
-- @note The link command line is set in Modules/CMake{C,CXX,Fortran}Information.cmake and defaults to using the compiler, not CMAKE_LINKER,
608
625
-- so we need to set CMAKE_CXX_LINK_EXECUTABLE to use CMAKE_LINKER as linker.
609
626
--
@@ -662,24 +679,7 @@ function _get_configs_for_host_toolchain(package, configs, opt)
662
679
envs .CMAKE_ASM_COMPILER = _translate_bin_path (package :build_getenv (" as" ))
663
680
envs .CMAKE_RC_COMPILER = _translate_bin_path (package :build_getenv (" mrc" ))
664
681
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
682
+ _fix_cxx_compiler_cmake (package , envs )
683
683
-- @note The link command line is set in Modules/CMake{C,CXX,Fortran}Information.cmake and defaults to using the compiler, not CMAKE_LINKER,
684
684
-- so we need set CMAKE_CXX_LINK_EXECUTABLE to use CMAKE_LINKER as linker.
685
685
--
@@ -1013,8 +1013,7 @@ function _build_for_make(package, configs, opt)
1013
1013
if is_host (" bsd" ) then
1014
1014
os .vrunv (" gmake" , argv )
1015
1015
elseif is_subhost (" windows" ) and package :is_plat (" mingw" ) then
1016
- local mingw = assert (package :build_getenv (" mingw" ) or package :build_getenv (" sdk" ), " mingw not found!" )
1017
- local mingw_make = path .join (mingw , " bin" , " mingw32-make.exe" )
1016
+ local mingw_make = assert (_get_mingw32_make (package ), " mingw32-make.exe not found!" )
1018
1017
os .vrunv (mingw_make , argv )
1019
1018
elseif package :is_plat (" android" ) and is_host (" windows" ) then
1020
1019
local make
@@ -1090,8 +1089,7 @@ function _install_for_make(package, configs, opt)
1090
1089
os .vrunv (" gmake" , argv )
1091
1090
os .vrunv (" gmake" , {" install" })
1092
1091
elseif is_subhost (" windows" ) and package :is_plat (" mingw" , " wasm" ) then
1093
- local mingw = assert (package :build_getenv (" mingw" ) or package :build_getenv (" sdk" ), " mingw not found!" )
1094
- local mingw_make = path .join (mingw , " bin" , " mingw32-make.exe" )
1092
+ local mingw_make = assert (_get_mingw32_make (package ), " mingw32-make.exe not found!" )
1095
1093
os .vrunv (mingw_make , argv )
1096
1094
os .vrunv (mingw_make , {" install" })
1097
1095
elseif package :is_plat (" android" ) and is_host (" windows" ) then
@@ -1144,6 +1142,11 @@ function _get_cmake_generator(package, opt)
1144
1142
if not cmake_generator then
1145
1143
if package :has_tool (" cc" , " clang_cl" ) or package :has_tool (" cxx" , " clang_cl" ) then
1146
1144
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
1148
+ cmake_generator = " Ninja"
1149
+ end
1147
1150
end
1148
1151
end
1149
1152
local cmake_generator_env = os.getenv (" CMAKE_GENERATOR" )
0 commit comments