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

[magnum] Builds for emsdk #7412

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions recipes/magnum/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@ sources:
"2020.06":
url: "https://github.com/mosra/magnum/archive/refs/tags/v2020.06.tar.gz"
sha256: "98dfe802e56614e4e6bf750d9b693de46a5ed0c6eb479b0268f1a20bf34268bf"
patches:
"2020.06":
- base_path: "source_subfolder"
patch_file: "patches/2020.06/0001-emscripten-toolchain.patch"
# patch_type: "portability"
# description: "Remove unnecessary dependency on UseEmscripten"
# source: "https://github.com/mosra/magnum/issues/490"
jgsogo marked this conversation as resolved.
Show resolved Hide resolved
73 changes: 59 additions & 14 deletions recipes/magnum/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class MagnumConan(ConanFile):
"wav_audio_importer": True,
}
generators = "cmake", "cmake_find_package"
exports_sources = ["CMakeLists.txt", "cmake/*"]
exports_sources = ["CMakeLists.txt", "cmake/*", "patches/*"]

_cmake = None

Expand Down Expand Up @@ -190,6 +190,48 @@ def config_options(self):
del self.options.windowless_windows_egl_application
del self.options.target_headless # Requires EGL (when used gl_info)

if self.settings.os == "Emscripten":
self.options.shared_plugins = False
self.options.target_gl = "desktop_gl" # FIXME: Should be gles2?

self.options.sdl2_application = False # FIXME: Fails to build (because of target_gl value? Needs emscripten-port?)

self.options.gl_info = False

del self.options.vk
del self.options.target_vk

self.options.audio = False
self.options.any_audio_importer = False
self.options.wav_audio_importer = False
self.options.al_info = False

self.options.glfw_application = False

# X11 is not available
jgsogo marked this conversation as resolved.
Show resolved Hide resolved
del self.options.glx_context
del self.options.glx_application
del self.options.windowless_glx_application

# Some executables
del self.options.font_converter
del self.options.distance_field_converter
del self.options.scene_converter
del self.options.image_converter

# Because of OpenGLFunctionLoader.cpp (because of target_gl option?)
self.options.wgl_context = False
self.options.windowless_wgl_application = False
self.options.cgl_context = False
self.options.windowless_cgl_application = False

# FIXME: Disable EGL, Conan provides only Linux and FreeBSD (depends on build platform?)
self.options.egl_context = False
self.options.xegl_application = False
self.options.windowless_egl_application = False
self.options.windowless_windows_egl_application = False
self.options.target_headless = False

if self.settings.os != "Android":
del self.options.android_application

Expand Down Expand Up @@ -220,7 +262,7 @@ def requirements(self):
self.requires("openal/1.21.1")
if self.options.gl:
self.requires("opengl/system")
if self.options.vk:
if self.options.get_safe("vk", False):
self.requires("vulkan-loader/1.2.190")

if self.options.get_safe("egl_context", False) or \
Expand Down Expand Up @@ -260,7 +302,7 @@ def validate(self):
if self.options.target_gl in ["gles2", "gles3"] and self.settings.os == "Windows":
raise ConanInvalidConfiguration("OpenGL ES is not supported in Windows")

if not self.options.vk and self.options.target_vk:
if not self.options.get_safe("vk", False) and self.options.get_safe("target_vk", False):
raise ConanInvalidConfiguration("Option 'vk=True' is required")

if self.options.get_safe("cgl_context", False) and not self.options.target_gl:
Expand All @@ -269,8 +311,8 @@ def validate(self):
if self.options.get_safe("windowless_cgl_application", False) and not self.options.target_gl:
raise ConanInvalidConfiguration("Option 'windowless_cgl_application' requires some 'target_gl'")

if self.options.al_info and not self.options.audio:
raise ConanInvalidConfiguration("Option 'al_info' requires 'audio=True'")
if (self.options.al_info or self.options.wav_audio_importer) and not self.options.audio:
raise ConanInvalidConfiguration("Options 'al_info' and 'wav_audio_importer' require 'audio=True'")

if self.options.magnum_font_converter and not self.options.tga_image_converter:
raise ConanInvalidConfiguration("magnum_font_converter requires tga_image_converter")
Expand All @@ -297,7 +339,7 @@ def _configure_cmake(self):
self._cmake.definitions["TARGET_GLES2"] = self.options.target_gl == "gles2"
self._cmake.definitions["TARGET_DESKTOP_GLES"] = self.options.target_gl == "desktop_gl"
self._cmake.definitions["TARGET_HEADLESS"] = self.options.get_safe("target_headless", False)
self._cmake.definitions["TARGET_VK"] = self.options.target_vk
self._cmake.definitions["TARGET_VK"] = self.options.get_safe("target_vk", False)

self._cmake.definitions["WITH_AUDIO"] = self.options.audio
self._cmake.definitions["WITH_DEBUGTOOLS"] = self.options.debug_tools
Expand All @@ -309,7 +351,7 @@ def _configure_cmake(self):
self._cmake.definitions["WITH_TEXT"] = self.options.text
self._cmake.definitions["WITH_TEXTURETOOLS"] = self.options.texture_tools
self._cmake.definitions["WITH_TRADE"] = self.options.trade
self._cmake.definitions["WITH_VK"] = self.options.vk
self._cmake.definitions["WITH_VK"] = self.options.get_safe("vk", False)

self._cmake.definitions["WITH_ANDROIDAPPLICATION"] = self.options.get_safe("android_application", False)
self._cmake.definitions["WITH_EMSCRIPTENAPPLICATION"] = self.options.get_safe("emscripten_application", False)
Expand All @@ -326,7 +368,7 @@ def _configure_cmake(self):

self._cmake.definitions["WITH_CGLCONTEXT"] = self.options.get_safe("cgl_context", False)
self._cmake.definitions["WITH_EGLCONTEXT"] = self.options.get_safe("egl_context", False)
self._cmake.definitions["WITH_GLXCONTEXT"] = self.options.glx_context
self._cmake.definitions["WITH_GLXCONTEXT"] = self.options.get_safe("glx_context", False)
self._cmake.definitions["WITH_WGLCONTEXT"] = self.options.get_safe("wgl_context", False)

##### Plugins related #####
Expand All @@ -346,9 +388,9 @@ def _configure_cmake(self):
self._cmake.definitions["WITH_GL_INFO"] = self.options.gl_info
self._cmake.definitions["WITH_AL_INFO"] = self.options.al_info
self._cmake.definitions["WITH_DISTANCEFIELDCONVERTER"] = self.options.get_safe("distance_field_converter", False)
self._cmake.definitions["WITH_FONTCONVERTER"] = self.options.font_converter
self._cmake.definitions["WITH_IMAGECONVERTER"] = self.options.image_converter
self._cmake.definitions["WITH_SCENECONVERTER"] = self.options.scene_converter
self._cmake.definitions["WITH_FONTCONVERTER"] = self.options.get_safe("font_converter", False)
self._cmake.definitions["WITH_IMAGECONVERTER"] = self.options.get_safe("image_converter", False)
self._cmake.definitions["WITH_SCENECONVERTER"] = self.options.get_safe("scene_converter", False)

self._cmake.configure()
return self._cmake
Expand Down Expand Up @@ -531,7 +573,7 @@ def package_info(self):
self.cpp_info.components["trade"].requires = ["magnum_main", "corrade::plugin_manager"]

# VK
if self.options.vk:
if self.options.get_safe("vk", False):
self.cpp_info.components["vk"].names["cmake_find_package"] = "Vk"
self.cpp_info.components["vk"].names["cmake_find_package_multi"] = "Vk"
self.cpp_info.components["vk"].libs = ["MagnumVk{}".format(lib_suffix)]
Expand All @@ -543,7 +585,10 @@ def package_info(self):
raise Exception("Recipe doesn't define this component")

if self.options.get_safe("emscripten_application", False):
raise Exception("Recipe doesn't define this component")
self.cpp_info.components["emscripten_application"].names["cmake_find_package"] = "EmscriptenApplication"
self.cpp_info.components["emscripten_application"].names["cmake_find_package_multi"] = "EmscriptenApplication"
self.cpp_info.components["emscripten_application"].libs = ["MagnumEmscriptenApplication{}".format(lib_suffix)]
self.cpp_info.components["emscripten_application"].requires = ["gl"]

if self.options.get_safe("windowless_ios_application", False):
raise Exception("Recipe doesn't define this component")
Expand Down Expand Up @@ -623,7 +668,7 @@ def package_info(self):
self.cpp_info.components["egl_context"].libs = ["MagnumEglContext{}".format(lib_suffix)]
self.cpp_info.components["egl_context"].requires = ["gl", "egl::egl"]

if self.options.glx_context:
if self.options.get_safe("glx_context", False):
self.cpp_info.components["glx_context"].names["cmake_find_package"] = "GlxContext"
self.cpp_info.components["glx_context"].names["cmake_find_package_multi"] = "GlxContext"
self.cpp_info.components["glx_context"].libs = ["MagnumGlxContext{}".format(lib_suffix)]
Expand Down
15 changes: 15 additions & 0 deletions recipes/magnum/all/patches/2020.06/0001-emscripten-toolchain.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 19e6c2d..feda9a4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -276,10 +276,6 @@ if(TARGET_VK)
set(MAGNUM_TARGET_VK 1)
endif()

-if(CORRADE_TARGET_EMSCRIPTEN)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not needed? what does UseEmscripten do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The source of the patch is documented, and the reasons are explained by the library author himself: mosra/magnum#490. Basically he was providing his own Emscripten toolchain in the past because the official ones were quite unstable. New versions already remove this custom toolchain.

- include(UseEmscripten)
-endif()
-
if(WITH_OPENGLTESTER)
if(MAGNUM_TARGET_HEADLESS OR CORRADE_TARGET_EMSCRIPTEN OR CORRADE_TARGET_ANDROID)
set(WITH_WINDOWLESSEGLAPPLICATION ON)
8 changes: 8 additions & 0 deletions recipes/magnum/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ set_target_properties(${PROJECT_NAME}
CXX_EXTENSIONS OFF
)

if(TARGET_EMSCRIPTEN)
message("Embed OBJ file")
set_target_properties(${PROJECT_NAME}
PROPERTIES
LINK_FLAGS "--embed-file ${OBJ_FILE}@${OBJ_FILE}"
jgsogo marked this conversation as resolved.
Show resolved Hide resolved
)
endif()


# Run some executables (we can only be sure they exist if native build)
if (EXEC_GL_INFO AND NOT CMAKE_CROSSCOMPILING)
Expand Down
5 changes: 5 additions & 0 deletions recipes/magnum/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def build(self):
cmake.definitions["IMPORTER_PLUGINS_FOLDER"] = os.path.join(self.deps_user_info["magnum"].plugins_basepath, "importers").replace("\\", "/")
cmake.definitions["OBJ_FILE"] = os.path.join(self.source_folder, "triangleMesh.obj").replace("\\", "/")
cmake.definitions["SHARED_PLUGINS"] = self.options["magnum"].shared_plugins
cmake.definitions["TARGET_EMSCRIPTEN"] = bool(self.settings.os == "Emscripten")
cmake.configure()
cmake.build()

Expand All @@ -42,3 +43,7 @@ def test(self):

bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)

if self.settings.os == "Emscripten":
bin_path = os.path.join("bin", "test_package.js")
self.run("node {}".format(bin_path), run_environment=True)
jgsogo marked this conversation as resolved.
Show resolved Hide resolved