@@ -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
///
@@ -507,14 +509,14 @@ impl Config {
507
509
let executable = self
508
510
. getenv_target_os ( "CMAKE" )
509
511
. unwrap_or ( OsString :: from ( "cmake" ) ) ;
510
- let mut cmd = Command :: new ( & executable) ;
512
+ let mut conf_cmd = Command :: new ( & executable) ;
511
513
512
514
if self . verbose_cmake {
513
- cmd . arg ( "-Wdev" ) ;
514
- cmd . arg ( "--debug-output" ) ;
515
+ conf_cmd . arg ( "-Wdev" ) ;
516
+ conf_cmd . arg ( "--debug-output" ) ;
515
517
}
516
518
517
- cmd . arg ( & self . path ) . current_dir ( & build) ;
519
+ conf_cmd . arg ( & self . path ) . current_dir ( & build) ;
518
520
let mut is_ninja = false ;
519
521
if let Some ( ref generator) = generator {
520
522
is_ninja = generator. to_string_lossy ( ) . contains ( "Ninja" ) ;
@@ -547,15 +549,15 @@ impl Config {
547
549
( false , false ) => fail ( "no valid generator found for GNU toolchain; MSYS or MinGW must be installed" )
548
550
} ;
549
551
550
- cmd . arg ( "-G" ) . arg ( generator) ;
552
+ conf_cmd . arg ( "-G" ) . arg ( generator) ;
551
553
}
552
554
} else {
553
555
// If we're cross compiling onto windows, then set some
554
556
// variables which will hopefully get things to succeed. Some
555
557
// systems may need the `windres` or `dlltool` variables set, so
556
558
// set them if possible.
557
559
if !self . defined ( "CMAKE_SYSTEM_NAME" ) {
558
- cmd . arg ( "-DCMAKE_SYSTEM_NAME=Windows" ) ;
560
+ conf_cmd . arg ( "-DCMAKE_SYSTEM_NAME=Windows" ) ;
559
561
}
560
562
if !self . defined ( "CMAKE_RC_COMPILER" ) {
561
563
let exe = find_exe ( c_compiler. path ( ) ) ;
@@ -565,7 +567,7 @@ impl Config {
565
567
if windres. is_file ( ) {
566
568
let mut arg = OsString :: from ( "-DCMAKE_RC_COMPILER=" ) ;
567
569
arg. push ( & windres) ;
568
- cmd . arg ( arg) ;
570
+ conf_cmd . arg ( arg) ;
569
571
}
570
572
}
571
573
}
@@ -576,27 +578,29 @@ impl Config {
576
578
// This also guarantees that NMake generator isn't chosen implicitly.
577
579
let using_nmake_generator;
578
580
if generator. is_none ( ) {
579
- cmd. arg ( "-G" ) . arg ( self . visual_studio_generator ( & target) ) ;
581
+ conf_cmd
582
+ . arg ( "-G" )
583
+ . arg ( self . visual_studio_generator ( & target) ) ;
580
584
using_nmake_generator = false ;
581
585
} else {
582
586
using_nmake_generator = generator. as_ref ( ) . unwrap ( ) == "NMake Makefiles" ;
583
587
}
584
588
if !is_ninja && !using_nmake_generator {
585
589
if target. contains ( "x86_64" ) {
586
590
if self . generator_toolset . is_none ( ) {
587
- cmd . arg ( "-Thost=x64" ) ;
591
+ conf_cmd . arg ( "-Thost=x64" ) ;
588
592
}
589
- cmd . arg ( "-Ax64" ) ;
593
+ conf_cmd . arg ( "-Ax64" ) ;
590
594
} else if target. contains ( "thumbv7a" ) {
591
595
if self . generator_toolset . is_none ( ) {
592
- cmd . arg ( "-Thost=x64" ) ;
596
+ conf_cmd . arg ( "-Thost=x64" ) ;
593
597
}
594
- cmd . arg ( "-Aarm" ) ;
598
+ conf_cmd . arg ( "-Aarm" ) ;
595
599
} else if target. contains ( "aarch64" ) {
596
600
if self . generator_toolset . is_none ( ) {
597
- cmd . arg ( "-Thost=x64" ) ;
601
+ conf_cmd . arg ( "-Thost=x64" ) ;
598
602
}
599
- cmd . arg ( "-AARM64" ) ;
603
+ conf_cmd . arg ( "-AARM64" ) ;
600
604
} else if target. contains ( "i686" ) {
601
605
use cc:: windows_registry:: { find_vs_version, VsVers } ;
602
606
match find_vs_version ( ) {
@@ -605,9 +609,9 @@ impl Config {
605
609
// but Visual Studio 2019 changed the default toolset to match the host,
606
610
// so we need to manually override it for x86 targets
607
611
if self . generator_toolset . is_none ( ) {
608
- cmd . arg ( "-Thost=x86" ) ;
612
+ conf_cmd . arg ( "-Thost=x86" ) ;
609
613
}
610
- cmd . arg ( "-AWin32" ) ;
614
+ conf_cmd . arg ( "-AWin32" ) ;
611
615
}
612
616
_ => { }
613
617
} ;
@@ -617,38 +621,38 @@ impl Config {
617
621
}
618
622
} else if target. contains ( "redox" ) {
619
623
if !self . defined ( "CMAKE_SYSTEM_NAME" ) {
620
- cmd . arg ( "-DCMAKE_SYSTEM_NAME=Generic" ) ;
624
+ conf_cmd . arg ( "-DCMAKE_SYSTEM_NAME=Generic" ) ;
621
625
}
622
626
} else if target. contains ( "solaris" ) {
623
627
if !self . defined ( "CMAKE_SYSTEM_NAME" ) {
624
- cmd . arg ( "-DCMAKE_SYSTEM_NAME=SunOS" ) ;
628
+ conf_cmd . arg ( "-DCMAKE_SYSTEM_NAME=SunOS" ) ;
625
629
}
626
630
} else if target. contains ( "apple-ios" ) || target. contains ( "apple-tvos" ) {
627
631
// These two flags prevent CMake from adding an OSX sysroot, which messes up compilation.
628
632
if !self . defined ( "CMAKE_OSX_SYSROOT" ) && !self . defined ( "CMAKE_OSX_DEPLOYMENT_TARGET" ) {
629
- cmd . arg ( "-DCMAKE_OSX_SYSROOT=/" ) ;
630
- cmd . arg ( "-DCMAKE_OSX_DEPLOYMENT_TARGET=" ) ;
633
+ conf_cmd . arg ( "-DCMAKE_OSX_SYSROOT=/" ) ;
634
+ conf_cmd . arg ( "-DCMAKE_OSX_DEPLOYMENT_TARGET=" ) ;
631
635
}
632
636
}
633
637
if let Some ( ref generator) = generator {
634
- cmd . arg ( "-G" ) . arg ( generator) ;
638
+ conf_cmd . arg ( "-G" ) . arg ( generator) ;
635
639
}
636
640
if let Some ( ref generator_toolset) = self . generator_toolset {
637
- cmd . arg ( "-T" ) . arg ( generator_toolset) ;
641
+ conf_cmd . arg ( "-T" ) . arg ( generator_toolset) ;
638
642
}
639
643
let profile = self . get_profile ( ) . to_string ( ) ;
640
644
for & ( ref k, ref v) in & self . defines {
641
645
let mut os = OsString :: from ( "-D" ) ;
642
646
os. push ( k) ;
643
647
os. push ( "=" ) ;
644
648
os. push ( v) ;
645
- cmd . arg ( os) ;
649
+ conf_cmd . arg ( os) ;
646
650
}
647
651
648
652
if !self . defined ( "CMAKE_INSTALL_PREFIX" ) {
649
653
let mut dstflag = OsString :: from ( "-DCMAKE_INSTALL_PREFIX=" ) ;
650
654
dstflag. push ( & dst) ;
651
- cmd . arg ( dstflag) ;
655
+ conf_cmd . arg ( dstflag) ;
652
656
}
653
657
654
658
let build_type = self
@@ -683,7 +687,7 @@ impl Config {
683
687
flagsflag. push ( " " ) ;
684
688
flagsflag. push ( arg) ;
685
689
}
686
- cmd . arg ( flagsflag) ;
690
+ conf_cmd . arg ( flagsflag) ;
687
691
}
688
692
689
693
// The visual studio generator apparently doesn't respect
@@ -707,7 +711,7 @@ impl Config {
707
711
flagsflag. push ( " " ) ;
708
712
flagsflag. push ( arg) ;
709
713
}
710
- cmd . arg ( flagsflag) ;
714
+ conf_cmd . arg ( flagsflag) ;
711
715
}
712
716
}
713
717
@@ -746,7 +750,7 @@ impl Config {
746
750
. collect :: < Vec < _ > > ( ) ;
747
751
ccompiler = OsString :: from_wide ( & wchars) ;
748
752
}
749
- cmd . arg ( ccompiler) ;
753
+ conf_cmd . arg ( ccompiler) ;
750
754
}
751
755
} ;
752
756
@@ -756,39 +760,42 @@ impl Config {
756
760
}
757
761
758
762
if !self . defined ( "CMAKE_BUILD_TYPE" ) {
759
- cmd . arg ( & format ! ( "-DCMAKE_BUILD_TYPE={}" , profile) ) ;
763
+ conf_cmd . arg ( & format ! ( "-DCMAKE_BUILD_TYPE={}" , profile) ) ;
760
764
}
761
765
762
766
if self . verbose_make {
763
- cmd . arg ( "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON" ) ;
767
+ conf_cmd . arg ( "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON" ) ;
764
768
}
765
769
766
770
if !self . defined ( "CMAKE_TOOLCHAIN_FILE" ) {
767
771
if let Some ( s) = self . getenv_target_os ( "CMAKE_TOOLCHAIN_FILE" ) {
768
772
let mut cmake_toolchain_file = OsString :: from ( "-DCMAKE_TOOLCHAIN_FILE=" ) ;
769
773
cmake_toolchain_file. push ( & s) ;
770
- cmd . arg ( cmake_toolchain_file) ;
774
+ conf_cmd . arg ( cmake_toolchain_file) ;
771
775
}
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;
@@ -903,7 +910,7 @@ impl Config {
903
910
// isn't relevant to us but we canonicalize it here to ensure
904
911
// we're both checking the same thing.
905
912
let path = fs:: canonicalize ( & self . path ) . unwrap_or ( self . path . clone ( ) ) ;
906
- let mut f = match File :: open ( dir. join ( "CMakeCache.txt" ) ) {
913
+ let mut f = match File :: open ( dir. join ( CMAKE_CACHE_FILE ) ) {
907
914
Ok ( f) => f,
908
915
Err ( ..) => return ,
909
916
} ;
0 commit comments