@@ -512,10 +512,7 @@ impl Config {
512
512
let cmake_prefix_path = env:: join_paths ( & cmake_prefix_path) . unwrap ( ) ;
513
513
514
514
// Build up the first cmake command to build the build system.
515
- let executable = self
516
- . getenv_target_os ( "CMAKE" )
517
- . unwrap_or_else ( || OsString :: from ( "cmake" ) ) ;
518
- let mut cmd = Command :: new ( & executable) ;
515
+ let mut cmd = self . cmake_configure_command ( & target) ;
519
516
520
517
if self . verbose_cmake {
521
518
cmd. arg ( "-Wdev" ) ;
@@ -775,11 +772,7 @@ impl Config {
775
772
}
776
773
777
774
// And build!
778
- let target = self
779
- . cmake_target
780
- . clone ( )
781
- . unwrap_or_else ( || "install" . to_string ( ) ) ;
782
- let mut cmd = Command :: new ( & executable) ;
775
+ let mut cmd = self . cmake_build_command ( & target) ;
783
776
cmd. current_dir ( & build) ;
784
777
785
778
for & ( ref k, ref v) in c_compiler. env ( ) . iter ( ) . chain ( & self . env ) {
@@ -810,6 +803,10 @@ impl Config {
810
803
cmd. arg ( "--build" ) . arg ( "." ) ;
811
804
812
805
if !self . no_build_target {
806
+ let target = self
807
+ . cmake_target
808
+ . clone ( )
809
+ . unwrap_or_else ( || "install" . to_string ( ) ) ;
813
810
cmd. arg ( "--target" ) . arg ( target) ;
814
811
}
815
812
@@ -830,6 +827,41 @@ impl Config {
830
827
dst
831
828
}
832
829
830
+ fn cmake_executable ( & mut self ) -> OsString {
831
+ self . getenv_target_os ( "CMAKE" )
832
+ . unwrap_or_else ( || OsString :: from ( "cmake" ) )
833
+ }
834
+
835
+ // If we are building for Emscripten, wrap the calls to CMake
836
+ // as "emcmake cmake ..." and "emmake cmake --build ...".
837
+ // https://emscripten.org/docs/compiling/Building-Projects.html
838
+
839
+ fn cmake_configure_command ( & mut self , target : & str ) -> Command {
840
+ if target. contains ( "emscripten" ) {
841
+ let emcmake = self
842
+ . getenv_target_os ( "EMCMAKE" )
843
+ . unwrap_or_else ( || OsString :: from ( "emcmake" ) ) ;
844
+ let mut cmd = Command :: new ( emcmake) ;
845
+ cmd. arg ( self . cmake_executable ( ) ) ;
846
+ cmd
847
+ } else {
848
+ Command :: new ( self . cmake_executable ( ) )
849
+ }
850
+ }
851
+
852
+ fn cmake_build_command ( & mut self , target : & str ) -> Command {
853
+ if target. contains ( "emscripten" ) {
854
+ let emmake = self
855
+ . getenv_target_os ( "EMMAKE" )
856
+ . unwrap_or_else ( || OsString :: from ( "emmake" ) ) ;
857
+ let mut cmd = Command :: new ( emmake) ;
858
+ cmd. arg ( self . cmake_executable ( ) ) ;
859
+ cmd
860
+ } else {
861
+ Command :: new ( self . cmake_executable ( ) )
862
+ }
863
+ }
864
+
833
865
fn getenv_os ( & mut self , v : & str ) -> Option < OsString > {
834
866
if let Some ( val) = self . env_cache . get ( v) {
835
867
return val. clone ( ) ;
0 commit comments