@@ -782,54 +782,34 @@ impl Config {
782
782
println ! ( "CMake project was already configured. Skipping configuration step." ) ;
783
783
}
784
784
785
- let mut makeflags = None ;
786
- let mut parallel_flags = None ;
787
-
788
- if let Ok ( s) = env:: var ( "NUM_JOBS" ) {
789
- match generator. as_ref ( ) . map ( |g| g. to_string_lossy ( ) ) {
790
- Some ( ref g) if g. contains ( "Ninja" ) => {
791
- parallel_flags = Some ( format ! ( "-j{}" , s) ) ;
792
- }
793
- Some ( ref g) if g. contains ( "Visual Studio" ) => {
794
- parallel_flags = Some ( format ! ( "/MP{}" , s) ) ;
795
- }
796
- Some ( ref g) if g. contains ( "NMake" ) => {
797
- // NMake creates `Makefile`s, but doesn't understand `-jN`.
798
- }
799
- _ if fs:: metadata ( & build. join ( "Makefile" ) ) . is_ok ( ) => {
800
- match env:: var_os ( "CARGO_MAKEFLAGS" ) {
801
- // Only do this on non-windows and non-bsd
802
- // On Windows, we could be invoking make instead of
803
- // mingw32-make which doesn't work with our jobserver
804
- // bsdmake also does not work with our job server
805
- Some ( ref s)
806
- if !( cfg ! ( windows)
807
- || cfg ! ( target_os = "openbsd" )
808
- || cfg ! ( target_os = "netbsd" )
809
- || cfg ! ( target_os = "freebsd" )
810
- || cfg ! ( target_os = "bitrig" )
811
- || cfg ! ( target_os = "dragonflybsd" ) ) =>
812
- {
813
- makeflags = Some ( s. clone ( ) )
814
- }
815
-
816
- // This looks like `make`, let's hope it understands `-jN`.
817
- _ => makeflags = Some ( OsString :: from ( format ! ( "-j{}" , s) ) ) ,
818
- }
819
- }
820
- _ => { }
821
- }
822
- }
823
-
824
785
// And build!
825
786
let target = self . cmake_target . clone ( ) . unwrap_or ( "install" . to_string ( ) ) ;
826
787
let mut cmd = Command :: new ( & executable) ;
788
+ cmd. current_dir ( & build) ;
789
+
827
790
for & ( ref k, ref v) in c_compiler. env ( ) . iter ( ) . chain ( & self . env ) {
828
791
cmd. env ( k, v) ;
829
792
}
830
793
831
- if let Some ( flags) = makeflags {
832
- cmd. env ( "MAKEFLAGS" , flags) ;
794
+ // If the generated project is Makefile based we should carefully transfer corresponding CARGO_MAKEFLAGS
795
+ if fs:: metadata ( & build. join ( "Makefile" ) ) . is_ok ( ) {
796
+ match env:: var_os ( "CARGO_MAKEFLAGS" ) {
797
+ // Only do this on non-windows and non-bsd
798
+ // On Windows, we could be invoking make instead of
799
+ // mingw32-make which doesn't work with our jobserver
800
+ // bsdmake also does not work with our job server
801
+ Some ( ref makeflags)
802
+ if !( cfg ! ( windows)
803
+ || cfg ! ( target_os = "openbsd" )
804
+ || cfg ! ( target_os = "netbsd" )
805
+ || cfg ! ( target_os = "freebsd" )
806
+ || cfg ! ( target_os = "bitrig" )
807
+ || cfg ! ( target_os = "dragonflybsd" ) ) =>
808
+ {
809
+ cmd. env ( "MAKEFLAGS" , makeflags) ;
810
+ }
811
+ _ => { }
812
+ }
833
813
}
834
814
835
815
cmd. arg ( "--build" ) . arg ( "." ) ;
@@ -838,14 +818,15 @@ impl Config {
838
818
cmd. arg ( "--target" ) . arg ( target) ;
839
819
}
840
820
841
- cmd. arg ( "--config" )
842
- . arg ( & profile)
843
- . arg ( "--" )
844
- . args ( & self . build_args )
845
- . current_dir ( & build) ;
821
+ cmd. arg ( "--config" ) . arg ( & profile) ;
822
+
823
+ if let Ok ( s) = env:: var ( "NUM_JOBS" ) {
824
+ // See https://cmake.org/cmake/help/v3.12/manual/cmake.1.html#build-tool-mode
825
+ cmd. arg ( "--parallel" ) . arg ( s) ;
826
+ }
846
827
847
- if let Some ( flags ) = parallel_flags {
848
- cmd. arg ( flags ) ;
828
+ if ! & self . build_args . is_empty ( ) {
829
+ cmd. arg ( "--" ) . args ( & self . build_args ) ;
849
830
}
850
831
851
832
run ( & mut cmd, "cmake" ) ;
0 commit comments