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

Use EmscriptenApplication for emscripten ports #59

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 47 additions & 43 deletions modules/FindMagnum.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
# TextureTools - TextureTools library
# Trade - Trade library
# Vk - Vk library
# AndroidApplication - Android application
mosra marked this conversation as resolved.
Show resolved Hide resolved
# EmscriptenApplication - Emscripten application
# GlfwApplication - GLFW application
# GlxApplication - GLX application
# Sdl2Application - SDL2 application
Expand Down Expand Up @@ -260,6 +262,14 @@ foreach(_magnumFlag ${_magnumFlags})
endif()
endforeach()

# OpenGL library preference. Prefer to use GLVND, since that's the better
# approach nowadays, but allow the users to override it from outside in case
# it is broken for some reason (Nvidia drivers in Debian's testing (Buster) --
# reported on 2019-04-09).
if(NOT CMAKE_VERSION VERSION_LESS 3.10 AND NOT OpenGL_GL_PREFERENCE)
set(OpenGL_GL_PREFERENCE GLVND)
endif()

# Base Magnum library
if(NOT TARGET Magnum::Magnum)
add_library(Magnum::Magnum UNKNOWN IMPORTED)
Expand Down Expand Up @@ -330,10 +340,10 @@ endif()
set(_MAGNUM_LIBRARY_COMPONENT_LIST
Audio DebugTools GL MeshTools Primitives SceneGraph Shaders Text
TextureTools Trade Vk
AndroidApplication GlfwApplication GlxApplication Sdl2Application
XEglApplication WindowlessCglApplication WindowlessEglApplication
WindowlessGlxApplication WindowlessIosApplication WindowlessWglApplication
WindowlessWindowsEglApplication
AndroidApplication EmscriptenApplication GlfwApplication GlxApplication
Sdl2Application XEglApplication WindowlessCglApplication
WindowlessEglApplication WindowlessGlxApplication WindowlessIosApplication
WindowlessWglApplication WindowlessWindowsEglApplication
CglContext EglContext GlxContext WglContext
OpenGLTester)
set(_MAGNUM_PLUGIN_COMPONENT_LIST
Expand Down Expand Up @@ -402,6 +412,10 @@ endif()

set(_MAGNUM_Trade_DEPENDENCIES )
set(_MAGNUM_AndroidApplication_DEPENDENCIES GL)
set(_MAGNUM_EmscriptenApplication_DEPENDENCIES)
if(MAGNUM_TARGET_GL)
list(APPEND _MAGNUM_EmscriptenApplication_DEPENDENCIES GL)
endif()

set(_MAGNUM_GlfwApplication_DEPENDENCIES )
if(MAGNUM_TARGET_GL)
Expand Down Expand Up @@ -542,11 +556,17 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
set(CMAKE_FIND_LIBRARY_PREFIXES "${CMAKE_FIND_LIBRARY_PREFIXES};")

# Try to find both debug and release version. Dynamic and static
# debug libraries are in different places.
find_library(MAGNUM_${_COMPONENT}_LIBRARY_DEBUG ${_component}
PATH_SUFFIXES magnum-d/${_MAGNUM_${_COMPONENT}_PATH_SUFFIX})
# debug libraries are in different places. Static debug plugins are
# in magnum/ with a -d suffix while dynamic debug plugins are in
# magnum-d/ with no suffix. Problem is that Vcpkg's library linking
# automagic needs the static libs to be in the root library
# directory along with everything else and so we need to search for
# the -d suffixed version *before* the unsuffixed so it doesn't
# pick the release library for both debug and release.
find_library(MAGNUM_${_COMPONENT}_LIBRARY_DEBUG ${_component}-d
PATH_SUFFIXES magnum/${_MAGNUM_${_COMPONENT}_PATH_SUFFIX})
find_library(MAGNUM_${_COMPONENT}_LIBRARY_DEBUG ${_component}
PATH_SUFFIXES magnum-d/${_MAGNUM_${_COMPONENT}_PATH_SUFFIX})
find_library(MAGNUM_${_COMPONENT}_LIBRARY_RELEASE ${_component}
PATH_SUFFIXES magnum/${_MAGNUM_${_COMPONENT}_PATH_SUFFIX})
mark_as_advanced(MAGNUM_${_COMPONENT}_LIBRARY_DEBUG
Expand Down Expand Up @@ -618,12 +638,13 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
# our own EGL find module, which makes things simpler. The
# upstream FindOpenGL is anything but simple. Also can't use
# OpenGL_OpenGL_FOUND, because that one is set also if GLVND is
# *not* found. WTF.
# *not* found. WTF. Also can't just check for
# OPENGL_opengl_LIBRARY because that's set even if
# OpenGL_GL_PREFERENCE is explicitly set to LEGACY.
if(MAGNUM_TARGET_GL)
if(CORRADE_TARGET_UNIX AND NOT CORRADE_TARGET_APPLE AND (NOT MAGNUM_TARGET_GLES OR MAGNUM_TARGET_DESKTOP_GLES))
set(OpenGL_GL_PREFERENCE GLVND)
find_package(OpenGL)
if(OPENGL_opengl_LIBRARY)
if(OPENGL_opengl_LIBRARY AND OpenGL_GL_PREFERENCE STREQUAL GLVND)
set_property(TARGET Magnum::${_component} APPEND
PROPERTY INTERFACE_LINK_LIBRARIES OpenGL::GLX)
endif()
Expand Down Expand Up @@ -656,33 +677,13 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
# our own EGL find module, which makes things simpler. The
# upstream FindOpenGL is anything but simple. Also can't use
# OpenGL_OpenGL_FOUND, because that one is set also if GLVND is
# *not* found. WTF.
if(MAGNUM_TARGET_GL)
if(CORRADE_TARGET_UNIX AND NOT CORRADE_TARGET_APPLE AND (NOT MAGNUM_TARGET_GLES OR MAGNUM_TARGET_DESKTOP_GLES))
set(OpenGL_GL_PREFERENCE GLVND)
find_package(OpenGL)
if(OPENGL_opengl_LIBRARY)
set_property(TARGET Magnum::${_component} APPEND
PROPERTY INTERFACE_LINK_LIBRARIES OpenGL::GLX)
endif()
elseif(MAGNUM_TARGET_GLES AND NOT MAGNUM_TARGET_DESKTOP_GLES AND NOT CORRADE_TARGET_EMSCRIPTEN)
find_package(EGL)
set_property(TARGET Magnum::${_component} APPEND
PROPERTY INTERFACE_LINK_LIBRARIES EGL::EGL)
endif()
endif()

# With GLVND (since CMake 3.11) we need to explicitly link to
# GLX/EGL because libOpenGL doesn't provide it. For EGL we have
# our own EGL find module, which makes things simpler. The
# upstream FindOpenGL is anything but simple. Also can't use
# OpenGL_OpenGL_FOUND, because that one is set also if GLVND is
# *not* found. WTF.
# *not* found. WTF. Also can't just check for
# OPENGL_opengl_LIBRARY because that's set even if
# OpenGL_GL_PREFERENCE is explicitly set to LEGACY.
if(MAGNUM_TARGET_GL)
if(CORRADE_TARGET_UNIX AND NOT CORRADE_TARGET_APPLE AND (NOT MAGNUM_TARGET_GLES OR MAGNUM_TARGET_DESKTOP_GLES))
set(OpenGL_GL_PREFERENCE GLVND)
find_package(OpenGL)
if(OPENGL_opengl_LIBRARY)
if(OPENGL_opengl_LIBRARY AND OpenGL_GL_PREFERENCE STREQUAL GLVND)
set_property(TARGET Magnum::${_component} APPEND
PROPERTY INTERFACE_LINK_LIBRARIES OpenGL::GLX)
endif()
Expand All @@ -704,10 +705,11 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
# With GLVND (since CMake 3.11) we need to explicitly link to
# GLX because libOpenGL doesn't provide it. Also can't use
# OpenGL_OpenGL_FOUND, because that one is set also if GLVND is
# *not* found. WTF.
set(OpenGL_GL_PREFERENCE GLVND)
# *not* found. WTF. Also can't just check for
# OPENGL_opengl_LIBRARY because that's set even if
# OpenGL_GL_PREFERENCE is explicitly set to LEGACY.
find_package(OpenGL)
if(OPENGL_opengl_LIBRARY)
if(OPENGL_opengl_LIBRARY AND OpenGL_GL_PREFERENCE STREQUAL GLVND)
set_property(TARGET Magnum::${_component} APPEND PROPERTY
INTERFACE_LINK_LIBRARIES OpenGL::GLX)
endif()
Expand Down Expand Up @@ -757,10 +759,11 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
# With GLVND (since CMake 3.11) we need to explicitly link to
# GLX because libOpenGL doesn't provide it. Also can't use
# OpenGL_OpenGL_FOUND, because that one is set also if GLVND is
# *not* found. If GLVND is not used, link to X11 instead.
set(OpenGL_GL_PREFERENCE GLVND)
# *not* found. If GLVND is not used, link to X11 instead. Also
# can't just check for OPENGL_opengl_LIBRARY because that's set
# even if OpenGL_GL_PREFERENCE is explicitly set to LEGACY.
find_package(OpenGL)
if(OPENGL_opengl_LIBRARY)
if(OPENGL_opengl_LIBRARY AND OpenGL_GL_PREFERENCE STREQUAL GLVND)
set_property(TARGET Magnum::${_component} APPEND PROPERTY
INTERFACE_LINK_LIBRARIES OpenGL::GLX)
else()
Expand Down Expand Up @@ -801,10 +804,11 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
# imported target. Otherwise (and also on all systems except
# Linux) link to the classic libGL. Can't use
# OpenGL_OpenGL_FOUND, because that one is set also if GLVND is
# *not* found. WTF.
set(OpenGL_GL_PREFERENCE GLVND)
# *not* found. WTF. Also can't just check for
# OPENGL_opengl_LIBRARY because that's set even if
# OpenGL_GL_PREFERENCE is explicitly set to LEGACY.
find_package(OpenGL REQUIRED)
if(OPENGL_opengl_LIBRARY)
if(OPENGL_opengl_LIBRARY AND OpenGL_GL_PREFERENCE STREQUAL GLVND)
set_property(TARGET Magnum::${_component} APPEND PROPERTY
INTERFACE_LINK_LIBRARIES OpenGL::OpenGL)
else()
Expand Down
4 changes: 4 additions & 0 deletions src/arealights/AreaLightsExample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@
#include <Magnum/GL/Texture.h>
#include <Magnum/GL/TextureFormat.h>
#include <Magnum/GL/Version.h>
#ifdef CORRADE_TARGET_EMSCRIPTEN
#include <Magnum/Platform/EmscriptenApplication.h>
#else
#include <Magnum/Platform/Sdl2Application.h>
#endif
#include <Magnum/Shaders/Flat.h>
#include <Magnum/Text/Alignment.h>
#include <Magnum/Trade/AbstractImporter.h>
Expand Down
6 changes: 4 additions & 2 deletions src/arealights/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@ endif()
find_package(Magnum REQUIRED
GL
Shaders
Trade
Sdl2Application)
Trade)
find_package(MagnumExtras REQUIRED Ui)

if(CORRADE_TARGET_EMSCRIPTEN)
find_package(Magnum REQUIRED EmscriptenApplication)
find_package(MagnumPlugins REQUIRED
DdsImporter
StbTrueTypeFont)
else()
find_package(Magnum REQUIRED Sdl2Application)
endif()

set_directory_properties(PROPERTIES CORRADE_USE_PEDANTIC_FLAGS ON)
Expand Down
6 changes: 5 additions & 1 deletion src/audio/AudioExample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@
#include <Magnum/GL/Mesh.h>
#include <Magnum/GL/Renderer.h>
#include <Magnum/MeshTools/Compile.h>
#ifdef CORRADE_TARGET_EMSCRIPTEN
#include <Magnum/Platform/EmscriptenApplication.h>
#else
#include <Magnum/Platform/Sdl2Application.h>
#endif
#include <Magnum/Primitives/Cone.h>
#include <Magnum/Primitives/Cylinder.h>
#include <Magnum/Shaders/Flat.h>
Expand Down Expand Up @@ -180,8 +184,8 @@ AudioExample::AudioExample(const Arguments& arguments):
Debug{} << "HRTF specifier:" << _context.hrtfSpecifierString();

/* Loop at 60 Hz max */
setSwapInterval(1);
#ifndef CORRADE_TARGET_EMSCRIPTEN
setSwapInterval(1);
setMinimalLoopPeriod(16);
#endif
}
Expand Down
6 changes: 4 additions & 2 deletions src/audio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ find_package(Magnum REQUIRED
Primitives
SceneGraph
Shaders
Trade
Sdl2Application)
Trade)

if(CORRADE_TARGET_EMSCRIPTEN)
find_package(Magnum REQUIRED EmscriptenApplication)
find_package(MagnumPlugins REQUIRED StbVorbisAudioImporter)
else()
find_package(Magnum REQUIRED Sdl2Application)
endif()

set_directory_properties(PROPERTIES CORRADE_USE_PEDANTIC_FLAGS ON)
Expand Down
7 changes: 7 additions & 0 deletions src/box2d/Box2DExample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@
#include <Magnum/Math/ConfigurationValue.h>
#include <Magnum/Math/DualComplex.h>
#include <Magnum/MeshTools/Compile.h>
#ifdef CORRADE_TARGET_EMSCRIPTEN
#include <Magnum/Platform/EmscriptenApplication.h>
#else
#include <Magnum/Platform/Sdl2Application.h>
#endif
#include <Magnum/Primitives/Square.h>
#include <Magnum/SceneGraph/Camera.h>
#include <Magnum/SceneGraph/Drawable.h>
Expand Down Expand Up @@ -166,7 +170,10 @@ Box2DExample::Box2DExample(const Arguments& arguments): Platform::Application{ar
}
}

#ifndef CORRADE_TARGET_EMSCRIPTEN
setSwapInterval(1);
#endif

#if !defined(CORRADE_TARGET_EMSCRIPTEN) && !defined(CORRADE_TARGET_ANDROID)
setMinimalLoopPeriod(16);
#endif
Expand Down
8 changes: 7 additions & 1 deletion src/box2d/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,17 @@ find_package(Magnum REQUIRED
MeshTools
Primitives
SceneGraph
Sdl2Application
Shaders
Trade)
find_package(Box2D REQUIRED)

if(CORRADE_TARGET_EMSCRIPTEN)
find_package(Magnum REQUIRED EmscriptenApplication)
find_package(MagnumPlugins REQUIRED StbVorbisAudioImporter)
else()
find_package(Magnum REQUIRED Sdl2Application)
endif()

set_directory_properties(PROPERTIES CORRADE_USE_PEDANTIC_FLAGS ON)

add_executable(magnum-box2d Box2DExample.cpp)
Expand Down
6 changes: 5 additions & 1 deletion src/bullet/BulletExample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@
#include <Magnum/Math/Constants.h>
#include <Magnum/MeshTools/Compile.h>
#include <Magnum/MeshTools/Transform.h>
#ifdef CORRADE_TARGET_EMSCRIPTEN
#include <Magnum/Platform/EmscriptenApplication.h>
#else
#include <Magnum/Platform/Sdl2Application.h>
#endif
#include <Magnum/Primitives/Cube.h>
#include <Magnum/Primitives/UVSphere.h>
#include <Magnum/SceneGraph/Camera.h>
Expand Down Expand Up @@ -215,8 +219,8 @@ BulletExample::BulletExample(const Arguments& arguments): Platform::Application(
}

/* Loop at 60 Hz max */
setSwapInterval(1);
#ifndef CORRADE_TARGET_EMSCRIPTEN
setSwapInterval(1);
setMinimalLoopPeriod(16);
#endif
_timeline.start();
Expand Down
7 changes: 6 additions & 1 deletion src/bullet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@ find_package(Magnum REQUIRED
MeshTools
Primitives
SceneGraph
Sdl2Application
Shaders
Trade)
find_package(MagnumIntegration REQUIRED Bullet)

if(CORRADE_TARGET_EMSCRIPTEN)
find_package(Magnum REQUIRED EmscriptenApplication)
else()
find_package(Magnum REQUIRED Sdl2Application)
endif()

set_directory_properties(PROPERTIES CORRADE_USE_PEDANTIC_FLAGS ON)

add_executable(magnum-bullet BulletExample.cpp)
Expand Down
10 changes: 9 additions & 1 deletion src/imgui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,17 @@ if(PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/../../modules/")
endif()

find_package(Magnum REQUIRED GL Sdl2Application)
find_package(Magnum REQUIRED GL)
find_package(MagnumIntegration REQUIRED ImGui)

if(CORRADE_TARGET_ANDROID)
find_package(Magnum REQUIRED AndroidApplication)
elseif(CORRADE_TARGET_EMSCRIPTEN)
find_package(Magnum REQUIRED EmscriptenApplication)
else()
find_package(Magnum REQUIRED Sdl2Application)
endif()

set_directory_properties(PROPERTIES CORRADE_USE_PEDANTIC_FLAGS ON)

# Bundle a better font
Expand Down
2 changes: 2 additions & 0 deletions src/imgui/ImGuiExample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

#ifdef CORRADE_TARGET_ANDROID
#include <Magnum/Platform/AndroidApplication.h>
#elif defined(CORRADE_TARGET_EMSCRIPTEN)
#include <Magnum/Platform/EmscriptenApplication.h>
#else
#include <Magnum/Platform/Sdl2Application.h>
#endif
Expand Down
9 changes: 7 additions & 2 deletions src/mouseinteraction/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,13 @@ find_package(Magnum REQUIRED
MeshTools
Primitives
SceneGraph
Shaders
Sdl2Application)
Shaders)

if(CORRADE_TARGET_EMSCRIPTEN)
find_package(Magnum REQUIRED EmscriptenApplication)
else()
find_package(Magnum REQUIRED Sdl2Application)
endif()

set_directory_properties(PROPERTIES CORRADE_USE_PEDANTIC_FLAGS ON)

Expand Down
4 changes: 4 additions & 0 deletions src/mouseinteraction/MouseInteractionExample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@
#include <Magnum/GL/Renderer.h>
#include <Magnum/Math/FunctionsBatch.h>
#include <Magnum/MeshTools/Compile.h>
#ifdef CORRADE_TARGET_EMSCRIPTEN
#include <Magnum/Platform/EmscriptenApplication.h>
#else
#include <Magnum/Platform/Sdl2Application.h>
#endif
#include <Magnum/Primitives/Grid.h>
#include <Magnum/SceneGraph/Camera.h>
#include <Magnum/SceneGraph/Drawable.h>
Expand Down
9 changes: 7 additions & 2 deletions src/picking/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ find_package(Magnum REQUIRED
GL
MeshTools
Primitives
SceneGraph
Sdl2Application)
SceneGraph)

if(CORRADE_TARGET_EMSCRIPTEN)
find_package(Magnum REQUIRED EmscriptenApplication)
else()
find_package(Magnum REQUIRED Sdl2Application)
endif()

project(MagnumPickingExample)

Expand Down
Loading