@@ -443,6 +443,59 @@ impl Config {
443
443
if !self . defined ( "CMAKE_TOOLCHAIN_FILE" ) {
444
444
if let Some ( s) = self . getenv_target_os ( "CMAKE_TOOLCHAIN_FILE" ) {
445
445
self . define ( "CMAKE_TOOLCHAIN_FILE" , s) ;
446
+ } else {
447
+ if target. contains ( "redox" ) {
448
+ if !self . defined ( "CMAKE_SYSTEM_NAME" ) {
449
+ self . define ( "CMAKE_SYSTEM_NAME" , "Generic" ) ;
450
+ }
451
+ } else if target. contains ( "solaris" ) {
452
+ if !self . defined ( "CMAKE_SYSTEM_NAME" ) {
453
+ self . define ( "CMAKE_SYSTEM_NAME" , "SunOS" ) ;
454
+ }
455
+ } else if target != host && !self . defined ( "CMAKE_SYSTEM_NAME" ) {
456
+ // Set CMAKE_SYSTEM_NAME and CMAKE_SYSTEM_PROCESSOR when cross compiling
457
+ let os = getenv_unwrap ( "CARGO_CFG_TARGET_OS" ) ;
458
+ let arch = getenv_unwrap ( "CARGO_CFG_TARGET_ARCH" ) ;
459
+ // CMAKE_SYSTEM_NAME list
460
+ // https://gitlab.kitware.com/cmake/cmake/-/issues/21489#note_1077167
461
+ //
462
+ // CMAKE_SYSTEM_PROCESSOR
463
+ // some of the values come from https://en.wikipedia.org/wiki/Uname
464
+ let ( system_name, system_processor) = match ( os. as_str ( ) , arch. as_str ( ) ) {
465
+ ( "android" , arch) => ( "Android" , arch) ,
466
+ ( "dragonfly" , arch) => ( "DragonFly" , arch) ,
467
+ ( "macos" , "x86_64" ) => ( "Darwin" , "x86_64" ) ,
468
+ ( "macos" , "aarch64" ) => ( "Darwin" , "arm64" ) ,
469
+ ( "freebsd" , "x86_64" ) => ( "FreeBSD" , "amd64" ) ,
470
+ ( "freebsd" , arch) => ( "FreeBSD" , arch) ,
471
+ ( "fuchsia" , arch) => ( "Fuchsia" , arch) ,
472
+ ( "haiku" , arch) => ( "Haiku" , arch) ,
473
+ ( "ios" , "aarch64" ) => ( "iOS" , "arm64" ) ,
474
+ ( "ios" , arch) => ( "iOS" , arch) ,
475
+ ( "linux" , arch) => {
476
+ let name = "Linux" ;
477
+ match arch {
478
+ "powerpc" => ( name, "ppc" ) ,
479
+ "powerpc64" => ( name, "ppc64" ) ,
480
+ "powerpc64le" => ( name, "ppc64le" ) ,
481
+ _ => ( name, arch) ,
482
+ }
483
+ }
484
+ ( "netbsd" , arch) => ( "NetBSD" , arch) ,
485
+ ( "openbsd" , "x86_64" ) => ( "OpenBSD" , "amd64" ) ,
486
+ ( "openbsd" , arch) => ( "OpenBSD" , arch) ,
487
+ ( "solaris" , arch) => ( "SunOS" , arch) ,
488
+ ( "tvos" , arch) => ( "tvOS" , arch) ,
489
+ ( "watchos" , arch) => ( "watchOS" , arch) ,
490
+ ( "windows" , "x86_64" ) => ( "Windows" , "AMD64" ) ,
491
+ ( "windows" , "i686" ) => ( "Windows" , "X86" ) ,
492
+ ( "windows" , "aarch64" ) => ( "Windows" , "ARM64" ) ,
493
+ // Others
494
+ ( os, arch) => ( os, arch) ,
495
+ } ;
496
+ self . define ( "CMAKE_SYSTEM_NAME" , system_name) ;
497
+ self . define ( "CMAKE_SYSTEM_PROCESSOR" , system_processor) ;
498
+ }
446
499
}
447
500
}
448
501
@@ -561,9 +614,6 @@ impl Config {
561
614
// variables which will hopefully get things to succeed. Some
562
615
// systems may need the `windres` or `dlltool` variables set, so
563
616
// set them if possible.
564
- if !self . defined ( "CMAKE_SYSTEM_NAME" ) {
565
- cmd. arg ( "-DCMAKE_SYSTEM_NAME=Windows" ) ;
566
- }
567
617
if !self . defined ( "CMAKE_RC_COMPILER" ) {
568
618
let exe = find_exe ( c_compiler. path ( ) ) ;
569
619
if let Some ( name) = exe. file_name ( ) . unwrap ( ) . to_str ( ) {
@@ -614,14 +664,6 @@ impl Config {
614
664
panic ! ( "unsupported msvc target: {}" , target) ;
615
665
}
616
666
}
617
- } else if target. contains ( "redox" ) {
618
- if !self . defined ( "CMAKE_SYSTEM_NAME" ) {
619
- cmd. arg ( "-DCMAKE_SYSTEM_NAME=Generic" ) ;
620
- }
621
- } else if target. contains ( "solaris" ) {
622
- if !self . defined ( "CMAKE_SYSTEM_NAME" ) {
623
- cmd. arg ( "-DCMAKE_SYSTEM_NAME=SunOS" ) ;
624
- }
625
667
} else if target. contains ( "apple-ios" ) || target. contains ( "apple-tvos" ) {
626
668
// These two flags prevent CMake from adding an OSX sysroot, which messes up compilation.
627
669
if !self . defined ( "CMAKE_OSX_SYSROOT" ) && !self . defined ( "CMAKE_OSX_DEPLOYMENT_TARGET" ) {
0 commit comments