Browse Source

Add build support for Emscripten 1.38.x. Emit WASM by default.

Yao Wei Tjong 姚伟忠 7 years ago
parent
commit
e65cdac59e
2 changed files with 12 additions and 2 deletions
  1. 11 1
      CMake/Modules/UrhoCommon.cmake
  2. 1 1
      Docs/GettingStarted.dox

+ 11 - 1
CMake/Modules/UrhoCommon.cmake

@@ -332,7 +332,7 @@ if (EMSCRIPTEN)     # CMAKE_CROSSCOMPILING is always true for Emscripten
     set (MODULE MODULE)
     set (EMSCRIPTEN_ROOT_PATH "" CACHE PATH "Root path to Emscripten cross-compiler tools (Emscripten only)")
     set (EMSCRIPTEN_SYSROOT "" CACHE PATH "Path to Emscripten system root (Emscripten only)")
-    cmake_dependent_option (EMSCRIPTEN_WASM "Enable Binaryen support to generate output to WASM (WebAssembly) format (Emscripten only)" FALSE "NOT EMSCRIPTEN_EMCC_VERSION VERSION_LESS 1.37.3" FALSE)
+    cmake_dependent_option (EMSCRIPTEN_WASM "Enable Binaryen support to generate output to WASM (WebAssembly) format (Emscripten only)" TRUE "NOT EMSCRIPTEN_EMCC_VERSION VERSION_LESS 1.37.3" FALSE)
     # Currently Emscripten does not support memory growth with MODULE library type
     if (URHO3D_LIB_TYPE STREQUAL MODULE)
         set (DEFAULT_MEMORY_GROWTH FALSE)
@@ -683,6 +683,12 @@ else ()
                     set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s EXTRA_EXPORTED_RUNTIME_METHODS=\"['Pointer_stringify']\"")
                     set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -s EXTRA_EXPORTED_RUNTIME_METHODS=\"['Pointer_stringify']\"")
                 endif ()
+                # Since version 1.37.28 emcc reduces default runtime exports, but we need "FS" so it needs to be explicitly requested now
+                # (See https://github.com/kripken/emscripten/commit/f2191c1223e8261bf45f4e27d2ba4d2e9d8b3341 for more detail)
+                if (NOT EMSCRIPTEN_EMCC_VERSION VERSION_LESS 1.37.28)
+                    set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s FORCE_FILESYSTEM=1")
+                    set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -s FORCE_FILESYSTEM=1")
+                endif ()
                 set (CMAKE_C_FLAGS_RELEASE "-Oz -DNDEBUG")
                 set (CMAKE_CXX_FLAGS_RELEASE "-Oz -DNDEBUG")
                 # Remove variables to make the -O3 regalloc easier, embed data in asm.js to reduce number of moving part
@@ -1794,6 +1800,10 @@ macro (_setup_target)
             list (APPEND LINK_FLAGS "-s NO_EXIT_RUNTIME=1 -s ERROR_ON_UNDEFINED_SYMBOLS=1")
             if (EMSCRIPTEN_WASM)
                 list (APPEND LINK_FLAGS "-s WASM=1")
+            elseif (NOT EMSCRIPTEN_EMCC_VERSION VERSION_LESS 1.38.1)
+                # Since version 1.38.1 emcc emits WASM by default, so we need to explicitily turn it off to emits asm.js
+                # (See https://github.com/kripken/emscripten/commit/6e5818017d1b2e09e9f7ad22a32e9a191f6f9a3b for more detail)
+                list (APPEND LINK_FLAGS "-s WASM=0")
             endif ()
         endif ()
         # Pass EMCC-specifc setting to differentiate between main and side modules

+ 1 - 1
Docs/GettingStarted.dox

@@ -167,7 +167,7 @@ A number of build options can be defined when invoking the build scripts or when
 |ARM_ABI_FLAGS        |-|Specify ABI compiler flags (ARM on Linux platform only); e.g. Orange-Pi Mini 2 could use '-mcpu=cortex-a7 -mfpu=neon-vfpv4'|
 |EMSCRIPTEN_ROOT_PATH |-|Root path to Emscripten cross-compiler tools (Emscripten only)|
 |EMSCRIPTEN_SYSROOT   |-|Path to Emscripten system root (Emscripten only)|
-|EMSCRIPTEN_WASM      |0|Enable Binaryen support to generate output to WASM (WebAssembly) format (Emscripten only)|
+|EMSCRIPTEN_WASM      |1|Enable Binaryen support to generate output to WASM (WebAssembly) format (Emscripten only)|
 |EMSCRIPTEN_ALLOW_MEMORY_GROWTH|*|Enable memory growing based on application demand when targeting asm.js, it is not set by default due to performance penalty (Emscripten with STATIC or SHARED library type only)|
 |EMSCRIPTEN_TOTAL_MEMORY|*|Specify the total size of memory to be used (Emscripten only); default to 128 MB, must be in multiple of 64 KB when targeting WebAssembly and in multiple of 16 MB when targeting asm.js|
 |EMSCRIPTEN_SHARE_DATA|0|Enable sharing data file support (Emscripten only)|