如何在 Windows 上构建 Ammo.js?

问题描述

我目前正在尝试按照自述文件中的说明在 Windows 上构建 Ammo.js我有

  • emcc 在路径中
  • cmake 通过 Visual Studio (C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe) 安装
  • MinGW 通过 Chocolatey 安装

显然,因为我使用的是 Windows,cmake 无法解析 CMakeLists.txt 中可执行文件的任何路径

set(EMSCRIPTEN_ROOT $ENV{EMSDK}/upstream/emscripten CACHE STRING "Emscripten path")

所以我不得不用我的二进制文件的完整路径替换它们:

set(EMSCRIPTEN_ROOT "C:/Program Files/emsdk/upstream/emscripten" CACHE STRING "Emscripten path")
set(CMAKE_TOOLCHAIN_FILE "C:/Program Files/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake")
set(WEBIDL_BINDER_SCRIPT "C:/Program Files/emsdk/upstream/emscripten/tools/webidl_binder.py")

现在,如果我运行 cmake -B builds,cmake 似乎运行没有错误,但它会吐出以下文件

enter image description here

cmake -B builds 
-- Building for: Visual Studio 16 2019
-- Found python3: C:/python39/python.exe (found version "3.9.1") found components: 
 Interpreter CMake Deprecation Warning at bullet/CMakeLists.txt:1 (cmake_minimum_required): 
 Compatibility with CMake < 2.8.12 will be removed from a future version of CMake.
 Update the VERSION argument <min> value or use a ...<max> suffix to tell CMake that the project does not need compatibility with older versions. 
 
 OPENGL FOUND
 
 nul 
 
 -- WARNING: you are using the obsolete 'glu' package,please use 'OpenGL' instead 
 -- Could NOT find OpenGL (missing: OPENGL_opengl_LIBRARY OPENGL_glx_LIBRARY OPENGL_INCLUDE_DIR) 
 -- Configuring done 
 -- Generating done
 -- Build files have been written to: G:/dev/projects/ammo.js/builds 

没有 ammo.js,没有 ammo.wasm.js 和 ammo.wasm

当我尝试使用 'MinGW Makefiles' 标志进行编译时,出现错误

cmake -B builds -G 'MinGW Makefiles'
-- Found python3: C:/python39/python.exe (found version "3.9.1") found components: Interpreter 
CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set,after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set,after EnableLanguage
-- Configuring incomplete,errors occurred!

我不能使用预构建的文件作为对 new Ammo.bt@R_404_6277@Shape(new Ammo.btVector3())调用抛出 Uncaught (in promise) RuntimeError: memory access out of bounds 并且根据我的理解,我需要在编译时分配更大的堆。

那么如何在 Windows 上构建 Ammo.js?

解决方法

这里有两个不同的问题

  1. 来自 Chocolatey 的 MinGw 安装不包括 mingw32-make.exe。我卸载了它,得到了 MinGW-Installer 并按照这个答案继续:CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles"

  2. 我必须在第一个命令之后实际运行 cmake --build builds,我在文档中忽略了这一点