@@ -355,6 +355,33 @@ 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 = 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
+
358
385
-- insert configs from envs
359
386
function _insert_configs_from_envs (configs , envs , opt )
360
387
opt = opt or {}
@@ -552,12 +579,12 @@ function _get_configs_for_mingw(package, configs, opt)
552
579
envs .HAVE_FLAG_SEARCH_PATHS_FIRST = " 0"
553
580
-- CMAKE_MAKE_PROGRAM may be required for some CMakeLists.txt (libcurl)
554
581
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 )
557
583
end
558
584
if opt .cmake_generator == " Ninja" then
559
585
envs .CMAKE_MAKE_PROGRAM = " ninja"
560
586
end
587
+ _fix_cxx_compiler_cmake (package , envs )
561
588
_insert_configs_from_envs (configs , envs , opt )
562
589
end
563
590
@@ -570,8 +597,7 @@ function _get_configs_for_wasm(package, configs, opt)
570
597
assert (emscripten_cmakefile , " Emscripten.cmake not found!" )
571
598
table.insert (configs , " -DCMAKE_TOOLCHAIN_FILE=" .. emscripten_cmakefile )
572
599
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 ))
575
601
end
576
602
_get_configs_for_generic (package , configs , opt )
577
603
end
@@ -586,24 +612,7 @@ function _get_configs_for_cross(package, configs, opt)
586
612
envs .CMAKE_CXX_COMPILER = _translate_bin_path (package :build_getenv (" cxx" ))
587
613
envs .CMAKE_ASM_COMPILER = _translate_bin_path (package :build_getenv (" as" ))
588
614
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 )
607
616
-- @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
617
-- so we need to set CMAKE_CXX_LINK_EXECUTABLE to use CMAKE_LINKER as linker.
609
618
--
@@ -662,24 +671,7 @@ function _get_configs_for_host_toolchain(package, configs, opt)
662
671
envs .CMAKE_ASM_COMPILER = _translate_bin_path (package :build_getenv (" as" ))
663
672
envs .CMAKE_RC_COMPILER = _translate_bin_path (package :build_getenv (" mrc" ))
664
673
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 )
683
675
-- @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
676
-- so we need set CMAKE_CXX_LINK_EXECUTABLE to use CMAKE_LINKER as linker.
685
677
--
@@ -1012,8 +1004,7 @@ function _build_for_make(package, configs, opt)
1012
1004
if is_host (" bsd" ) then
1013
1005
os .vrunv (" gmake" , argv )
1014
1006
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 )
1017
1008
os .vrunv (mingw_make , argv )
1018
1009
elseif package :is_plat (" android" ) and is_host (" windows" ) then
1019
1010
local make
@@ -1088,8 +1079,7 @@ function _install_for_make(package, configs, opt)
1088
1079
os .vrunv (" gmake" , argv )
1089
1080
os .vrunv (" gmake" , {" install" })
1090
1081
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 )
1093
1083
os .vrunv (mingw_make , argv )
1094
1084
os .vrunv (mingw_make , {" install" })
1095
1085
elseif package :is_plat (" android" ) and is_host (" windows" ) then
@@ -1142,6 +1132,11 @@ function _get_cmake_generator(package, opt)
1142
1132
if not cmake_generator then
1143
1133
if package :has_tool (" cc" , " clang_cl" ) or package :has_tool (" cxx" , " clang_cl" ) then
1144
1134
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
1145
1140
end
1146
1141
end
1147
1142
local cmake_generator_env = os.getenv (" CMAKE_GENERATOR" )
0 commit comments