@@ -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 ///
@@ -507,14 +509,14 @@ impl Config {
507509 let executable = self
508510 . getenv_target_os ( "CMAKE" )
509511 . unwrap_or ( OsString :: from ( "cmake" ) ) ;
510- let mut cmd = Command :: new ( & executable) ;
512+ let mut conf_cmd = Command :: new ( & executable) ;
511513
512514 if self . verbose_cmake {
513- cmd . arg ( "-Wdev" ) ;
514- cmd . arg ( "--debug-output" ) ;
515+ conf_cmd . arg ( "-Wdev" ) ;
516+ conf_cmd . arg ( "--debug-output" ) ;
515517 }
516518
517- cmd . arg ( & self . path ) . current_dir ( & build) ;
519+ conf_cmd . arg ( & self . path ) . current_dir ( & build) ;
518520 let mut is_ninja = false ;
519521 if let Some ( ref generator) = generator {
520522 is_ninja = generator. to_string_lossy ( ) . contains ( "Ninja" ) ;
@@ -547,15 +549,15 @@ impl Config {
547549 ( false , false ) => fail ( "no valid generator found for GNU toolchain; MSYS or MinGW must be installed" )
548550 } ;
549551
550- cmd . arg ( "-G" ) . arg ( generator) ;
552+ conf_cmd . arg ( "-G" ) . arg ( generator) ;
551553 }
552554 } else {
553555 // If we're cross compiling onto windows, then set some
554556 // variables which will hopefully get things to succeed. Some
555557 // systems may need the `windres` or `dlltool` variables set, so
556558 // set them if possible.
557559 if !self . defined ( "CMAKE_SYSTEM_NAME" ) {
558- cmd . arg ( "-DCMAKE_SYSTEM_NAME=Windows" ) ;
560+ conf_cmd . arg ( "-DCMAKE_SYSTEM_NAME=Windows" ) ;
559561 }
560562 if !self . defined ( "CMAKE_RC_COMPILER" ) {
561563 let exe = find_exe ( c_compiler. path ( ) ) ;
@@ -565,7 +567,7 @@ impl Config {
565567 if windres. is_file ( ) {
566568 let mut arg = OsString :: from ( "-DCMAKE_RC_COMPILER=" ) ;
567569 arg. push ( & windres) ;
568- cmd . arg ( arg) ;
570+ conf_cmd . arg ( arg) ;
569571 }
570572 }
571573 }
@@ -576,27 +578,29 @@ impl Config {
576578 // This also guarantees that NMake generator isn't chosen implicitly.
577579 let using_nmake_generator;
578580 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) ) ;
580584 using_nmake_generator = false ;
581585 } else {
582586 using_nmake_generator = generator. as_ref ( ) . unwrap ( ) == "NMake Makefiles" ;
583587 }
584588 if !is_ninja && !using_nmake_generator {
585589 if target. contains ( "x86_64" ) {
586590 if self . generator_toolset . is_none ( ) {
587- cmd . arg ( "-Thost=x64" ) ;
591+ conf_cmd . arg ( "-Thost=x64" ) ;
588592 }
589- cmd . arg ( "-Ax64" ) ;
593+ conf_cmd . arg ( "-Ax64" ) ;
590594 } else if target. contains ( "thumbv7a" ) {
591595 if self . generator_toolset . is_none ( ) {
592- cmd . arg ( "-Thost=x64" ) ;
596+ conf_cmd . arg ( "-Thost=x64" ) ;
593597 }
594- cmd . arg ( "-Aarm" ) ;
598+ conf_cmd . arg ( "-Aarm" ) ;
595599 } else if target. contains ( "aarch64" ) {
596600 if self . generator_toolset . is_none ( ) {
597- cmd . arg ( "-Thost=x64" ) ;
601+ conf_cmd . arg ( "-Thost=x64" ) ;
598602 }
599- cmd . arg ( "-AARM64" ) ;
603+ conf_cmd . arg ( "-AARM64" ) ;
600604 } else if target. contains ( "i686" ) {
601605 use cc:: windows_registry:: { find_vs_version, VsVers } ;
602606 match find_vs_version ( ) {
@@ -605,9 +609,9 @@ impl Config {
605609 // but Visual Studio 2019 changed the default toolset to match the host,
606610 // so we need to manually override it for x86 targets
607611 if self . generator_toolset . is_none ( ) {
608- cmd . arg ( "-Thost=x86" ) ;
612+ conf_cmd . arg ( "-Thost=x86" ) ;
609613 }
610- cmd . arg ( "-AWin32" ) ;
614+ conf_cmd . arg ( "-AWin32" ) ;
611615 }
612616 _ => { }
613617 } ;
@@ -617,38 +621,38 @@ impl Config {
617621 }
618622 } else if target. contains ( "redox" ) {
619623 if !self . defined ( "CMAKE_SYSTEM_NAME" ) {
620- cmd . arg ( "-DCMAKE_SYSTEM_NAME=Generic" ) ;
624+ conf_cmd . arg ( "-DCMAKE_SYSTEM_NAME=Generic" ) ;
621625 }
622626 } else if target. contains ( "solaris" ) {
623627 if !self . defined ( "CMAKE_SYSTEM_NAME" ) {
624- cmd . arg ( "-DCMAKE_SYSTEM_NAME=SunOS" ) ;
628+ conf_cmd . arg ( "-DCMAKE_SYSTEM_NAME=SunOS" ) ;
625629 }
626630 } else if target. contains ( "apple-ios" ) || target. contains ( "apple-tvos" ) {
627631 // These two flags prevent CMake from adding an OSX sysroot, which messes up compilation.
628632 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=" ) ;
631635 }
632636 }
633637 if let Some ( ref generator) = generator {
634- cmd . arg ( "-G" ) . arg ( generator) ;
638+ conf_cmd . arg ( "-G" ) . arg ( generator) ;
635639 }
636640 if let Some ( ref generator_toolset) = self . generator_toolset {
637- cmd . arg ( "-T" ) . arg ( generator_toolset) ;
641+ conf_cmd . arg ( "-T" ) . arg ( generator_toolset) ;
638642 }
639643 let profile = self . get_profile ( ) . to_string ( ) ;
640644 for & ( ref k, ref v) in & self . defines {
641645 let mut os = OsString :: from ( "-D" ) ;
642646 os. push ( k) ;
643647 os. push ( "=" ) ;
644648 os. push ( v) ;
645- cmd . arg ( os) ;
649+ conf_cmd . arg ( os) ;
646650 }
647651
648652 if !self . defined ( "CMAKE_INSTALL_PREFIX" ) {
649653 let mut dstflag = OsString :: from ( "-DCMAKE_INSTALL_PREFIX=" ) ;
650654 dstflag. push ( & dst) ;
651- cmd . arg ( dstflag) ;
655+ conf_cmd . arg ( dstflag) ;
652656 }
653657
654658 let build_type = self
@@ -683,7 +687,7 @@ impl Config {
683687 flagsflag. push ( " " ) ;
684688 flagsflag. push ( arg) ;
685689 }
686- cmd . arg ( flagsflag) ;
690+ conf_cmd . arg ( flagsflag) ;
687691 }
688692
689693 // The visual studio generator apparently doesn't respect
@@ -707,7 +711,7 @@ impl Config {
707711 flagsflag. push ( " " ) ;
708712 flagsflag. push ( arg) ;
709713 }
710- cmd . arg ( flagsflag) ;
714+ conf_cmd . arg ( flagsflag) ;
711715 }
712716 }
713717
@@ -746,7 +750,7 @@ impl Config {
746750 . collect :: < Vec < _ > > ( ) ;
747751 ccompiler = OsString :: from_wide ( & wchars) ;
748752 }
749- cmd . arg ( ccompiler) ;
753+ conf_cmd . arg ( ccompiler) ;
750754 }
751755 } ;
752756
@@ -756,39 +760,42 @@ impl Config {
756760 }
757761
758762 if !self . defined ( "CMAKE_BUILD_TYPE" ) {
759- cmd . arg ( & format ! ( "-DCMAKE_BUILD_TYPE={}" , profile) ) ;
763+ conf_cmd . arg ( & format ! ( "-DCMAKE_BUILD_TYPE={}" , profile) ) ;
760764 }
761765
762766 if self . verbose_make {
763- cmd . arg ( "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON" ) ;
767+ conf_cmd . arg ( "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON" ) ;
764768 }
765769
766770 if !self . defined ( "CMAKE_TOOLCHAIN_FILE" ) {
767771 if let Some ( s) = self . getenv_target_os ( "CMAKE_TOOLCHAIN_FILE" ) {
768772 let mut cmake_toolchain_file = OsString :: from ( "-DCMAKE_TOOLCHAIN_FILE=" ) ;
769773 cmake_toolchain_file. push ( & s) ;
770- cmd . arg ( cmake_toolchain_file) ;
774+ conf_cmd . arg ( cmake_toolchain_file) ;
771775 }
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;
@@ -903,7 +910,7 @@ impl Config {
903910 // isn't relevant to us but we canonicalize it here to ensure
904911 // we're both checking the same thing.
905912 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 ) ) {
907914 Ok ( f) => f,
908915 Err ( ..) => return ,
909916 } ;
0 commit comments