@@ -102,6 +102,8 @@ pub fn build<P: AsRef<Path>>(path: P) -> PathBuf {
102
102
Config :: new ( path. as_ref ( ) ) . build ( )
103
103
}
104
104
105
+ static CMAKE_CACHE_FILE : & str = "CMakeCache.txt" ;
106
+
105
107
impl Config {
106
108
/// Return explicitly set profile or infer `CMAKE_BUILD_TYPE` from Rust's compilation profile.
107
109
///
@@ -479,14 +481,14 @@ impl Config {
479
481
480
482
// Build up the first cmake command to build the build system.
481
483
let executable = env:: var ( "CMAKE" ) . unwrap_or ( "cmake" . to_owned ( ) ) ;
482
- let mut cmd = Command :: new ( & executable) ;
484
+ let mut conf_cmd = Command :: new ( & executable) ;
483
485
484
486
if self . verbose_cmake {
485
- cmd . arg ( "-Wdev" ) ;
486
- cmd . arg ( "--debug-output" ) ;
487
+ conf_cmd . arg ( "-Wdev" ) ;
488
+ conf_cmd . arg ( "--debug-output" ) ;
487
489
}
488
490
489
- cmd . arg ( & self . path ) . current_dir ( & build) ;
491
+ conf_cmd . arg ( & self . path ) . current_dir ( & build) ;
490
492
let mut is_ninja = false ;
491
493
if let Some ( ref generator) = self . generator {
492
494
is_ninja = generator. to_string_lossy ( ) . contains ( "Ninja" ) ;
@@ -519,15 +521,15 @@ impl Config {
519
521
( false , false ) => fail ( "no valid generator found for GNU toolchain; MSYS or MinGW must be installed" )
520
522
} ;
521
523
522
- cmd . arg ( "-G" ) . arg ( generator) ;
524
+ conf_cmd . arg ( "-G" ) . arg ( generator) ;
523
525
}
524
526
} else {
525
527
// If we're cross compiling onto windows, then set some
526
528
// variables which will hopefully get things to succeed. Some
527
529
// systems may need the `windres` or `dlltool` variables set, so
528
530
// set them if possible.
529
531
if !self . defined ( "CMAKE_SYSTEM_NAME" ) {
530
- cmd . arg ( "-DCMAKE_SYSTEM_NAME=Windows" ) ;
532
+ conf_cmd . arg ( "-DCMAKE_SYSTEM_NAME=Windows" ) ;
531
533
}
532
534
if !self . defined ( "CMAKE_RC_COMPILER" ) {
533
535
let exe = find_exe ( c_compiler. path ( ) ) ;
@@ -537,7 +539,7 @@ impl Config {
537
539
if windres. is_file ( ) {
538
540
let mut arg = OsString :: from ( "-DCMAKE_RC_COMPILER=" ) ;
539
541
arg. push ( & windres) ;
540
- cmd . arg ( arg) ;
542
+ conf_cmd . arg ( arg) ;
541
543
}
542
544
}
543
545
}
@@ -548,30 +550,32 @@ impl Config {
548
550
// This also guarantees that NMake generator isn't chosen implicitly.
549
551
let using_nmake_generator;
550
552
if self . generator . is_none ( ) {
551
- cmd. arg ( "-G" ) . arg ( self . visual_studio_generator ( & target) ) ;
553
+ conf_cmd
554
+ . arg ( "-G" )
555
+ . arg ( self . visual_studio_generator ( & target) ) ;
552
556
using_nmake_generator = false ;
553
557
} else {
554
558
using_nmake_generator = self . generator . as_ref ( ) . unwrap ( ) == "NMake Makefiles" ;
555
559
}
556
560
if !is_ninja && !using_nmake_generator {
557
561
if target. contains ( "x86_64" ) {
558
- cmd . arg ( "-Thost=x64" ) ;
559
- cmd . arg ( "-Ax64" ) ;
562
+ conf_cmd . arg ( "-Thost=x64" ) ;
563
+ conf_cmd . arg ( "-Ax64" ) ;
560
564
} else if target. contains ( "thumbv7a" ) {
561
- cmd . arg ( "-Thost=x64" ) ;
562
- cmd . arg ( "-Aarm" ) ;
565
+ conf_cmd . arg ( "-Thost=x64" ) ;
566
+ conf_cmd . arg ( "-Aarm" ) ;
563
567
} else if target. contains ( "aarch64" ) {
564
- cmd . arg ( "-Thost=x64" ) ;
565
- cmd . arg ( "-AARM64" ) ;
568
+ conf_cmd . arg ( "-Thost=x64" ) ;
569
+ conf_cmd . arg ( "-AARM64" ) ;
566
570
} else if target. contains ( "i686" ) {
567
571
use cc:: windows_registry:: { find_vs_version, VsVers } ;
568
572
match find_vs_version ( ) {
569
573
Ok ( VsVers :: Vs16 ) => {
570
574
// 32-bit x86 toolset used to be the default for all hosts,
571
575
// but Visual Studio 2019 changed the default toolset to match the host,
572
576
// so we need to manually override it for x86 targets
573
- cmd . arg ( "-Thost=x86" ) ;
574
- cmd . arg ( "-AWin32" ) ;
577
+ conf_cmd . arg ( "-Thost=x86" ) ;
578
+ conf_cmd . arg ( "-AWin32" ) ;
575
579
}
576
580
_ => { }
577
581
} ;
@@ -581,35 +585,35 @@ impl Config {
581
585
}
582
586
} else if target. contains ( "redox" ) {
583
587
if !self . defined ( "CMAKE_SYSTEM_NAME" ) {
584
- cmd . arg ( "-DCMAKE_SYSTEM_NAME=Generic" ) ;
588
+ conf_cmd . arg ( "-DCMAKE_SYSTEM_NAME=Generic" ) ;
585
589
}
586
590
} else if target. contains ( "solaris" ) {
587
591
if !self . defined ( "CMAKE_SYSTEM_NAME" ) {
588
- cmd . arg ( "-DCMAKE_SYSTEM_NAME=SunOS" ) ;
592
+ conf_cmd . arg ( "-DCMAKE_SYSTEM_NAME=SunOS" ) ;
589
593
}
590
594
} else if target. contains ( "apple-ios" ) || target. contains ( "apple-tvos" ) {
591
595
// These two flags prevent CMake from adding an OSX sysroot, which messes up compilation.
592
596
if !self . defined ( "CMAKE_OSX_SYSROOT" ) && !self . defined ( "CMAKE_OSX_DEPLOYMENT_TARGET" ) {
593
- cmd . arg ( "-DCMAKE_OSX_SYSROOT=/" ) ;
594
- cmd . arg ( "-DCMAKE_OSX_DEPLOYMENT_TARGET=" ) ;
597
+ conf_cmd . arg ( "-DCMAKE_OSX_SYSROOT=/" ) ;
598
+ conf_cmd . arg ( "-DCMAKE_OSX_DEPLOYMENT_TARGET=" ) ;
595
599
}
596
600
}
597
601
if let Some ( ref generator) = self . generator {
598
- cmd . arg ( "-G" ) . arg ( generator) ;
602
+ conf_cmd . arg ( "-G" ) . arg ( generator) ;
599
603
}
600
604
let profile = self . get_profile ( ) ;
601
605
for & ( ref k, ref v) in & self . defines {
602
606
let mut os = OsString :: from ( "-D" ) ;
603
607
os. push ( k) ;
604
608
os. push ( "=" ) ;
605
609
os. push ( v) ;
606
- cmd . arg ( os) ;
610
+ conf_cmd . arg ( os) ;
607
611
}
608
612
609
613
if !self . defined ( "CMAKE_INSTALL_PREFIX" ) {
610
614
let mut dstflag = OsString :: from ( "-DCMAKE_INSTALL_PREFIX=" ) ;
611
615
dstflag. push ( & dst) ;
612
- cmd . arg ( dstflag) ;
616
+ conf_cmd . arg ( dstflag) ;
613
617
}
614
618
615
619
let build_type = self
@@ -644,7 +648,7 @@ impl Config {
644
648
flagsflag. push ( " " ) ;
645
649
flagsflag. push ( arg) ;
646
650
}
647
- cmd . arg ( flagsflag) ;
651
+ conf_cmd . arg ( flagsflag) ;
648
652
}
649
653
650
654
// The visual studio generator apparently doesn't respect
@@ -668,7 +672,7 @@ impl Config {
668
672
flagsflag. push ( " " ) ;
669
673
flagsflag. push ( arg) ;
670
674
}
671
- cmd . arg ( flagsflag) ;
675
+ conf_cmd . arg ( flagsflag) ;
672
676
}
673
677
}
674
678
@@ -707,7 +711,7 @@ impl Config {
707
711
. collect :: < Vec < _ > > ( ) ;
708
712
ccompiler = OsString :: from_wide ( & wchars) ;
709
713
}
710
- cmd . arg ( ccompiler) ;
714
+ conf_cmd . arg ( ccompiler) ;
711
715
}
712
716
} ;
713
717
@@ -717,26 +721,29 @@ impl Config {
717
721
}
718
722
719
723
if !self . defined ( "CMAKE_BUILD_TYPE" ) {
720
- cmd . arg ( & format ! ( "-DCMAKE_BUILD_TYPE={}" , profile) ) ;
724
+ conf_cmd . arg ( & format ! ( "-DCMAKE_BUILD_TYPE={}" , profile) ) ;
721
725
}
722
726
723
727
if self . verbose_make {
724
- cmd . arg ( "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON" ) ;
728
+ conf_cmd . arg ( "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON" ) ;
725
729
}
726
730
727
731
if !self . defined ( "CMAKE_TOOLCHAIN_FILE" ) {
728
732
if let Ok ( s) = env:: var ( "CMAKE_TOOLCHAIN_FILE" ) {
729
- cmd . arg ( & format ! ( "-DCMAKE_TOOLCHAIN_FILE={}" , s) ) ;
733
+ conf_cmd . arg ( & format ! ( "-DCMAKE_TOOLCHAIN_FILE={}" , s) ) ;
730
734
}
731
735
}
732
736
733
737
for & ( ref k, ref v) in c_compiler. env ( ) . iter ( ) . chain ( & self . env ) {
734
- cmd . env ( k, v) ;
738
+ conf_cmd . env ( k, v) ;
735
739
}
736
740
737
- if self . always_configure || !build. join ( "CMakeCache.txt" ) . exists ( ) {
738
- cmd. args ( & self . configure_args ) ;
739
- run ( cmd. env ( "CMAKE_PREFIX_PATH" , cmake_prefix_path) , "cmake" ) ;
741
+ if self . always_configure || !build. join ( CMAKE_CACHE_FILE ) . exists ( ) {
742
+ conf_cmd. args ( & self . configure_args ) ;
743
+ run (
744
+ conf_cmd. env ( "CMAKE_PREFIX_PATH" , cmake_prefix_path) ,
745
+ "cmake" ,
746
+ ) ;
740
747
} else {
741
748
println ! ( "CMake project was already configured. Skipping configuration step." ) ;
742
749
}
@@ -782,32 +789,33 @@ impl Config {
782
789
783
790
// And build!
784
791
let target = self . cmake_target . clone ( ) . unwrap_or ( "install" . to_string ( ) ) ;
785
- let mut cmd = Command :: new ( & executable) ;
792
+ let mut build_cmd = Command :: new ( & executable) ;
786
793
for & ( ref k, ref v) in c_compiler. env ( ) . iter ( ) . chain ( & self . env ) {
787
- cmd . env ( k, v) ;
794
+ build_cmd . env ( k, v) ;
788
795
}
789
796
790
797
if let Some ( flags) = makeflags {
791
- cmd . env ( "MAKEFLAGS" , flags) ;
798
+ build_cmd . env ( "MAKEFLAGS" , flags) ;
792
799
}
793
800
794
- cmd . arg ( "--build" ) . arg ( "." ) ;
801
+ build_cmd . arg ( "--build" ) . arg ( "." ) ;
795
802
796
803
if !self . no_build_target {
797
- cmd . arg ( "--target" ) . arg ( target) ;
804
+ build_cmd . arg ( "--target" ) . arg ( target) ;
798
805
}
799
806
800
- cmd. arg ( "--config" )
807
+ build_cmd
808
+ . arg ( "--config" )
801
809
. arg ( & profile)
802
810
. arg ( "--" )
803
811
. args ( & self . build_args )
804
812
. current_dir ( & build) ;
805
813
806
814
if let Some ( flags) = parallel_flags {
807
- cmd . arg ( flags) ;
815
+ build_cmd . arg ( flags) ;
808
816
}
809
817
810
- run ( & mut cmd , "cmake" ) ;
818
+ run ( & mut build_cmd , "cmake" ) ;
811
819
812
820
println ! ( "cargo:root={}" , dst. display( ) ) ;
813
821
return dst;
@@ -826,7 +834,7 @@ impl Config {
826
834
doesn't know how to generate cmake files for it, \
827
835
can the `cmake` crate be updated?"
828
836
) ,
829
- Err ( msg) => panic ! ( msg) ,
837
+ Err ( msg) => panic ! ( "{}" , msg) ,
830
838
} ;
831
839
if [ "i686" , "x86_64" , "thumbv7a" , "aarch64" ]
832
840
. iter ( )
@@ -855,7 +863,7 @@ impl Config {
855
863
// isn't relevant to us but we canonicalize it here to ensure
856
864
// we're both checking the same thing.
857
865
let path = fs:: canonicalize ( & self . path ) . unwrap_or ( self . path . clone ( ) ) ;
858
- let mut f = match File :: open ( dir. join ( "CMakeCache.txt" ) ) {
866
+ let mut f = match File :: open ( dir. join ( CMAKE_CACHE_FILE ) ) {
859
867
Ok ( f) => f,
860
868
Err ( ..) => return ,
861
869
} ;
0 commit comments