@@ -400,53 +400,44 @@ end
400
400
401
401
-- get configs for generic
402
402
function _get_configs_for_generic (package , configs , opt )
403
+ local envs = {}
403
404
local cflags = _get_cflags (package , opt )
404
405
if cflags then
405
- table.insert ( configs , " -DCMAKE_C_FLAGS= " .. cflags )
406
+ envs . CMAKE_C_FLAGS = cflags
406
407
end
407
408
local cxxflags = _get_cxxflags (package , opt )
408
409
if cxxflags then
409
- table.insert ( configs , " -DCMAKE_CXX_FLAGS= " .. cxxflags )
410
+ envs . CMAKE_CXX_FLAGS = cxxflags
410
411
end
411
412
local asflags = _get_asflags (package , opt )
412
413
if asflags then
413
- table.insert ( configs , " -DCMAKE_ASM_FLAGS= " .. asflags )
414
+ envs . CMAKE_ASM_FLAGS = asflags
414
415
end
415
416
local ldflags = _get_ldflags (package , opt )
416
417
if ldflags then
417
- table.insert ( configs , " -DCMAKE_EXE_LINKER_FLAGS= " .. ldflags )
418
+ envs . CMAKE_EXE_LINKER_FLAGS = ldflags
418
419
end
419
420
local shflags = _get_shflags (package , opt )
420
421
if shflags then
421
- table.insert ( configs , " -DCMAKE_SHARED_LINKER_FLAGS= " .. shflags )
422
- table.insert ( configs , " -DCMAKE_MODULE_LINKER_FLAGS= " .. shflags )
422
+ envs . CMAKE_SHARED_LINKER_FLAGS = shflags
423
+ envs . CMAKE_MODULE_LINKER_FLAGS = shflags
423
424
end
424
425
if not package :is_plat (" windows" , " mingw" ) and package :config (" pic" ) ~= false then
425
- table.insert ( configs , " -DCMAKE_POSITION_INDEPENDENT_CODE= ON" )
426
+ envs . CMAKE_POSITION_INDEPENDENT_CODE = " ON"
426
427
end
427
428
if not package :use_external_includes () then
428
- table.insert (configs , " -DCMAKE_NO_SYSTEM_FROM_IMPORTED=ON" )
429
- end
430
- local has_already_debugflag = opt ._configs_str and opt ._configs_str :find (" CMAKE_BUILD_TYPE" , 1 , true )
431
- if package :is_debug () then
432
- if not has_already_debugflag then
433
- table.insert (configs , " -DCMAKE_BUILD_TYPE=Debug" )
434
- end
435
- else
436
- if not has_already_debugflag then
437
- table.insert (configs , " -DCMAKE_BUILD_TYPE=Release" )
438
- end
429
+ envs .CMAKE_NO_SYSTEM_FROM_IMPORTED = " ON"
439
430
end
431
+ envs .CMAKE_BUILD_TYPE = package :is_debug () and " Debug" or " Release"
440
432
if package :is_library () then
441
- local has_already_libflag = opt ._configs_str and opt ._configs_str :find (" BUILD_SHARED_LIBS" , 1 , true )
442
- if not has_already_libflag then
443
- table.insert (configs , " -DBUILD_SHARED_LIBS=" .. (package :config (" shared" ) and " ON" or " OFF" ))
444
- end
433
+ envs .BUILD_SHARED_LIBS = package :config (" shared" ) and " ON" or " OFF"
445
434
end
435
+ _insert_configs_from_envs (configs , envs , opt )
446
436
end
447
437
448
438
-- get configs for windows
449
439
function _get_configs_for_windows (package , configs , opt )
440
+ local envs = {}
450
441
local cmake_generator = opt .cmake_generator
451
442
if not cmake_generator or cmake_generator :find (" Visual Studio" , 1 , true ) then
452
443
table.insert (configs , " -A" )
@@ -463,38 +454,35 @@ function _get_configs_for_windows(package, configs, opt)
463
454
end
464
455
local vs_toolset = toolchain_utils .get_vs_toolset_ver (_get_msvc (package ):config (" vs_toolset" ) or config .get (" vs_toolset" ))
465
456
if vs_toolset then
466
- table.insert ( configs , " -DCMAKE_GENERATOR_TOOLSET= " .. vs_toolset )
457
+ envs . CMAKE_GENERATOR_TOOLSET = vs_toolset
467
458
end
468
459
end
469
460
470
461
-- use clang-cl
471
462
if package :has_tool (" cc" , " clang" , " clang_cl" ) then
472
- table.insert ( configs , " -DCMAKE_C_COMPILER= " .. _translate_bin_path (package :build_getenv (" cc" ) ))
463
+ envs . CMAKE_C_COMPILER = _translate_bin_path (package :build_getenv (" cc" ))
473
464
end
474
465
if package :has_tool (" cxx" , " clang" , " clang_cl" ) then
475
- table.insert ( configs , " -DCMAKE_CXX_COMPILER= " .. _translate_bin_path (package :build_getenv (" cxx" ) ))
466
+ envs . CMAKE_CXX_COMPILER = _translate_bin_path (package :build_getenv (" cxx" ))
476
467
end
477
468
478
469
-- we maybe need patch `cmake_policy(SET CMP0091 NEW)` to enable this argument for some packages
479
470
-- @see https://cmake.org/cmake/help/latest/policy/CMP0091.html#policy:CMP0091
480
471
-- https://github.com/xmake-io/xmake-repo/pull/303
481
472
if package :has_runtime (" MT" ) then
482
- table.insert ( configs , " -DCMAKE_MSVC_RUNTIME_LIBRARY= MultiThreaded" )
473
+ envs . CMAKE_MSVC_RUNTIME_LIBRARY = " MultiThreaded"
483
474
elseif package :has_runtime (" MTd" ) then
484
- table.insert ( configs , " -DCMAKE_MSVC_RUNTIME_LIBRARY= MultiThreadedDebug" )
475
+ envs . CMAKE_MSVC_RUNTIME_LIBRARY = " MultiThreadedDebug"
485
476
elseif package :has_runtime (" MD" ) then
486
- table.insert ( configs , " -DCMAKE_MSVC_RUNTIME_LIBRARY= MultiThreadedDLL" )
477
+ envs . CMAKE_MSVC_RUNTIME_LIBRARY = " MultiThreadedDLL"
487
478
elseif package :has_runtime (" MDd" ) then
488
- table.insert ( configs , " -DCMAKE_MSVC_RUNTIME_LIBRARY= MultiThreadedDebugDLL" )
479
+ envs . CMAKE_MSVC_RUNTIME_LIBRARY = " MultiThreadedDebugDLL"
489
480
end
490
481
491
482
local pdb_dir = path .unix (path .join (os .curdir (), " pdb" ))
492
- if not opt ._configs_str :find (" CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY" , 1 , true ) then
493
- table.insert (configs , " -DCMAKE_COMPILE_PDB_OUTPUT_DIRECTORY=" .. pdb_dir )
494
- end
495
- if not opt ._configs_str :find (" CMAKE_PDB_OUTPUT_DIRECTORY" , 1 , true ) then
496
- table.insert (configs , " -DCMAKE_PDB_OUTPUT_DIRECTORY=" .. pdb_dir )
497
- end
483
+ envs .CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY = pdb_dir
484
+ envs .CMAKE_PDB_OUTPUT_DIRECTORY = pdb_dir
485
+ _insert_configs_from_envs (configs , envs , opt )
498
486
499
487
if package :is_cross () then
500
488
_get_configs_for_cross (package , configs , opt )
0 commit comments