@@ -99,6 +99,8 @@ pub fn build<P: AsRef<Path>>(path: P) -> PathBuf {
99
99
Config :: new ( path. as_ref ( ) ) . build ( )
100
100
}
101
101
102
+ static CMAKE_CACHE_FILE : & str = "CMakeCache.txt" ;
103
+
102
104
impl Config {
103
105
/// Return explicitly set profile or infer `CMAKE_BUILD_TYPE` from Rust's compilation profile.
104
106
///
@@ -454,14 +456,14 @@ impl Config {
454
456
455
457
// Build up the first cmake command to build the build system.
456
458
let executable = env:: var ( "CMAKE" ) . unwrap_or ( "cmake" . to_owned ( ) ) ;
457
- let mut cmd = Command :: new ( & executable) ;
459
+ let mut conf_cmd = Command :: new ( & executable) ;
458
460
459
461
if self . verbose_cmake {
460
- cmd . arg ( "-Wdev" ) ;
461
- cmd . arg ( "--debug-output" ) ;
462
+ conf_cmd . arg ( "-Wdev" ) ;
463
+ conf_cmd . arg ( "--debug-output" ) ;
462
464
}
463
465
464
- cmd . arg ( & self . path ) . current_dir ( & build) ;
466
+ conf_cmd . arg ( & self . path ) . current_dir ( & build) ;
465
467
let mut is_ninja = false ;
466
468
if let Some ( ref generator) = self . generator {
467
469
is_ninja = generator. to_string_lossy ( ) . contains ( "Ninja" ) ;
@@ -494,15 +496,15 @@ impl Config {
494
496
( false , false ) => fail ( "no valid generator found for GNU toolchain; MSYS or MinGW must be installed" )
495
497
} ;
496
498
497
- cmd . arg ( "-G" ) . arg ( generator) ;
499
+ conf_cmd . arg ( "-G" ) . arg ( generator) ;
498
500
}
499
501
} else {
500
502
// If we're cross compiling onto windows, then set some
501
503
// variables which will hopefully get things to succeed. Some
502
504
// systems may need the `windres` or `dlltool` variables set, so
503
505
// set them if possible.
504
506
if !self . defined ( "CMAKE_SYSTEM_NAME" ) {
505
- cmd . arg ( "-DCMAKE_SYSTEM_NAME=Windows" ) ;
507
+ conf_cmd . arg ( "-DCMAKE_SYSTEM_NAME=Windows" ) ;
506
508
}
507
509
if !self . defined ( "CMAKE_RC_COMPILER" ) {
508
510
let exe = find_exe ( c_compiler. path ( ) ) ;
@@ -512,7 +514,7 @@ impl Config {
512
514
if windres. is_file ( ) {
513
515
let mut arg = OsString :: from ( "-DCMAKE_RC_COMPILER=" ) ;
514
516
arg. push ( & windres) ;
515
- cmd . arg ( arg) ;
517
+ conf_cmd . arg ( arg) ;
516
518
}
517
519
}
518
520
}
@@ -523,30 +525,32 @@ impl Config {
523
525
// This also guarantees that NMake generator isn't chosen implicitly.
524
526
let using_nmake_generator;
525
527
if self . generator . is_none ( ) {
526
- cmd. arg ( "-G" ) . arg ( self . visual_studio_generator ( & target) ) ;
528
+ conf_cmd
529
+ . arg ( "-G" )
530
+ . arg ( self . visual_studio_generator ( & target) ) ;
527
531
using_nmake_generator = false ;
528
532
} else {
529
533
using_nmake_generator = self . generator . as_ref ( ) . unwrap ( ) == "NMake Makefiles" ;
530
534
}
531
535
if !is_ninja && !using_nmake_generator {
532
536
if target. contains ( "x86_64" ) {
533
- cmd . arg ( "-Thost=x64" ) ;
534
- cmd . arg ( "-Ax64" ) ;
537
+ conf_cmd . arg ( "-Thost=x64" ) ;
538
+ conf_cmd . arg ( "-Ax64" ) ;
535
539
} else if target. contains ( "thumbv7a" ) {
536
- cmd . arg ( "-Thost=x64" ) ;
537
- cmd . arg ( "-Aarm" ) ;
540
+ conf_cmd . arg ( "-Thost=x64" ) ;
541
+ conf_cmd . arg ( "-Aarm" ) ;
538
542
} else if target. contains ( "aarch64" ) {
539
- cmd . arg ( "-Thost=x64" ) ;
540
- cmd . arg ( "-AARM64" ) ;
543
+ conf_cmd . arg ( "-Thost=x64" ) ;
544
+ conf_cmd . arg ( "-AARM64" ) ;
541
545
} else if target. contains ( "i686" ) {
542
546
use cc:: windows_registry:: { find_vs_version, VsVers } ;
543
547
match find_vs_version ( ) {
544
548
Ok ( VsVers :: Vs16 ) => {
545
549
// 32-bit x86 toolset used to be the default for all hosts,
546
550
// but Visual Studio 2019 changed the default toolset to match the host,
547
551
// so we need to manually override it for x86 targets
548
- cmd . arg ( "-Thost=x86" ) ;
549
- cmd . arg ( "-AWin32" ) ;
552
+ conf_cmd . arg ( "-Thost=x86" ) ;
553
+ conf_cmd . arg ( "-AWin32" ) ;
550
554
}
551
555
_ => { }
552
556
} ;
@@ -556,29 +560,29 @@ impl Config {
556
560
}
557
561
} else if target. contains ( "redox" ) {
558
562
if !self . defined ( "CMAKE_SYSTEM_NAME" ) {
559
- cmd . arg ( "-DCMAKE_SYSTEM_NAME=Generic" ) ;
563
+ conf_cmd . arg ( "-DCMAKE_SYSTEM_NAME=Generic" ) ;
560
564
}
561
565
} else if target. contains ( "solaris" ) {
562
566
if !self . defined ( "CMAKE_SYSTEM_NAME" ) {
563
- cmd . arg ( "-DCMAKE_SYSTEM_NAME=SunOS" ) ;
567
+ conf_cmd . arg ( "-DCMAKE_SYSTEM_NAME=SunOS" ) ;
564
568
}
565
569
}
566
570
if let Some ( ref generator) = self . generator {
567
- cmd . arg ( "-G" ) . arg ( generator) ;
571
+ conf_cmd . arg ( "-G" ) . arg ( generator) ;
568
572
}
569
573
let profile = self . get_profile ( ) ;
570
574
for & ( ref k, ref v) in & self . defines {
571
575
let mut os = OsString :: from ( "-D" ) ;
572
576
os. push ( k) ;
573
577
os. push ( "=" ) ;
574
578
os. push ( v) ;
575
- cmd . arg ( os) ;
579
+ conf_cmd . arg ( os) ;
576
580
}
577
581
578
582
if !self . defined ( "CMAKE_INSTALL_PREFIX" ) {
579
583
let mut dstflag = OsString :: from ( "-DCMAKE_INSTALL_PREFIX=" ) ;
580
584
dstflag. push ( & dst) ;
581
- cmd . arg ( dstflag) ;
585
+ conf_cmd . arg ( dstflag) ;
582
586
}
583
587
584
588
let build_type = self
@@ -613,7 +617,7 @@ impl Config {
613
617
flagsflag. push ( " " ) ;
614
618
flagsflag. push ( arg) ;
615
619
}
616
- cmd . arg ( flagsflag) ;
620
+ conf_cmd . arg ( flagsflag) ;
617
621
}
618
622
619
623
// The visual studio generator apparently doesn't respect
@@ -637,7 +641,7 @@ impl Config {
637
641
flagsflag. push ( " " ) ;
638
642
flagsflag. push ( arg) ;
639
643
}
640
- cmd . arg ( flagsflag) ;
644
+ conf_cmd . arg ( flagsflag) ;
641
645
}
642
646
}
643
647
@@ -676,7 +680,7 @@ impl Config {
676
680
. collect :: < Vec < _ > > ( ) ;
677
681
ccompiler = OsString :: from_wide ( & wchars) ;
678
682
}
679
- cmd . arg ( ccompiler) ;
683
+ conf_cmd . arg ( ccompiler) ;
680
684
}
681
685
} ;
682
686
@@ -686,25 +690,28 @@ impl Config {
686
690
}
687
691
688
692
if !self . defined ( "CMAKE_BUILD_TYPE" ) {
689
- cmd . arg ( & format ! ( "-DCMAKE_BUILD_TYPE={}" , profile) ) ;
693
+ conf_cmd . arg ( & format ! ( "-DCMAKE_BUILD_TYPE={}" , profile) ) ;
690
694
}
691
695
692
696
if self . verbose_make {
693
- cmd . arg ( "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON" ) ;
697
+ conf_cmd . arg ( "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON" ) ;
694
698
}
695
699
696
700
if !self . defined ( "CMAKE_TOOLCHAIN_FILE" ) {
697
701
if let Ok ( s) = env:: var ( "CMAKE_TOOLCHAIN_FILE" ) {
698
- cmd . arg ( & format ! ( "-DCMAKE_TOOLCHAIN_FILE={}" , s) ) ;
702
+ conf_cmd . arg ( & format ! ( "-DCMAKE_TOOLCHAIN_FILE={}" , s) ) ;
699
703
}
700
704
}
701
705
702
706
for & ( ref k, ref v) in c_compiler. env ( ) . iter ( ) . chain ( & self . env ) {
703
- cmd . env ( k, v) ;
707
+ conf_cmd . env ( k, v) ;
704
708
}
705
709
706
- if self . always_configure || !build. join ( "CMakeCache.txt" ) . exists ( ) {
707
- run ( cmd. env ( "CMAKE_PREFIX_PATH" , cmake_prefix_path) , "cmake" ) ;
710
+ if self . always_configure || !build. join ( CMAKE_CACHE_FILE ) . exists ( ) {
711
+ run (
712
+ conf_cmd. env ( "CMAKE_PREFIX_PATH" , cmake_prefix_path) ,
713
+ "cmake" ,
714
+ ) ;
708
715
} else {
709
716
println ! ( "CMake project was already configured. Skipping configuration step." ) ;
710
717
}
@@ -750,32 +757,33 @@ impl Config {
750
757
751
758
// And build!
752
759
let target = self . cmake_target . clone ( ) . unwrap_or ( "install" . to_string ( ) ) ;
753
- let mut cmd = Command :: new ( & executable) ;
760
+ let mut build_cmd = Command :: new ( & executable) ;
754
761
for & ( ref k, ref v) in c_compiler. env ( ) . iter ( ) . chain ( & self . env ) {
755
- cmd . env ( k, v) ;
762
+ build_cmd . env ( k, v) ;
756
763
}
757
764
758
765
if let Some ( flags) = makeflags {
759
- cmd . env ( "MAKEFLAGS" , flags) ;
766
+ build_cmd . env ( "MAKEFLAGS" , flags) ;
760
767
}
761
768
762
- cmd . arg ( "--build" ) . arg ( "." ) ;
769
+ build_cmd . arg ( "--build" ) . arg ( "." ) ;
763
770
764
771
if !self . no_build_target {
765
- cmd . arg ( "--target" ) . arg ( target) ;
772
+ build_cmd . arg ( "--target" ) . arg ( target) ;
766
773
}
767
774
768
- cmd. arg ( "--config" )
775
+ build_cmd
776
+ . arg ( "--config" )
769
777
. arg ( & profile)
770
778
. arg ( "--" )
771
779
. args ( & self . build_args )
772
780
. current_dir ( & build) ;
773
781
774
782
if let Some ( flags) = parallel_flags {
775
- cmd . arg ( flags) ;
783
+ build_cmd . arg ( flags) ;
776
784
}
777
785
778
- run ( & mut cmd , "cmake" ) ;
786
+ run ( & mut build_cmd , "cmake" ) ;
779
787
780
788
println ! ( "cargo:root={}" , dst. display( ) ) ;
781
789
return dst;
@@ -823,7 +831,7 @@ impl Config {
823
831
// isn't relevant to us but we canonicalize it here to ensure
824
832
// we're both checking the same thing.
825
833
let path = fs:: canonicalize ( & self . path ) . unwrap_or ( self . path . clone ( ) ) ;
826
- let mut f = match File :: open ( dir. join ( "CMakeCache.txt" ) ) {
834
+ let mut f = match File :: open ( dir. join ( CMAKE_CACHE_FILE ) ) {
827
835
Ok ( f) => f,
828
836
Err ( ..) => return ,
829
837
} ;
0 commit comments