@@ -105,6 +105,8 @@ pub fn build<P: AsRef<Path>>(path: P) -> PathBuf {
105105 Config :: new ( path. as_ref ( ) ) . build ( )
106106}
107107
108+ static CMAKE_CACHE_FILE : & str = "CMakeCache.txt" ;
109+
108110impl Config {
109111 /// Return explicitly set profile or infer `CMAKE_BUILD_TYPE` from Rust's compilation profile.
110112 ///
@@ -515,14 +517,14 @@ impl Config {
515517 let executable = self
516518 . getenv_target_os ( "CMAKE" )
517519 . unwrap_or ( OsString :: from ( "cmake" ) ) ;
518- let mut cmd = Command :: new ( & executable) ;
520+ let mut conf_cmd = Command :: new ( & executable) ;
519521
520522 if self . verbose_cmake {
521- cmd . arg ( "-Wdev" ) ;
522- cmd . arg ( "--debug-output" ) ;
523+ conf_cmd . arg ( "-Wdev" ) ;
524+ conf_cmd . arg ( "--debug-output" ) ;
523525 }
524526
525- cmd . arg ( & self . path ) . current_dir ( & build) ;
527+ conf_cmd . arg ( & self . path ) . current_dir ( & build) ;
526528 let mut is_ninja = false ;
527529 if let Some ( ref generator) = generator {
528530 is_ninja = generator. to_string_lossy ( ) . contains ( "Ninja" ) ;
@@ -555,15 +557,15 @@ impl Config {
555557 ( false , false ) => fail ( "no valid generator found for GNU toolchain; MSYS or MinGW must be installed" )
556558 } ;
557559
558- cmd . arg ( "-G" ) . arg ( generator) ;
560+ conf_cmd . arg ( "-G" ) . arg ( generator) ;
559561 }
560562 } else {
561563 // If we're cross compiling onto windows, then set some
562564 // variables which will hopefully get things to succeed. Some
563565 // systems may need the `windres` or `dlltool` variables set, so
564566 // set them if possible.
565567 if !self . defined ( "CMAKE_SYSTEM_NAME" ) {
566- cmd . arg ( "-DCMAKE_SYSTEM_NAME=Windows" ) ;
568+ conf_cmd . arg ( "-DCMAKE_SYSTEM_NAME=Windows" ) ;
567569 }
568570 if !self . defined ( "CMAKE_RC_COMPILER" ) {
569571 let exe = find_exe ( c_compiler. path ( ) ) ;
@@ -573,7 +575,7 @@ impl Config {
573575 if windres. is_file ( ) {
574576 let mut arg = OsString :: from ( "-DCMAKE_RC_COMPILER=" ) ;
575577 arg. push ( & windres) ;
576- cmd . arg ( arg) ;
578+ conf_cmd . arg ( arg) ;
577579 }
578580 }
579581 }
@@ -584,27 +586,29 @@ impl Config {
584586 // This also guarantees that NMake generator isn't chosen implicitly.
585587 let using_nmake_generator;
586588 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) ) ;
588592 using_nmake_generator = false ;
589593 } else {
590594 using_nmake_generator = generator. as_ref ( ) . unwrap ( ) == "NMake Makefiles" ;
591595 }
592596 if !is_ninja && !using_nmake_generator {
593597 if target. contains ( "x86_64" ) {
594598 if self . generator_toolset . is_none ( ) {
595- cmd . arg ( "-Thost=x64" ) ;
599+ conf_cmd . arg ( "-Thost=x64" ) ;
596600 }
597- cmd . arg ( "-Ax64" ) ;
601+ conf_cmd . arg ( "-Ax64" ) ;
598602 } else if target. contains ( "thumbv7a" ) {
599603 if self . generator_toolset . is_none ( ) {
600- cmd . arg ( "-Thost=x64" ) ;
604+ conf_cmd . arg ( "-Thost=x64" ) ;
601605 }
602- cmd . arg ( "-Aarm" ) ;
606+ conf_cmd . arg ( "-Aarm" ) ;
603607 } else if target. contains ( "aarch64" ) {
604608 if self . generator_toolset . is_none ( ) {
605- cmd . arg ( "-Thost=x64" ) ;
609+ conf_cmd . arg ( "-Thost=x64" ) ;
606610 }
607- cmd . arg ( "-AARM64" ) ;
611+ conf_cmd . arg ( "-AARM64" ) ;
608612 } else if target. contains ( "i686" ) {
609613 use cc:: windows_registry:: { find_vs_version, VsVers } ;
610614 match find_vs_version ( ) {
@@ -613,9 +617,9 @@ impl Config {
613617 // but Visual Studio 2019 changed the default toolset to match the host,
614618 // so we need to manually override it for x86 targets
615619 if self . generator_toolset . is_none ( ) {
616- cmd . arg ( "-Thost=x86" ) ;
620+ conf_cmd . arg ( "-Thost=x86" ) ;
617621 }
618- cmd . arg ( "-AWin32" ) ;
622+ conf_cmd . arg ( "-AWin32" ) ;
619623 }
620624 _ => { }
621625 } ;
@@ -625,38 +629,38 @@ impl Config {
625629 }
626630 } else if target. contains ( "redox" ) {
627631 if !self . defined ( "CMAKE_SYSTEM_NAME" ) {
628- cmd . arg ( "-DCMAKE_SYSTEM_NAME=Generic" ) ;
632+ conf_cmd . arg ( "-DCMAKE_SYSTEM_NAME=Generic" ) ;
629633 }
630634 } else if target. contains ( "solaris" ) {
631635 if !self . defined ( "CMAKE_SYSTEM_NAME" ) {
632- cmd . arg ( "-DCMAKE_SYSTEM_NAME=SunOS" ) ;
636+ conf_cmd . arg ( "-DCMAKE_SYSTEM_NAME=SunOS" ) ;
633637 }
634638 } else if target. contains ( "apple-ios" ) || target. contains ( "apple-tvos" ) {
635639 // These two flags prevent CMake from adding an OSX sysroot, which messes up compilation.
636640 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=" ) ;
639643 }
640644 }
641645 if let Some ( ref generator) = generator {
642- cmd . arg ( "-G" ) . arg ( generator) ;
646+ conf_cmd . arg ( "-G" ) . arg ( generator) ;
643647 }
644648 if let Some ( ref generator_toolset) = self . generator_toolset {
645- cmd . arg ( "-T" ) . arg ( generator_toolset) ;
649+ conf_cmd . arg ( "-T" ) . arg ( generator_toolset) ;
646650 }
647651 let profile = self . get_profile ( ) . to_string ( ) ;
648652 for & ( ref k, ref v) in & self . defines {
649653 let mut os = OsString :: from ( "-D" ) ;
650654 os. push ( k) ;
651655 os. push ( "=" ) ;
652656 os. push ( v) ;
653- cmd . arg ( os) ;
657+ conf_cmd . arg ( os) ;
654658 }
655659
656660 if !self . defined ( "CMAKE_INSTALL_PREFIX" ) {
657661 let mut dstflag = OsString :: from ( "-DCMAKE_INSTALL_PREFIX=" ) ;
658662 dstflag. push ( & dst) ;
659- cmd . arg ( dstflag) ;
663+ conf_cmd . arg ( dstflag) ;
660664 }
661665
662666 let build_type = self
@@ -691,7 +695,7 @@ impl Config {
691695 flagsflag. push ( " " ) ;
692696 flagsflag. push ( arg) ;
693697 }
694- cmd . arg ( flagsflag) ;
698+ conf_cmd . arg ( flagsflag) ;
695699 }
696700
697701 // The visual studio generator apparently doesn't respect
@@ -715,7 +719,7 @@ impl Config {
715719 flagsflag. push ( " " ) ;
716720 flagsflag. push ( arg) ;
717721 }
718- cmd . arg ( flagsflag) ;
722+ conf_cmd . arg ( flagsflag) ;
719723 }
720724 }
721725
@@ -754,7 +758,7 @@ impl Config {
754758 . collect :: < Vec < _ > > ( ) ;
755759 ccompiler = OsString :: from_wide ( & wchars) ;
756760 }
757- cmd . arg ( ccompiler) ;
761+ conf_cmd . arg ( ccompiler) ;
758762 }
759763 } ;
760764
@@ -764,31 +768,34 @@ impl Config {
764768 }
765769
766770 if !self . defined ( "CMAKE_BUILD_TYPE" ) {
767- cmd . arg ( & format ! ( "-DCMAKE_BUILD_TYPE={}" , profile) ) ;
771+ conf_cmd . arg ( & format ! ( "-DCMAKE_BUILD_TYPE={}" , profile) ) ;
768772 }
769773
770774 if self . verbose_make {
771- cmd . arg ( "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON" ) ;
775+ conf_cmd . arg ( "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON" ) ;
772776 }
773777
774778 for & ( ref k, ref v) in c_compiler. env ( ) . iter ( ) . chain ( & self . env ) {
775- cmd . env ( k, v) ;
779+ conf_cmd . env ( k, v) ;
776780 }
777781
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+ ) ;
781788 } else {
782789 println ! ( "CMake project was already configured. Skipping configuration step." ) ;
783790 }
784791
785792 // And build!
786793 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) ;
789796
790797 for & ( ref k, ref v) in c_compiler. env ( ) . iter ( ) . chain ( & self . env ) {
791- cmd . env ( k, v) ;
798+ build_cmd . env ( k, v) ;
792799 }
793800
794801 // If the generated project is Makefile based we should carefully transfer corresponding CARGO_MAKEFLAGS
@@ -806,30 +813,30 @@ impl Config {
806813 || cfg ! ( target_os = "bitrig" )
807814 || cfg ! ( target_os = "dragonflybsd" ) ) =>
808815 {
809- cmd . env ( "MAKEFLAGS" , makeflags) ;
816+ build_cmd . env ( "MAKEFLAGS" , makeflags) ;
810817 }
811818 _ => { }
812819 }
813820 }
814821
815- cmd . arg ( "--build" ) . arg ( "." ) ;
822+ build_cmd . arg ( "--build" ) . arg ( "." ) ;
816823
817824 if !self . no_build_target {
818- cmd . arg ( "--target" ) . arg ( target) ;
825+ build_cmd . arg ( "--target" ) . arg ( target) ;
819826 }
820827
821- cmd . arg ( "--config" ) . arg ( & profile) ;
828+ build_cmd . arg ( "--config" ) . arg ( & profile) ;
822829
823830 if let Ok ( s) = env:: var ( "NUM_JOBS" ) {
824831 // 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) ;
826833 }
827834
828835 if !& self . build_args . is_empty ( ) {
829- cmd . arg ( "--" ) . args ( & self . build_args ) ;
836+ build_cmd . arg ( "--" ) . args ( & self . build_args ) ;
830837 }
831838
832- run ( & mut cmd , "cmake" ) ;
839+ run ( & mut build_cmd , "cmake" ) ;
833840
834841 println ! ( "cargo:root={}" , dst. display( ) ) ;
835842 return dst;
@@ -904,7 +911,7 @@ impl Config {
904911 // isn't relevant to us but we canonicalize it here to ensure
905912 // we're both checking the same thing.
906913 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 ) ) {
908915 Ok ( f) => f,
909916 Err ( ..) => return ,
910917 } ;
0 commit comments