@@ -99,6 +99,8 @@ pub fn build<P: AsRef<Path>>(path: P) -> PathBuf {
99
99
Config :: new ( path. as_ref ( ) ) . build ( )
100
100
}
101
101
102
+ static CMAKE_CACHE_FILE : & str = "CMakeCache.txt" ;
103
+
102
104
impl Config {
103
105
/// Creates a new blank set of configuration to build the project specified
104
106
/// at the path `path`.
@@ -383,14 +385,14 @@ impl Config {
383
385
384
386
// Build up the first cmake command to build the build system.
385
387
let executable = env:: var ( "CMAKE" ) . unwrap_or ( "cmake" . to_owned ( ) ) ;
386
- let mut cmd = Command :: new ( & executable) ;
388
+ let mut conf_cmd = Command :: new ( & executable) ;
387
389
388
390
if self . verbose_cmake {
389
- cmd . arg ( "-Wdev" ) ;
390
- cmd . arg ( "--debug-output" ) ;
391
+ conf_cmd . arg ( "-Wdev" ) ;
392
+ conf_cmd . arg ( "--debug-output" ) ;
391
393
}
392
394
393
- cmd . arg ( & self . path ) . current_dir ( & build) ;
395
+ conf_cmd . arg ( & self . path ) . current_dir ( & build) ;
394
396
let mut is_ninja = false ;
395
397
if let Some ( ref generator) = self . generator {
396
398
is_ninja = generator. to_string_lossy ( ) . contains ( "Ninja" ) ;
@@ -423,15 +425,15 @@ impl Config {
423
425
( false , false ) => fail ( "no valid generator found for GNU toolchain; MSYS or MinGW must be installed" )
424
426
} ;
425
427
426
- cmd . arg ( "-G" ) . arg ( generator) ;
428
+ conf_cmd . arg ( "-G" ) . arg ( generator) ;
427
429
}
428
430
} else {
429
431
// If we're cross compiling onto windows, then set some
430
432
// variables which will hopefully get things to succeed. Some
431
433
// systems may need the `windres` or `dlltool` variables set, so
432
434
// set them if possible.
433
435
if !self . defined ( "CMAKE_SYSTEM_NAME" ) {
434
- cmd . arg ( "-DCMAKE_SYSTEM_NAME=Windows" ) ;
436
+ conf_cmd . arg ( "-DCMAKE_SYSTEM_NAME=Windows" ) ;
435
437
}
436
438
if !self . defined ( "CMAKE_RC_COMPILER" ) {
437
439
let exe = find_exe ( c_compiler. path ( ) ) ;
@@ -441,7 +443,7 @@ impl Config {
441
443
if windres. is_file ( ) {
442
444
let mut arg = OsString :: from ( "-DCMAKE_RC_COMPILER=" ) ;
443
445
arg. push ( & windres) ;
444
- cmd . arg ( arg) ;
446
+ conf_cmd . arg ( arg) ;
445
447
}
446
448
}
447
449
}
@@ -452,30 +454,32 @@ impl Config {
452
454
// This also guarantees that NMake generator isn't chosen implicitly.
453
455
let using_nmake_generator;
454
456
if self . generator . is_none ( ) {
455
- cmd. arg ( "-G" ) . arg ( self . visual_studio_generator ( & target) ) ;
457
+ conf_cmd
458
+ . arg ( "-G" )
459
+ . arg ( self . visual_studio_generator ( & target) ) ;
456
460
using_nmake_generator = false ;
457
461
} else {
458
462
using_nmake_generator = self . generator . as_ref ( ) . unwrap ( ) == "NMake Makefiles" ;
459
463
}
460
464
if !is_ninja && !using_nmake_generator {
461
465
if target. contains ( "x86_64" ) {
462
- cmd . arg ( "-Thost=x64" ) ;
463
- cmd . arg ( "-Ax64" ) ;
466
+ conf_cmd . arg ( "-Thost=x64" ) ;
467
+ conf_cmd . arg ( "-Ax64" ) ;
464
468
} else if target. contains ( "thumbv7a" ) {
465
- cmd . arg ( "-Thost=x64" ) ;
466
- cmd . arg ( "-Aarm" ) ;
469
+ conf_cmd . arg ( "-Thost=x64" ) ;
470
+ conf_cmd . arg ( "-Aarm" ) ;
467
471
} else if target. contains ( "aarch64" ) {
468
- cmd . arg ( "-Thost=x64" ) ;
469
- cmd . arg ( "-AARM64" ) ;
472
+ conf_cmd . arg ( "-Thost=x64" ) ;
473
+ conf_cmd . arg ( "-AARM64" ) ;
470
474
} else if target. contains ( "i686" ) {
471
475
use cc:: windows_registry:: { find_vs_version, VsVers } ;
472
476
match find_vs_version ( ) {
473
477
Ok ( VsVers :: Vs16 ) => {
474
478
// 32-bit x86 toolset used to be the default for all hosts,
475
479
// but Visual Studio 2019 changed the default toolset to match the host,
476
480
// so we need to manually override it for x86 targets
477
- cmd . arg ( "-Thost=x86" ) ;
478
- cmd . arg ( "-AWin32" ) ;
481
+ conf_cmd . arg ( "-Thost=x86" ) ;
482
+ conf_cmd . arg ( "-AWin32" ) ;
479
483
}
480
484
_ => { }
481
485
} ;
@@ -485,15 +489,15 @@ impl Config {
485
489
}
486
490
} else if target. contains ( "redox" ) {
487
491
if !self . defined ( "CMAKE_SYSTEM_NAME" ) {
488
- cmd . arg ( "-DCMAKE_SYSTEM_NAME=Generic" ) ;
492
+ conf_cmd . arg ( "-DCMAKE_SYSTEM_NAME=Generic" ) ;
489
493
}
490
494
} else if target. contains ( "solaris" ) {
491
495
if !self . defined ( "CMAKE_SYSTEM_NAME" ) {
492
- cmd . arg ( "-DCMAKE_SYSTEM_NAME=SunOS" ) ;
496
+ conf_cmd . arg ( "-DCMAKE_SYSTEM_NAME=SunOS" ) ;
493
497
}
494
498
}
495
499
if let Some ( ref generator) = self . generator {
496
- cmd . arg ( "-G" ) . arg ( generator) ;
500
+ conf_cmd . arg ( "-G" ) . arg ( generator) ;
497
501
}
498
502
let profile = self . profile . clone ( ) . unwrap_or_else ( || {
499
503
// Automatically set the `CMAKE_BUILD_TYPE` if the user did not
@@ -563,13 +567,13 @@ impl Config {
563
567
os. push ( k) ;
564
568
os. push ( "=" ) ;
565
569
os. push ( v) ;
566
- cmd . arg ( os) ;
570
+ conf_cmd . arg ( os) ;
567
571
}
568
572
569
573
if !self . defined ( "CMAKE_INSTALL_PREFIX" ) {
570
574
let mut dstflag = OsString :: from ( "-DCMAKE_INSTALL_PREFIX=" ) ;
571
575
dstflag. push ( & dst) ;
572
- cmd . arg ( dstflag) ;
576
+ conf_cmd . arg ( dstflag) ;
573
577
}
574
578
575
579
let build_type = self
@@ -604,7 +608,7 @@ impl Config {
604
608
flagsflag. push ( " " ) ;
605
609
flagsflag. push ( arg) ;
606
610
}
607
- cmd . arg ( flagsflag) ;
611
+ conf_cmd . arg ( flagsflag) ;
608
612
}
609
613
610
614
// The visual studio generator apparently doesn't respect
@@ -628,7 +632,7 @@ impl Config {
628
632
flagsflag. push ( " " ) ;
629
633
flagsflag. push ( arg) ;
630
634
}
631
- cmd . arg ( flagsflag) ;
635
+ conf_cmd . arg ( flagsflag) ;
632
636
}
633
637
}
634
638
@@ -667,7 +671,7 @@ impl Config {
667
671
. collect :: < Vec < _ > > ( ) ;
668
672
ccompiler = OsString :: from_wide ( & wchars) ;
669
673
}
670
- cmd . arg ( ccompiler) ;
674
+ conf_cmd . arg ( ccompiler) ;
671
675
}
672
676
} ;
673
677
@@ -677,25 +681,28 @@ impl Config {
677
681
}
678
682
679
683
if !self . defined ( "CMAKE_BUILD_TYPE" ) {
680
- cmd . arg ( & format ! ( "-DCMAKE_BUILD_TYPE={}" , profile) ) ;
684
+ conf_cmd . arg ( & format ! ( "-DCMAKE_BUILD_TYPE={}" , profile) ) ;
681
685
}
682
686
683
687
if self . verbose_make {
684
- cmd . arg ( "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON" ) ;
688
+ conf_cmd . arg ( "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON" ) ;
685
689
}
686
690
687
691
if !self . defined ( "CMAKE_TOOLCHAIN_FILE" ) {
688
692
if let Ok ( s) = env:: var ( "CMAKE_TOOLCHAIN_FILE" ) {
689
- cmd . arg ( & format ! ( "-DCMAKE_TOOLCHAIN_FILE={}" , s) ) ;
693
+ conf_cmd . arg ( & format ! ( "-DCMAKE_TOOLCHAIN_FILE={}" , s) ) ;
690
694
}
691
695
}
692
696
693
697
for & ( ref k, ref v) in c_compiler. env ( ) . iter ( ) . chain ( & self . env ) {
694
- cmd . env ( k, v) ;
698
+ conf_cmd . env ( k, v) ;
695
699
}
696
700
697
- if self . always_configure || !build. join ( "CMakeCache.txt" ) . exists ( ) {
698
- run ( cmd. env ( "CMAKE_PREFIX_PATH" , cmake_prefix_path) , "cmake" ) ;
701
+ if self . always_configure || !build. join ( CMAKE_CACHE_FILE ) . exists ( ) {
702
+ run (
703
+ conf_cmd. env ( "CMAKE_PREFIX_PATH" , cmake_prefix_path) ,
704
+ "cmake" ,
705
+ ) ;
699
706
} else {
700
707
println ! ( "CMake project was already configured. Skipping configuration step." ) ;
701
708
}
@@ -741,32 +748,33 @@ impl Config {
741
748
742
749
// And build!
743
750
let target = self . cmake_target . clone ( ) . unwrap_or ( "install" . to_string ( ) ) ;
744
- let mut cmd = Command :: new ( & executable) ;
751
+ let mut build_cmd = Command :: new ( & executable) ;
745
752
for & ( ref k, ref v) in c_compiler. env ( ) . iter ( ) . chain ( & self . env ) {
746
- cmd . env ( k, v) ;
753
+ build_cmd . env ( k, v) ;
747
754
}
748
755
749
756
if let Some ( flags) = makeflags {
750
- cmd . env ( "MAKEFLAGS" , flags) ;
757
+ build_cmd . env ( "MAKEFLAGS" , flags) ;
751
758
}
752
759
753
- cmd . arg ( "--build" ) . arg ( "." ) ;
760
+ build_cmd . arg ( "--build" ) . arg ( "." ) ;
754
761
755
762
if !self . no_build_target {
756
- cmd . arg ( "--target" ) . arg ( target) ;
763
+ build_cmd . arg ( "--target" ) . arg ( target) ;
757
764
}
758
765
759
- cmd. arg ( "--config" )
766
+ build_cmd
767
+ . arg ( "--config" )
760
768
. arg ( & profile)
761
769
. arg ( "--" )
762
770
. args ( & self . build_args )
763
771
. current_dir ( & build) ;
764
772
765
773
if let Some ( flags) = parallel_flags {
766
- cmd . arg ( flags) ;
774
+ build_cmd . arg ( flags) ;
767
775
}
768
776
769
- run ( & mut cmd , "cmake" ) ;
777
+ run ( & mut build_cmd , "cmake" ) ;
770
778
771
779
println ! ( "cargo:root={}" , dst. display( ) ) ;
772
780
return dst;
@@ -814,7 +822,7 @@ impl Config {
814
822
// isn't relevant to us but we canonicalize it here to ensure
815
823
// we're both checking the same thing.
816
824
let path = fs:: canonicalize ( & self . path ) . unwrap_or ( self . path . clone ( ) ) ;
817
- let mut f = match File :: open ( dir. join ( "CMakeCache.txt" ) ) {
825
+ let mut f = match File :: open ( dir. join ( CMAKE_CACHE_FILE ) ) {
818
826
Ok ( f) => f,
819
827
Err ( ..) => return ,
820
828
} ;
0 commit comments