@@ -105,6 +105,8 @@ pub fn build<P: AsRef<Path>>(path: P) -> PathBuf {
105
105
Config :: new ( path. as_ref ( ) ) . build ( )
106
106
}
107
107
108
+ static CMAKE_CACHE_FILE : & str = "CMakeCache.txt" ;
109
+
108
110
impl Config {
109
111
/// Return explicitly set profile or infer `CMAKE_BUILD_TYPE` from Rust's compilation profile.
110
112
///
@@ -515,14 +517,14 @@ impl Config {
515
517
let executable = self
516
518
. getenv_target_os ( "CMAKE" )
517
519
. unwrap_or ( OsString :: from ( "cmake" ) ) ;
518
- let mut cmd = Command :: new ( & executable) ;
520
+ let mut conf_cmd = Command :: new ( & executable) ;
519
521
520
522
if self . verbose_cmake {
521
- cmd . arg ( "-Wdev" ) ;
522
- cmd . arg ( "--debug-output" ) ;
523
+ conf_cmd . arg ( "-Wdev" ) ;
524
+ conf_cmd . arg ( "--debug-output" ) ;
523
525
}
524
526
525
- cmd . arg ( & self . path ) . current_dir ( & build) ;
527
+ conf_cmd . arg ( & self . path ) . current_dir ( & build) ;
526
528
let mut is_ninja = false ;
527
529
if let Some ( ref generator) = generator {
528
530
is_ninja = generator. to_string_lossy ( ) . contains ( "Ninja" ) ;
@@ -555,15 +557,15 @@ impl Config {
555
557
( false , false ) => fail ( "no valid generator found for GNU toolchain; MSYS or MinGW must be installed" )
556
558
} ;
557
559
558
- cmd . arg ( "-G" ) . arg ( generator) ;
560
+ conf_cmd . arg ( "-G" ) . arg ( generator) ;
559
561
}
560
562
} else {
561
563
// If we're cross compiling onto windows, then set some
562
564
// variables which will hopefully get things to succeed. Some
563
565
// systems may need the `windres` or `dlltool` variables set, so
564
566
// set them if possible.
565
567
if !self . defined ( "CMAKE_SYSTEM_NAME" ) {
566
- cmd . arg ( "-DCMAKE_SYSTEM_NAME=Windows" ) ;
568
+ conf_cmd . arg ( "-DCMAKE_SYSTEM_NAME=Windows" ) ;
567
569
}
568
570
if !self . defined ( "CMAKE_RC_COMPILER" ) {
569
571
let exe = find_exe ( c_compiler. path ( ) ) ;
@@ -573,7 +575,7 @@ impl Config {
573
575
if windres. is_file ( ) {
574
576
let mut arg = OsString :: from ( "-DCMAKE_RC_COMPILER=" ) ;
575
577
arg. push ( & windres) ;
576
- cmd . arg ( arg) ;
578
+ conf_cmd . arg ( arg) ;
577
579
}
578
580
}
579
581
}
@@ -584,27 +586,29 @@ impl Config {
584
586
// This also guarantees that NMake generator isn't chosen implicitly.
585
587
let using_nmake_generator;
586
588
if generator. is_none ( ) {
587
- cmd. arg ( "-G" ) . arg ( self . visual_studio_generator ( & target) ) ;
589
+ conf_cmd
590
+ . arg ( "-G" )
591
+ . arg ( self . visual_studio_generator ( & target) ) ;
588
592
using_nmake_generator = false ;
589
593
} else {
590
594
using_nmake_generator = generator. as_ref ( ) . unwrap ( ) == "NMake Makefiles" ;
591
595
}
592
596
if !is_ninja && !using_nmake_generator {
593
597
if target. contains ( "x86_64" ) {
594
598
if self . generator_toolset . is_none ( ) {
595
- cmd . arg ( "-Thost=x64" ) ;
599
+ conf_cmd . arg ( "-Thost=x64" ) ;
596
600
}
597
- cmd . arg ( "-Ax64" ) ;
601
+ conf_cmd . arg ( "-Ax64" ) ;
598
602
} else if target. contains ( "thumbv7a" ) {
599
603
if self . generator_toolset . is_none ( ) {
600
- cmd . arg ( "-Thost=x64" ) ;
604
+ conf_cmd . arg ( "-Thost=x64" ) ;
601
605
}
602
- cmd . arg ( "-Aarm" ) ;
606
+ conf_cmd . arg ( "-Aarm" ) ;
603
607
} else if target. contains ( "aarch64" ) {
604
608
if self . generator_toolset . is_none ( ) {
605
- cmd . arg ( "-Thost=x64" ) ;
609
+ conf_cmd . arg ( "-Thost=x64" ) ;
606
610
}
607
- cmd . arg ( "-AARM64" ) ;
611
+ conf_cmd . arg ( "-AARM64" ) ;
608
612
} else if target. contains ( "i686" ) {
609
613
use cc:: windows_registry:: { find_vs_version, VsVers } ;
610
614
match find_vs_version ( ) {
@@ -613,9 +617,9 @@ impl Config {
613
617
// but Visual Studio 2019 changed the default toolset to match the host,
614
618
// so we need to manually override it for x86 targets
615
619
if self . generator_toolset . is_none ( ) {
616
- cmd . arg ( "-Thost=x86" ) ;
620
+ conf_cmd . arg ( "-Thost=x86" ) ;
617
621
}
618
- cmd . arg ( "-AWin32" ) ;
622
+ conf_cmd . arg ( "-AWin32" ) ;
619
623
}
620
624
_ => { }
621
625
} ;
@@ -625,38 +629,38 @@ impl Config {
625
629
}
626
630
} else if target. contains ( "redox" ) {
627
631
if !self . defined ( "CMAKE_SYSTEM_NAME" ) {
628
- cmd . arg ( "-DCMAKE_SYSTEM_NAME=Generic" ) ;
632
+ conf_cmd . arg ( "-DCMAKE_SYSTEM_NAME=Generic" ) ;
629
633
}
630
634
} else if target. contains ( "solaris" ) {
631
635
if !self . defined ( "CMAKE_SYSTEM_NAME" ) {
632
- cmd . arg ( "-DCMAKE_SYSTEM_NAME=SunOS" ) ;
636
+ conf_cmd . arg ( "-DCMAKE_SYSTEM_NAME=SunOS" ) ;
633
637
}
634
638
} else if target. contains ( "apple-ios" ) || target. contains ( "apple-tvos" ) {
635
639
// These two flags prevent CMake from adding an OSX sysroot, which messes up compilation.
636
640
if !self . defined ( "CMAKE_OSX_SYSROOT" ) && !self . defined ( "CMAKE_OSX_DEPLOYMENT_TARGET" ) {
637
- cmd . arg ( "-DCMAKE_OSX_SYSROOT=/" ) ;
638
- cmd . arg ( "-DCMAKE_OSX_DEPLOYMENT_TARGET=" ) ;
641
+ conf_cmd . arg ( "-DCMAKE_OSX_SYSROOT=/" ) ;
642
+ conf_cmd . arg ( "-DCMAKE_OSX_DEPLOYMENT_TARGET=" ) ;
639
643
}
640
644
}
641
645
if let Some ( ref generator) = generator {
642
- cmd . arg ( "-G" ) . arg ( generator) ;
646
+ conf_cmd . arg ( "-G" ) . arg ( generator) ;
643
647
}
644
648
if let Some ( ref generator_toolset) = self . generator_toolset {
645
- cmd . arg ( "-T" ) . arg ( generator_toolset) ;
649
+ conf_cmd . arg ( "-T" ) . arg ( generator_toolset) ;
646
650
}
647
651
let profile = self . get_profile ( ) . to_string ( ) ;
648
652
for & ( ref k, ref v) in & self . defines {
649
653
let mut os = OsString :: from ( "-D" ) ;
650
654
os. push ( k) ;
651
655
os. push ( "=" ) ;
652
656
os. push ( v) ;
653
- cmd . arg ( os) ;
657
+ conf_cmd . arg ( os) ;
654
658
}
655
659
656
660
if !self . defined ( "CMAKE_INSTALL_PREFIX" ) {
657
661
let mut dstflag = OsString :: from ( "-DCMAKE_INSTALL_PREFIX=" ) ;
658
662
dstflag. push ( & dst) ;
659
- cmd . arg ( dstflag) ;
663
+ conf_cmd . arg ( dstflag) ;
660
664
}
661
665
662
666
let build_type = self
@@ -691,7 +695,7 @@ impl Config {
691
695
flagsflag. push ( " " ) ;
692
696
flagsflag. push ( arg) ;
693
697
}
694
- cmd . arg ( flagsflag) ;
698
+ conf_cmd . arg ( flagsflag) ;
695
699
}
696
700
697
701
// The visual studio generator apparently doesn't respect
@@ -715,7 +719,7 @@ impl Config {
715
719
flagsflag. push ( " " ) ;
716
720
flagsflag. push ( arg) ;
717
721
}
718
- cmd . arg ( flagsflag) ;
722
+ conf_cmd . arg ( flagsflag) ;
719
723
}
720
724
}
721
725
@@ -754,7 +758,7 @@ impl Config {
754
758
. collect :: < Vec < _ > > ( ) ;
755
759
ccompiler = OsString :: from_wide ( & wchars) ;
756
760
}
757
- cmd . arg ( ccompiler) ;
761
+ conf_cmd . arg ( ccompiler) ;
758
762
}
759
763
} ;
760
764
@@ -764,31 +768,34 @@ impl Config {
764
768
}
765
769
766
770
if !self . defined ( "CMAKE_BUILD_TYPE" ) {
767
- cmd . arg ( & format ! ( "-DCMAKE_BUILD_TYPE={}" , profile) ) ;
771
+ conf_cmd . arg ( & format ! ( "-DCMAKE_BUILD_TYPE={}" , profile) ) ;
768
772
}
769
773
770
774
if self . verbose_make {
771
- cmd . arg ( "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON" ) ;
775
+ conf_cmd . arg ( "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON" ) ;
772
776
}
773
777
774
778
for & ( ref k, ref v) in c_compiler. env ( ) . iter ( ) . chain ( & self . env ) {
775
- cmd . env ( k, v) ;
779
+ conf_cmd . env ( k, v) ;
776
780
}
777
781
778
- if self . always_configure || !build. join ( "CMakeCache.txt" ) . exists ( ) {
779
- cmd. args ( & self . configure_args ) ;
780
- run ( cmd. env ( "CMAKE_PREFIX_PATH" , cmake_prefix_path) , "cmake" ) ;
782
+ if self . always_configure || !build. join ( CMAKE_CACHE_FILE ) . exists ( ) {
783
+ conf_cmd. args ( & self . configure_args ) ;
784
+ run (
785
+ conf_cmd. env ( "CMAKE_PREFIX_PATH" , cmake_prefix_path) ,
786
+ "cmake" ,
787
+ ) ;
781
788
} else {
782
789
println ! ( "CMake project was already configured. Skipping configuration step." ) ;
783
790
}
784
791
785
792
// And build!
786
793
let target = self . cmake_target . clone ( ) . unwrap_or ( "install" . to_string ( ) ) ;
787
- let mut cmd = Command :: new ( & executable) ;
788
- cmd . current_dir ( & build) ;
794
+ let mut build_cmd = Command :: new ( & executable) ;
795
+ build_cmd . current_dir ( & build) ;
789
796
790
797
for & ( ref k, ref v) in c_compiler. env ( ) . iter ( ) . chain ( & self . env ) {
791
- cmd . env ( k, v) ;
798
+ build_cmd . env ( k, v) ;
792
799
}
793
800
794
801
// If the generated project is Makefile based we should carefully transfer corresponding CARGO_MAKEFLAGS
@@ -806,30 +813,30 @@ impl Config {
806
813
|| cfg ! ( target_os = "bitrig" )
807
814
|| cfg ! ( target_os = "dragonflybsd" ) ) =>
808
815
{
809
- cmd . env ( "MAKEFLAGS" , makeflags) ;
816
+ build_cmd . env ( "MAKEFLAGS" , makeflags) ;
810
817
}
811
818
_ => { }
812
819
}
813
820
}
814
821
815
- cmd . arg ( "--build" ) . arg ( "." ) ;
822
+ build_cmd . arg ( "--build" ) . arg ( "." ) ;
816
823
817
824
if !self . no_build_target {
818
- cmd . arg ( "--target" ) . arg ( target) ;
825
+ build_cmd . arg ( "--target" ) . arg ( target) ;
819
826
}
820
827
821
- cmd . arg ( "--config" ) . arg ( & profile) ;
828
+ build_cmd . arg ( "--config" ) . arg ( & profile) ;
822
829
823
830
if let Ok ( s) = env:: var ( "NUM_JOBS" ) {
824
831
// See https://cmake.org/cmake/help/v3.12/manual/cmake.1.html#build-tool-mode
825
- cmd . arg ( "--parallel" ) . arg ( s) ;
832
+ build_cmd . arg ( "--parallel" ) . arg ( s) ;
826
833
}
827
834
828
835
if !& self . build_args . is_empty ( ) {
829
- cmd . arg ( "--" ) . args ( & self . build_args ) ;
836
+ build_cmd . arg ( "--" ) . args ( & self . build_args ) ;
830
837
}
831
838
832
- run ( & mut cmd , "cmake" ) ;
839
+ run ( & mut build_cmd , "cmake" ) ;
833
840
834
841
println ! ( "cargo:root={}" , dst. display( ) ) ;
835
842
return dst;
@@ -904,7 +911,7 @@ impl Config {
904
911
// isn't relevant to us but we canonicalize it here to ensure
905
912
// we're both checking the same thing.
906
913
let path = fs:: canonicalize ( & self . path ) . unwrap_or ( self . path . clone ( ) ) ;
907
- let mut f = match File :: open ( dir. join ( "CMakeCache.txt" ) ) {
914
+ let mut f = match File :: open ( dir. join ( CMAKE_CACHE_FILE ) ) {
908
915
Ok ( f) => f,
909
916
Err ( ..) => return ,
910
917
} ;
0 commit comments