Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues building for Emscripten #106

Closed
scottschafer opened this issue Aug 25, 2015 · 4 comments
Closed

Issues building for Emscripten #106

scottschafer opened this issue Aug 25, 2015 · 4 comments
Assignees
Projects
Milestone

Comments

@scottschafer
Copy link

I think I'm close here, but there's something not quite right with my build procedure.

I'm on Mac OS X. I have the 'emsdk_portable' directory installed to '/projhome' and I've made a '/usr/lib/emscripten' symlink linking to the latest emscripten sdk (/projhome/emsdk_portable/emscripten/tag-1.34.6/).

The following is the script I've devised to automate getting, configuring and building. I think some of my parameters may be off, but it is mostly working. One issue that I am hacking around (but which may be a sign of something more broken) is that after the bootstrap project builds, the file "MyApplication.js.mem" is not in the right location.

I can make it run if I execute "cp src/CMakeFiles/CMakeRelink.dir/* bin/" to manually copy the files, but this seems indicative of something screwed up.

Please give this a review and tell me where I have messed up. Thank you!

# Prerequisites:
#  - CMake installed (3.3.1)
#  - Directory ~/projhome created
#  - Emscripten installed to ~/projhome/emsdk_portable
#  - Symlink from /usr/lib/emscripten created to ~/projhome/emsdk_portable/emscripten/tag-1.34.6/
#      sudo ln -s ~/projhome/emsdk_portable/emscripten/tag-1.34.6/ /usr/lib/emscripten

# Step 1 - Install Corrade
cd ~/projhome
git clone git://github.com/mosra/corrade.git

# Step 2 - Compile Corrade for emscripten
cd ~/projhome/corrade
git submodule init
git submodule update

mkdir -p build-emscripten && cd build-emscripten
cmake .. \
    -DCMAKE_MODULE_PATH="~/projhome/corrade/toolchains/modules" \
    -DCMAKE_TOOLCHAIN_FILE="../toolchains/generic/Emscripten.cmake" \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX="/usr/lib/emscripten/system" \
    -DWITH_SDL2APPLICATION=ON
cmake --build . --target install

# Step 3 - Compile Corrade for desktop
cd ~/projhome/corrade
mkdir -p build && cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr ..
make

# Step 4 - Install Corrade
cmake --build . --target install

# Step 5 - Install magnum
cd ~/projhome
git clone git://github.com/mosra/magnum.git


# Step 6 - Compile magnum
cd ~/projhome/magnum
mkdir -p build && cd build
cmake .. \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DWITH_SDL2APPLICATION=ON
make
make install

# Step 7 - Compile magnum for emscripten
cd ~/projhome/magnum
git submodule init
git submodule update

mkdir -p build-emscripten && cd build-emscripten
cmake .. \
    -DCMAKE_MODULE_PATH="~/projhome/magnum/toolchains/modules" \
    -DCMAKE_TOOLCHAIN_FILE="../toolchains/generic/Emscripten.cmake" \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_PREFIX_PATH="/usr/lib/emscripten/system" \
    -DCMAKE_INSTALL_PREFIX="/usr/lib/emscripten/system" 
cmake --build .
cmake --build . --target install

mkdir -p build && cd build
cmake -DCMAKE_INSTALL_PREFIX=./ ..
make
make install

#Step 8 - Checkout and compile bootstrap project
cd ~/projhome
git clone https://github.com/mosra/magnum-bootstrap.git

cd ~/projhome/magnum-bootstrap/
git checkout base-emscripten
git submodule init
git submodule update
cd ~/projhome/magnum-bootstrap/
mkdir -p build-emscripten && cd build-emscripten
cmake .. \
-DCMAKE_MODULE_PATH="~/projhome/magnum/toolchains/modules" \
-DCMAKE_TOOLCHAIN_FILE="../toolchains/generic/Emscripten.cmake" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH="/usr/lib/emscripten/system" \
-DCMAKE_INSTALL_PREFIX="./bin" \
-DWITH_SDL2APPLICATION=ON
cmake --build .
make install
@mosra
Copy link
Owner

mosra commented Aug 26, 2015

Hi,

no, it's not an error on your side. It took me a while to realize what's wrong, but then I discovered that I updated only the magnum-examples repo after Emscripten introduced *.mem files and forgot about the bootstrap project. Sorry about that.

Adding the following line here should install also the memory file:

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/MyApplication.js.mem DESTINATION ${CMAKE_INSTALL_PREFIX} OPTIONAL)

Please confirm that this works for you, I'll commit the change to the bootstrap project after that.


Just some notes, regarding the script:

  • make and cmake --build . are equivalent, the same goes for make install and cmake --build . --target install. The CMake commands are just cross-platform wrappers around the native tool (so you can use them regardless of whether there is make, ninja or XCode project being generated)
  • The -DWITH_SDL2APPLICATION=ON has no meaning for Corrade (but it won't break anything, that's for sure)
  • You might want to remove the .git directory of the cloned bootstrap repo so you can start your new project afresh (without my ugly entangled history) -- or download the contents as an archive
cd ~/projhome/magnum-bootstrap
rm -rf .git
git init .
git submodule add git://github.com/mosra/toolchains.git toolchains

@mosra mosra self-assigned this Aug 26, 2015
@scottschafer
Copy link
Author

Thanks for the quick reply. Yes, adding that line fixed the problem with .mem not being copied over.

Suggestion: have you thought of making a simple project generator (where you could select which targets you wanted to generate for, etc)? That would make this much more frictionless.

Question #1: Is there a way to generate an XCode project from the command line?
Question #2: In my revised script below (cleaned per your suggestions), the samples don't seem to be getting built. Can you take another look? Thanks.

# Prerequisites:
#  - CMake installed (3.3.1)
#  - Directory ~/projhome created
#  - Emscripten installed to ~/projhome/emsdk_portable
#  - Symlink from /usr/lib/emscripten created to ~/projhome/emsdk_portable/emscripten/tag-1.34.6/
#      sudo ln -s ~/projhome/emsdk_portable/emscripten/tag-1.34.6/ /usr/lib/emscripten

# Step 1 - Install Corrade
cd ~/projhome
git clone git://github.com/mosra/corrade.git

# Step 2 - Compile and install Corrade for emscripten
cd ~/projhome/corrade
git submodule init
git submodule update

mkdir -p build-emscripten && cd build-emscripten
cmake .. \
    -DCMAKE_MODULE_PATH="~/projhome/corrade/toolchains/modules" \
    -DCMAKE_TOOLCHAIN_FILE="../toolchains/generic/Emscripten.cmake" \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX="/usr/lib/emscripten/system"
make install

# Step 3 - Compile and install Corrade for desktop
cd ~/projhome/corrade
mkdir -p build && cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr ..
make
make install

# Step 4 - Install magnum
cd ~/projhome
git clone git://github.com/mosra/magnum.git

# Step 5 - Compile magnum
cd ~/projhome/magnum
mkdir -p build && cd build
cmake .. \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DWITH_SDL2APPLICATION=ON
make
make install

# Step 6 - Compile magnum for emscripten
cd ~/projhome/magnum
git submodule init
git submodule update

mkdir -p build-emscripten && cd build-emscripten
cmake .. \
    -DCMAKE_MODULE_PATH="~/projhome/magnum/toolchains/modules" \
    -DCMAKE_TOOLCHAIN_FILE="../toolchains/generic/Emscripten.cmake" \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_PREFIX_PATH="/usr/lib/emscripten/system" \
    -DCMAKE_INSTALL_PREFIX="/usr/lib/emscripten/system" 
make
make install

# Step 7 - Compile and install Magnum for desktop
mkdir -p build && cd build
cmake -DCMAKE_INSTALL_PREFIX=./ ..
make
make install


#Step 8 - Checkout and compile bootstrap project
cd ~/projhome
git clone https://github.com/mosra/magnum-bootstrap.git

cd ~/projhome/magnum-bootstrap/
git checkout base-emscripten
git submodule init
git submodule update
rm -rf .git

cd ~/projhome/magnum-bootstrap/
mkdir -p build-emscripten && cd build-emscripten
cmake .. \
-DCMAKE_MODULE_PATH="~/projhome/magnum/toolchains/modules" \
-DCMAKE_TOOLCHAIN_FILE="../toolchains/generic/Emscripten.cmake" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH="/usr/lib/emscripten/system" \
-DCMAKE_INSTALL_PREFIX="./bin" \
-DWITH_SDL2APPLICATION=ON
make
make install


# Step 9 - Checkout and compile samples
cd ~/projhome
git clone https://github.com/mosra/magnum-examples.git
cd magnum-examples
git submodule init
git submodule update

cd ~/projhome/magnum-examples
mkdir -p build && cd build
cmake .. \
-DCMAKE_MODULE_PATH="~/projhome/magnum/toolchains/modules" \
-DCMAKE_TOOLCHAIN_FILE="../toolchains/generic/Emscripten.cmake" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH="/usr/lib/emscripten/system" \
-DCMAKE_INSTALL_PREFIX="./bin" \
-DWITH_SDL2APPLICATION=ON
make
make install

@mosra
Copy link
Owner

mosra commented Aug 26, 2015

have you thought of making a simple project generator (where you could select which targets you wanted to generate for, etc)? That would make this much more frictionless.

Can you be more specific? Do you mean some sort of wizard? There's CMake GUI which you can use instead of the command line, some IDEs also have some sort of CMake wizard integrated.

I have some kind of Git "superproject" planned, which would allow you to clone and build everything in single place, but there are tasks that have more priority now.

Is there a way to generate an XCode project from the command line?

Yes, passing -G XCode to CMake (it defaults to Unix Makefiles on OSX), see CMake documentation for more info.

In my revised script below (cleaned per your suggestions), the samples don't seem to be getting built. Can you take another look? Thanks.

Yeah, sorry, this is rather undocumented -- samples for Emscripten are in the ports branch (along with NaCl and Android port, I didn't put these in master to retain brevity). Additionally, only the triangle example is built by default, you have to enable the others explicitly using WITH_* options, see the docs for more info.

Currently only the viewer, triangle, textured-triangle, primitives and text ones are ported for Emscripten/WebGL 1, the others require some functionality that is available only on desktop or in WebGL 2, which is sadly not very usable in browsers at the moment (see e.g. mosra/magnum-examples#12) so they don't have any port yet.

@mosra
Copy link
Owner

mosra commented Sep 26, 2015

The installation was fixed some time ago in mosra/magnum-bootstrap@18ef849, closing as solved.

@mosra mosra closed this as completed Sep 26, 2015
@mosra mosra added this to the 2018.02 milestone Feb 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Platforms
  
Done
Development

No branches or pull requests

2 participants