diff --git a/modules/FindCorrade.cmake b/modules/FindCorrade.cmake index d7806e0..969c68c 100644 --- a/modules/FindCorrade.cmake +++ b/modules/FindCorrade.cmake @@ -122,6 +122,7 @@ # automatically) # CORRADE_TESTSUITE_XCTEST_RUNNER - Path to XCTestRunner.mm.in file # CORRADE_TESTSUITE_ADB_RUNNER - Path to AdbRunner.sh file +# CORRADE_UTILITY_JS - Path to CorradeUtility.js file # CORRADE_PEDANTIC_COMPILER_OPTIONS - List of pedantic compiler options used # for targets with :prop_tgt:`CORRADE_USE_PEDANTIC_FLAGS` enabled # CORRADE_PEDANTIC_COMPILER_DEFINITIONS - List of pedantic compiler @@ -559,6 +560,15 @@ foreach(_component ${Corrade_FIND_COMPONENTS}) set_property(TARGET Corrade::${_component} APPEND PROPERTY INTERFACE_LINK_LIBRARIES "log") endif() + # Emscripten has various stuff implemented in JS + if(CORRADE_TARGET_EMSCRIPTEN) + find_file(CORRADE_UTILITY_JS CorradeUtility.js + PATH_SUFFIXES lib) + set_property(TARGET Corrade::${_component} APPEND PROPERTY + # TODO switch to INTERFACE_LINK_OPTIONS and SHELL: once we + # require CMake 3.13 unconditionally + INTERFACE_LINK_LIBRARIES "--js-library ${CORRADE_UTILITY_JS}") + endif() endif() # Find library includes diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index 9fdbd6e..c8c5e87 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -162,6 +162,7 @@ # MAGNUM_*_LIBRARY - Component libraries (w/o dependencies) # MAGNUM_*_LIBRARY_DEBUG - Debug version of given library, if found # MAGNUM_*_LIBRARY_RELEASE - Release version of given library, if found +# MAGNUM_PLATFORM_JS - Path to MagnumPlatform.js file # MAGNUM_BINARY_INSTALL_DIR - Binary installation directory # MAGNUM_LIBRARY_INSTALL_DIR - Library installation directory # MAGNUM_DATA_INSTALL_DIR - Data installation directory @@ -696,7 +697,17 @@ foreach(_component ${Magnum_FIND_COMPONENTS}) set_property(TARGET Magnum::${_component} APPEND PROPERTY INTERFACE_LINK_LIBRARIES android EGL::EGL) - # EmscriptenApplication has no additional dependencies + # Emscripten application dependencies + elseif(_component STREQUAL EmscriptenApplication) + # Emscripten has various stuff implemented in JS + if(CORRADE_TARGET_EMSCRIPTEN) + find_file(MAGNUM_PLATFORM_JS MagnumPlatform.js + PATH_SUFFIXES lib) + set_property(TARGET Magnum::${_component} APPEND PROPERTY + # TODO switch to INTERFACE_LINK_OPTIONS and SHELL: once + # we require CMake 3.13 unconditionally + INTERFACE_LINK_LIBRARIES "--js-library ${MAGNUM_PLATFORM_JS}") + endif() # GLFW application dependencies elseif(_component STREQUAL GlfwApplication) @@ -752,6 +763,14 @@ foreach(_component ${Magnum_FIND_COMPONENTS}) elseif(CORRADE_TARGET_UNIX) set_property(TARGET Magnum::${_component} APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${CMAKE_DL_LIBS}) + # Emscripten has various stuff implemented in JS + elseif(CORRADE_TARGET_EMSCRIPTEN) + find_file(MAGNUM_PLATFORM_JS MagnumPlatform.js + PATH_SUFFIXES lib) + set_property(TARGET Magnum::${_component} APPEND PROPERTY + # TODO switch to INTERFACE_LINK_OPTIONS and SHELL: once + # we require CMake 3.13 unconditionally + INTERFACE_LINK_LIBRARIES "--js-library ${MAGNUM_PLATFORM_JS}") endif() # With GLVND (since CMake 3.11) we need to explicitly link to @@ -985,7 +1004,7 @@ foreach(_component ${Magnum_FIND_COMPONENTS}) endforeach() set_property(TARGET Magnum::${_component} APPEND PROPERTY INTERFACE_LINK_LIBRARIES Magnum::Magnum) - set(_MAGNUM_${component}_OPTIONAL_DEPENDENCIES_TO_ADD ) + set(_MAGNUM_${_component}_OPTIONAL_DEPENDENCIES_TO_ADD ) foreach(_dependency ${_MAGNUM_${_component}_DEPENDENCIES}) if(NOT _MAGNUM_${_component}_${_dependency}_DEPENDENCY_IS_OPTIONAL) set_property(TARGET Magnum::${_component} APPEND PROPERTY @@ -1047,24 +1066,6 @@ if(CORRADE_TARGET_EMSCRIPTEN) MAGNUM_EMSCRIPTENAPPLICATION_JS MAGNUM_WINDOWLESSEMSCRIPTENAPPLICATION_JS MAGNUM_WEBAPPLICATION_CSS) - - # If we are on CMake 3.13 and up, `-s USE_WEBGL2=1` linker option is - # propagated from FindOpenGLES3.cmake already. If not (and the GL library - # is used), we need to modify the global CMAKE_EXE_LINKER_FLAGS. Do it here - # instead of in FindOpenGLES3.cmake so it works also for CMake subprojects - # (in which case find_package(OpenGLES3) is called in (and so - # CMAKE_EXE_LINKER_FLAGS would be modified in) Magnum's root CMakeLists.txt - # and thus can't affect the variable in the outer project). CMake supports - # IN_LIST as an operator since 3.1 (Emscripten needs at least 3.7), but - # it's behind a policy, so enable that one as well. - cmake_policy(SET CMP0057 NEW) - # TODO since 1.39.19 it's possible to use `-sUSE_WEBGL2=1`, which can be - # then passed via target_link_libraries() etc. without requiring CMake - # 3.13: https://github.com/emscripten-core/emscripten/blob/main/ChangeLog.md#13919-07072020 - # -- change to that once we drop support for older Emscripten versions - if(CMAKE_VERSION VERSION_LESS 3.13 AND GL IN_LIST Magnum_FIND_COMPONENTS AND NOT MAGNUM_TARGET_GLES2 AND NOT CMAKE_EXE_LINKER_FLAGS MATCHES "-s USE_WEBGL2=1") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s USE_WEBGL2=1") - endif() endif() # For CMake 3.16+ with REASON_FAILURE_MESSAGE, provide additional potentially diff --git a/modules/FindOpenGLES3.cmake b/modules/FindOpenGLES3.cmake index 2b1da5a..5c41acc 100644 --- a/modules/FindOpenGLES3.cmake +++ b/modules/FindOpenGLES3.cmake @@ -79,16 +79,11 @@ if(NOT TARGET OpenGLES3::OpenGLES3) IMPORTED_LOCATION ${OPENGLES3_LIBRARY}) endif() - # Emscripten needs a special flag to use WebGL 2. CMake 3.13 allows to set - # this via INTERFACE_LINK_OPTIONS, for older versions we modify the global - # CMAKE_EXE_LINKER_FLAGS inside FindMagnum.cmake. - # TODO since 1.39.19 it's possible to use `-sUSE_WEBGL2=1`, which can be - # then passed via target_link_libraries() etc. without requiring CMake - # 3.13: https://github.com/emscripten-core/emscripten/blob/main/ChangeLog.md#13919-07072020 - # -- change to that once we drop support for older Emscripten versions - if(CORRADE_TARGET_EMSCRIPTEN AND NOT CMAKE_VERSION VERSION_LESS 3.13) - # I could probably use target_link_options() here, but let's be - # consistent with the rest + # Emscripten needs a special flag to use WebGL 2 + if(CORRADE_TARGET_EMSCRIPTEN) + if(CMAKE_VERSION VERSION_LESS 3.13) + message(FATAL_ERROR "CMake 3.13+ is required in order to specify Emscripten linker options") + endif() set_property(TARGET OpenGLES3::OpenGLES3 APPEND PROPERTY INTERFACE_LINK_OPTIONS "SHELL:-s USE_WEBGL2=1") endif()