Open paulocoutinhox opened 2 years ago
I made a PR to fix all and all is working nice now. https://github.com/mitsuba-renderer/nanogui/pull/108
You can use this example to download nanogui with CPM (cmake package manager):
# cpm
include(get_cpm.cmake)
# nanogui
set(NANOGUI_BUILD_EXAMPLES OFF CACHE BOOL " " FORCE)
set(NANOGUI_BUILD_PYTHON OFF CACHE BOOL " " FORCE)
set(NANOGUI_INSTALL OFF CACHE BOOL " " FORCE)
set(NANOGUI_BUILD_SHARED OFF CACHE BOOL " " FORCE)
set(NANOGUI_BUILD_GLFW OFF CACHE BOOL " " FORCE)
set(NANOGUI_BACKEND "GLES 3" CACHE STRING " " FORCE)
CPMAddPackage(
NAME
nanogui
GIT_TAG
wasm-fix
GITHUB_REPOSITORY
paulo-coutinho/nanogui
)
# add nanogui as project library
list(APPEND NATIVIUM_LIBRARY_LINKS "nanogui")
# add nano gui include as search path
nativium_add_search_path("${nanogui_SOURCE_DIR}/include")
And at least:
# wasm
set_target_properties(MY_PROJECT_NAME PROPERTIES LINK_FLAGS "-s EXPORTED_RUNTIME_METHODS=['ccall','cwrap'] --bind -s MALLOC=emmalloc -s WASM_BIGINT=1 -s USE_GLFW=3 -s ALLOW_MEMORY_GROWTH=1")
DEAD ... Found a better way... See next comment.
After much pain I was able to get this to build on OSX also...
You have to correct an issue with emscripten a. Open your version of emcc.py b. Find the run function ... "def run (args):" c Add these lines to the very top of the run function... Because of clang being installed these args are being passed to the emcc (em++) compilers and they don't don't how to handle them as of version 3.14. This just removes the illegal args.
for argv in [ '-Wl,-search_paths_first', '-Wl,-headerpad_max_install_names' ]:
if argv in args:
args.remove (argv)
d. Hard part is done.
Go into the nanogui directory.
Create a new directory called "web", or something appropriate; then cd to the directory.
cmake .. -DCMAKE_CXX_COMPILER=em++ -DCMAKE_C_COMPILER=emcc -Wno-dev
make
python3 -m http.server
In a webbrowser - http://127.0.0.1:8000/example1.html
Follow the instructions from this page... (summarized) https://emscripten.org/docs/getting_started/downloads.html
Checkout nanogui
Follow the instructions from this page... (summarized) https://emscripten.org/docs/getting_started/downloads.html
- git clone https://github.com/emscripten-core/emsdk.git
- cd emsdk
- git pull
- ./emsdk install latest (3.1.34)
- ./emsdk activate latest
- source
Checkout nanogui
- cd nanogui
- vi CMakelists.txt a. change set(CMAKE_EXECUTABLE_SUFFIX ".bc") -> set(CMAKE_EXECUTABLE_SUFFIX ".html") :: (optional, but I could not figure out how to run with out an *.html file) b. change set(CMAKE_CXX_CREATE_STATIC_LIBRARY "
-o ") -> set(CMAKE_CXX_CREATE_STATIC_LIBRARY " -r -o ") :: Will no produce a static library without it. c. add add_compile_options(-Wno-unused-command-line-argument) :: removes some warnings. - mkdir web
- cd web
- CXXFLAGS='-s USE_WEBGL2=1 -s USE_GLFW=3 -s WASM=1' emcmake cmake ..; emmake make
- python3 -m http.server
occur some errors, overzeus@gxf188 web]$ emmake make make: make [ 2%] Running bin2c [ 4%] Building C object CMakeFiles/nanogui.dir/ext/nanovg/src/nanovg.c.o clang: error: unsupported option '-march=' for target 'wasm32-unknown-emscripten' make[2]: [CMakeFiles/nanogui.dir/build.make:95:CMakeFiles/nanogui.dir/ext/nanovg/src/nanovg.c.o] error 1 make[1]: [CMakeFiles/Makefile2:93:CMakeFiles/nanogui.dir/all] error 2 make: *** [Makefile:136:all] error 2 emmake: error: 'make' failed (returned 2)
Do you have the correct version 3.1.34? The error sounds like you are trying to build on a mac and the "-march" is causing problems which the emsdk does not care about. My cmake building foo is not strong enough to know how to remove the "-march".
Do you have the correct version 3.1.34? The error sounds like you are trying to build on a mac and the "-march" is causing problems which the emsdk does not care about. My cmake building foo is not strong enough to know how to remove the "-march".
I build on windows(MingW64)
Do you have the correct version 3.1.34? The error sounds like you are trying to build on a mac and the "-march" is causing problems which the emsdk does not care about. My cmake building foo is not strong enough to know how to remove the "-march".
My emsdk version 3.1.54. I remove "-march" .I use your instructions "set(CMAKE_CXX_CREATE_STATIC_LIBRARY "
Once emsdk is installed I think you and do a "emsdk install 3.1.34" and then "emsdk activate 3.1.34", or something like that. I would give that a try first then if it does not work move forward.
Hello, I have problems with nanoGui on Webassembly on fresh linux/Debian 12 install (in a dedicated VM). This is my first experience with webassembly as well as with nanogui, however I know well C/C++ and gui dev. I suceeded in installing and using nanoGui with native intel C/C++ on my main Linux machine. Well. Debian 12 proposes a package with 3.1.6 and I did not succeed in installing nanoGui. So I created a VM with still Debian 12 (but no GUI) to avoid breaking my install. In installed emsdk from sources, and what comes is 3.1.56. To follow what is previously suggested, I tried to downgrade to 3.1.34 with "emsdk install 3.1.34" and here is what comes :
emsdk install 3.1.34
Resolving SDK version '3.1.34' to 'sdk-releases-2fdd6b9e5b67d5b62f84d0501a876513ff118ef1-64bit'
Installing SDK 'sdk-releases-2fdd6b9e5b67d5b62f84d0501a876513ff118ef1-64bit'..
Skipped installing node-16.20.0-64bit, already installed.
Installing tool 'releases-2fdd6b9e5b67d5b62f84d0501a876513ff118ef1-64bit'..
Error: Downloading URL 'https://storage.googleapis.com/webassembly/emscripten-releases-builds/linux/2fdd6b9e5b67d5b62f84d0501a876513ff118ef1/wasm-binaries.tar.xz': HTTP Error 404: Not Found
Error: Downloading URL 'https://storage.googleapis.com/webassembly/emscripten-releases-builds/linux/2fdd6b9e5b67d5b62f84d0501a876513ff118ef1/wasm-binaries.tbz2': [Errno 13] Permission denied: '/home/mmyara/emsdk/downloads/2fdd6b9e5b67d5b62f84d0501a876513ff118ef1-wasm-binaries.tbz2'
Error: Downloading URL 'https://storage.googleapis.com/webassembly/emscripten-releases-builds/linux/2fdd6b9e5b67d5b62f84d0501a876513ff118ef1/wasm-binaries.tar.xz': HTTP Error 404: Not Found
error: installation failed!
So I continued with 3.1.56. So I git the nanogui :
git clone https://github.com/wjakob/nanogui.git --recursive
I think since the post the nanogui has changed as I did not find any "march" for example in the CMakeLists.txt
then followed as proposed above with :
cd nanogui
mkdir web
cd web
CXXFLAGS='-s USE_WEBGL2=1 -s USE_GLFW=3 -s WASM=1' emcmake cmake ..; emmake make
and here follows what I get :
configure: cmake .. -DCMAKE_TOOLCHAIN_FILE=/home/mmyara/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_CROSSCOMPILING_EMULATOR=/home/mmyara/emsdk/node/16.20.0_64bit/bin/node
CMake Deprecation Warning at ext/glfw/CMakeLists.txt:5 (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.
-- Using X11 for window creation
CMake Error at /usr/share/cmake-3.25/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find X11 (missing: X11_X11_LIB)
Call Stack (most recent call first):
/usr/share/cmake-3.25/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.25/Modules/FindX11.cmake:481 (find_package_handle_standard_args)
ext/glfw/CMakeLists.txt:190 (find_package)
-- Configuring incomplete, errors occurred!
See also "/home/mmyara/nanogui/nanogui/web/CMakeFiles/CMakeOutput.log".
emcmake: error: 'cmake .. -DCMAKE_TOOLCHAIN_FILE=/home/mmyara/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_CROSSCOMPILING_EMULATOR=/home/mmyara/emsdk/node/16.20.0_64bit/bin/node' failed (returned 1)
make: make
make: *** Pas de cible spécifiée et aucun makefile n'a été trouvé. Arrêt.
emmake: error: 'make' failed (returned 2)
So it does not work. I tried to install X11 related dev libraries as it is the problem expressed : " sudo apt-get install cmake xorg-dev libglu1-mesa-dev", no more success. Can someone help ?
regards, Mike
Last time I touched the code was on 2023/03/15... Can you try the commit hash from before that date?
Here it is :
git rev-parse --verify HEAD
e9ec8a1a9861cf578d9c6e85a6420080aa715c03
I think I did not clone the good "nanogui" project. I try now with "mitsuba-render". Sorry. I will give news after try.
It is better this time but does not still work. I think the library builds ok, but not the examples. I did mainly what mischievous said :
a. change set(CMAKE_EXECUTABLE_SUFFIX ".bc") -> set(CMAKE_EXECUTABLE_SUFFIX ".html") :: (optional, but I could not figure out how to run with out an *.html file) b. change set(CMAKE_CXX_CREATE_STATIC_LIBRARY "
-o ") -> set(CMAKE_CXX_CREATE_STATIC_LIBRARY " -r -o ") :: Will no produce a static library without it. c. add add_compile_options(-Wno-unused-command-line-argument) :: removes some warnings.
also removed the "march" lines (79-91)
Then
mkdir web
cd web
CXXFLAGS='-s USE_WEBGL2=1 -s USE_GLFW=3 -s WASM=1' emcmake cmake ..; emmake make
and here is what I get :
[ 78%] Linking CXX static library libnanogui.bc
[ 78%] Built target nanogui
[ 80%] Building CXX object CMakeFiles/example1.dir/src/example1.cpp.o
[ 82%] Linking CXX executable example1.html
libnanogui.bc:1:2: error: expected top-level entity
1 | <U+0000>asm<U+0001><U+0000><U+0000><U+0000><U+0001><B8><U+0005>N`<U+0003><U+007F><U+007F><U+007F><U+0000>`<U+0003><U+007F><U+007F><U+007F><U+0001><U+007F>`<U+0001><U+007F><U+0000>`<U+0005><U+007F><U+007F><U+007F><U+007F><U+007F><U+0000>`<U+0005><U+007F><U+007F><U+007F><U+007F><U+007F><U+0001><U+007F>`<U+0006><U+007F><U+007F><U+007F><U+007F><U+007F><U+007F><U+0000>`<U+0001><U+007F><U+0001><U+007F>`<U+0002><U+007F><U+007F><U+0000>`<U+0006><U+007F><U+007F><U+007F><U+007F><U+007F><U+007F><U+0001><U+007F>`<U+0002><U+007F><U+007F><U+0001><U+007F>`<U+0004><U+007F>}}}<U+0000>`<U+0004><U+007F><U+007F><U+007F><U+007F><U+0001><U+007F>`<U+0007><U+007F><U+007F><U+007F><U+007F><U+007F><U+007F><U+007F><U+0001><U+007F>`<U+0008><U+007F><U+007F><U+007F><U+007F>}<U+007F><U+007F><U+007F><U+0000>`<U+0008><U+007F><U+007F><U+007F><U+007F>}}<U+007F><U+007F><U+0000>`<U+0004><U+007F><U+007F><U+007F><U+007F><U+0000>`<U+0001>}<U+0001>}`<U+0002>||<U+0001>|`<U+0002>}}<U+0001>}`<U+0002>|<U+007F><U+0001>|` <U+007F><U+007F><U+007F><U+007F><U+007F><U+007F><U+007F><U+007F><U+007F><U+0000>`<U+0000><U+0001><U+007F>`<U+0007><U+007F><U+007F><U+007F><U+007F><U+007F><U+007F><U+007F><U+0000>`<U+0002><U+007F>}<U+0000>`<U+0003><U+007F>}}<U+0000>`<U+0005><U+007F>}}}}<U+0000>`<U+0001>}<U+0000>`<U+0004>}}}}<U+0000>`<U+0001>|<U+0000>`<U+0000><U+0000>`<U+0000><U+0001>|`<U+0003><U+007F>||<U+0001><U+007F>`<U+0002><U+007F>}<U+0001>}`
| ^
1 error generated.
em++: error: '/home/mmyara/emsdk/upstream/bin/clang++ -target wasm32-unknown-emscripten -fignore-exceptions -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --sysroot=/home/mmyara/emsdk/upstream/emscripten/cache/sysroot -DEMSCRIPTEN -Xclang -iwithsysroot/include/fakesdl -Xclang -iwithsysroot/include/compat -O3 -DNDEBUG libnanogui.bc -c -o /tmp/emscripten_temp_hcg5y5ht/libnanogui_0.o' failed (returned 1)
make[2]: *** [CMakeFiles/example1.dir/build.make:101 : example1.html] Erreur 1
make[1]: *** [CMakeFiles/Makefile2:119 : CMakeFiles/example1.dir/all] Erreur 2
make: *** [Makefile:136 : all] Erreur 2
emmake: error: 'make' failed (returned 2)
As soon as I can scratch my head I will check the git hash I have and re-try with my instructions.
emsdk list
The recommended precompiled SDK download is 3.1.48 (694434b6d47c5f6eff2c8fbd9eeb016c977ae9dc).
To install/activate it use: latest
This is equivalent to installing/activating: 3.1.48
All recent (non-legacy) installable versions are: 3.1.48 3.1.48-asserts 3.1.47 3.1.47-asserts .... 3.1.35 3.1.35-asserts 3.1.34 INSTALLED 3.1.34-asserts 3.1.33
CXXFLAGS='-s USE_WEBGL2=1 -s USE_GLFW=3 -s WASM=1' emcmake cmake ..; emmake make configure: cmake .. -DCMAKE_TOOLCHAIN_FILE=/usr/local/Cellar/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_CROSSCOMPILING_EMULATOR=/usr/local/Cellar/emsdk/node/16.20.0_64bit/bin/node -- NanoGUI v0.2.0 -- Setting build type to 'Release' as none was specified. -- NanoGUI: using GLES 2 backend. -- NanoGUI: building static library. -- NanoGUI: not building the Python plugin. -- Configuring done (1.1s) -- Generating done (0.0s) -- Build files have been written to: /Volumes/Promise/projects/runeQuest/nanogui/web make: make [ 2%] Running bin2c CMake Deprecation Warning at /Volumes/Promise/projects/runeQuest/nanogui/resources/bin2c.cmake:1 (cmake_minimum_required): Compatibility with CMake < 3.5 will be removed from a future version of CMake.
Update the VERSION argument
[ 4%] Building C object CMakeFiles/nanogui.dir/ext/nanovg/src/nanovg.c.o [ 6%] Building CXX object CMakeFiles/nanogui.dir/src/texture_gl.cpp.o [ 8%] Building CXX object CMakeFiles/nanogui.dir/src/shader_gl.cpp.o [ 10%] Building CXX object CMakeFiles/nanogui.dir/src/renderpass_gl.cpp.o [ 13%] Building CXX object CMakeFiles/nanogui.dir/src/opengl.cpp.o [ 15%] Building CXX object CMakeFiles/nanogui.dir/nanogui_resources.cpp.o [ 17%] Building CXX object CMakeFiles/nanogui.dir/src/common.cpp.o [ 19%] Building CXX object CMakeFiles/nanogui.dir/src/widget.cpp.o [ 21%] Building CXX object CMakeFiles/nanogui.dir/src/theme.cpp.o [ 23%] Building CXX object CMakeFiles/nanogui.dir/src/layout.cpp.o [ 26%] Building CXX object CMakeFiles/nanogui.dir/src/screen.cpp.o [ 28%] Building CXX object CMakeFiles/nanogui.dir/src/label.cpp.o [ 30%] Building CXX object CMakeFiles/nanogui.dir/src/window.cpp.o [ 32%] Building CXX object CMakeFiles/nanogui.dir/src/popup.cpp.o [ 34%] Building CXX object CMakeFiles/nanogui.dir/src/checkbox.cpp.o [ 36%] Building CXX object CMakeFiles/nanogui.dir/src/button.cpp.o [ 39%] Building CXX object CMakeFiles/nanogui.dir/src/popupbutton.cpp.o [ 41%] Building CXX object CMakeFiles/nanogui.dir/src/combobox.cpp.o [ 43%] Building CXX object CMakeFiles/nanogui.dir/src/progressbar.cpp.o [ 45%] Building CXX object CMakeFiles/nanogui.dir/src/slider.cpp.o [ 47%] Building CXX object CMakeFiles/nanogui.dir/src/messagedialog.cpp.o [ 50%] Building CXX object CMakeFiles/nanogui.dir/src/textbox.cpp.o [ 52%] Building CXX object CMakeFiles/nanogui.dir/src/textarea.cpp.o [ 54%] Building CXX object CMakeFiles/nanogui.dir/src/imagepanel.cpp.o [ 56%] Building CXX object CMakeFiles/nanogui.dir/src/vscrollpanel.cpp.o [ 58%] Building CXX object CMakeFiles/nanogui.dir/src/colorwheel.cpp.o [ 60%] Building CXX object CMakeFiles/nanogui.dir/src/colorpicker.cpp.o [ 63%] Building CXX object CMakeFiles/nanogui.dir/src/graph.cpp.o [ 65%] Building CXX object CMakeFiles/nanogui.dir/src/tabwidget.cpp.o [ 67%] Building CXX object CMakeFiles/nanogui.dir/src/canvas.cpp.o [ 69%] Building CXX object CMakeFiles/nanogui.dir/src/texture.cpp.o [ 71%] Building CXX object CMakeFiles/nanogui.dir/src/shader.cpp.o [ 73%] Building CXX object CMakeFiles/nanogui.dir/src/imageview.cpp.o [ 76%] Building CXX object CMakeFiles/nanogui.dir/src/traits.cpp.o [ 78%] Linking CXX static library libnanogui.bc [ 78%] Built target nanogui [ 80%] Building CXX object CMakeFiles/example1.dir/src/example1.cpp.o [ 82%] Linking CXX executable example1.html [ 82%] Built target example1 [ 84%] Building CXX object CMakeFiles/example2.dir/src/example2.cpp.o [ 86%] Linking CXX executable example2.html [ 86%] Built target example2 [ 89%] Building CXX object CMakeFiles/example3.dir/src/example3.cpp.o [ 91%] Linking CXX executable example3.html [ 91%] Built target example3 [ 93%] Building CXX object CMakeFiles/example4.dir/src/example4.cpp.o [ 95%] Linking CXX executable example4.html [ 95%] Built target example4 [ 97%] Building CXX object CMakeFiles/example_icons.dir/src/example_icons.cpp.o [100%] Linking CXX executable example_icons.html [100%] Built target example_icons
git hash... git rev-parse HEAD 2ee903c96480d4aee54542ea3c340c13cc06dc32
If you are getting failures in the 3 files below I can do a diff and see what I changed but I think the only change was in CMakeLists.txt
git status On branch master Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add
Hello, Thanks to your help I suceeded in compiling everything ! Just something was wrong : emcc "latest" is NOT 3.1.48, it is 3.1.56, and with 3.1.56 it does not work at link time, did not understand why. Here is what I did :
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install 3.1.48
./emsdk activate 3.1.48
source ./emsdk_env.sh
cd ..
git clone https://github.com/mitsuba-renderer/nanogui.git --recursive
cd nanogui
For other users : please notice that at this time the last commit is 8 March 2023 (2ee903c96480d4aee54542ea3c340c13cc06dc32).
Then had to change the CMakeLists.txt including points a,b and c, as discussed before in this thread. I enclose a CMakeLists.txt file ready to work with this message, so that other users only have to copy it : CMakeLists.txt
Then :
mkdir web
cd web
CXXFLAGS='-s USE_WEBGL2=1 -s USE_GLFW=3 -s WASM=1' emcmake cmake ..; emmake make
Then start a python webserver to test :
python3 -m http.server
Then everything is ok. Thanks a lot ! I will be able now to start my project.
Just a remark, don't know if it's normal, but, in webassembly context :
Best Regards, Mike
Hi,
I found this problems when compile to WASM:
1 - This line throw error that
GLFW_SCALE_TO_MONITOR
don't exists (screen.cpp):2 - This method
glfwSetWindowContentScaleCallback
throw error that don't exists (screen.cpp):3 - Adding a fixed suffix
.bc
don't work on emsdk: