Browse Source

CMake: move -s USE_WEBGL2=1 for Esmcripten to FindOpenGLES3.cmake.

Well, only for CMake 3.13 and newer, by using the SHELL: variant of
INTERFACE_LINK_OPTIONS. In order to stay compatible with older versions,
it needs to be done in FindMagnum.cmake and modifying the global
CMAKE_EXE_LINKER_FLAGS. This case was updated to work properly also with
CMake subprojects.
pull/331/head
Vladimír Vondruš 7 years ago
parent
commit
447fa84816
  1. 4
      doc/changelog.dox
  2. 22
      modules/FindMagnum.cmake
  3. 10
      modules/FindOpenGLES3.cmake
  4. 8
      src/CMakeLists.txt

4
doc/changelog.dox

@ -177,6 +177,10 @@ See also:
(the HTML markup was unchanged since 2013, heh)
- ES 2.0 and ES 3.0 subset of tests requiring GL context is now run on Travis
CI using SwiftShader for better code coverage
- On CMake 3.13 and up, WebGL2 build on Emscripten (and the `-s USE_WEBGL2=1`
flag in particular) is now handled by the `FindOpenGLES3.cmake` module
and the new `INTERFACE_LINK_OPTIONS` property instead of `FindMagnum.cmake`. On older versions this is handled in `FindMagnum.cmake` by modifying the
global `CMAKE_EXE_LINKER_FLAGS` variable.
@subsection changelog-latest-bugfixes Bug fixes

22
modules/FindMagnum.cmake

@ -832,12 +832,6 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
INTERFACE_LINK_LIBRARIES OpenGLES3::OpenGLES3)
endif()
# Emscripten needs a special flag to use WebGL 2
if(CORRADE_TARGET_EMSCRIPTEN AND NOT MAGNUM_TARGET_GLES2)
# TODO: give me INTERFACE_LINK_OPTIONS or something, please
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s USE_WEBGL2=1")
endif()
# MeshTools library
elseif(_component STREQUAL MeshTools)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES CompressIndices.h)
@ -959,7 +953,7 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
endif()
endforeach()
# Emscripten-specific files
# Emscripten-specific files and flags
if(CORRADE_TARGET_EMSCRIPTEN)
find_file(MAGNUM_EMSCRIPTENAPPLICATION_JS EmscriptenApplication.js
PATH_SUFFIXES share/magnum)
@ -975,6 +969,20 @@ 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)
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()
# Complete the check with also all components

10
modules/FindOpenGLES3.cmake

@ -87,4 +87,14 @@ if(NOT TARGET OpenGLES3::OpenGLES3)
set_property(TARGET OpenGLES3::OpenGLES3 PROPERTY
INTERFACE_INCLUDE_DIRECTORIES ${OPENGLES3_INCLUDE_DIR})
# 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.
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
set_property(TARGET OpenGLES3::OpenGLES3 APPEND PROPERTY
INTERFACE_LINK_OPTIONS "SHELL:-s USE_WEBGL2=1")
endif()
endif()

8
src/CMakeLists.txt

@ -35,9 +35,11 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" OR CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC
string(REPLACE "/W3" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endif()
# Emscripten needs special flag to use WebGL 2
if(CORRADE_TARGET_EMSCRIPTEN AND NOT TARGET_GLES2)
# TODO: give me INTERFACE_LINK_OPTIONS or something, please
# Emscripten needs special flag to use WebGL 2. 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.
if(CORRADE_TARGET_EMSCRIPTEN AND CMAKE_VERSION VERSION_LESS 3.13 AND WITH_GL AND NOT TARGET_GLES2)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s USE_WEBGL2=1")
endif()

Loading…
Cancel
Save