Browse Source

Require CMake 3.13+ for Emscripten and WebGL 2.

And drop all nasty workarounds related to this.
pull/168/head
Vladimír Vondruš 3 years ago
parent
commit
a1bb40b8f9
  1. 3
      doc/changelog.dox
  2. 6
      doc/snippets/CMakeLists.txt
  3. 25
      modules/FindMagnum.cmake
  4. 12
      src/CMakeLists.txt
  5. 9
      src/Magnum/GL/CMakeLists.txt
  6. 25
      src/Magnum/Platform/Test/CMakeLists.txt

3
doc/changelog.dox

@ -45,6 +45,9 @@ See also:
versions are not supported anymore and all workarounds for them were
removed. This is a conservative change, as there are no known supported
distributions which would have anything older than 3.5.
- Minimal supported CMake version for Emscripten WebGL 2 compilation is now
3.13, in order to be able to set linker options for enabling WebGL 2
without having to pollute the global `CMAKE_EXE_LINKER_FLAGS` variable.
@subsection changelog-latest-new New features

6
doc/snippets/CMakeLists.txt

@ -36,12 +36,6 @@ set_directory_properties(PROPERTIES
CORRADE_CXX_STANDARD 11
CORRADE_USE_PEDANTIC_FLAGS ON)
# Emscripten needs 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()
set(snippets_Magnum_SRCS
Magnum.cpp
MagnumAnimation.cpp

25
modules/FindMagnum.cmake

@ -894,6 +894,13 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
find_package(OpenGLES3 REQUIRED)
set_property(TARGET Magnum::${_component} APPEND PROPERTY
INTERFACE_LINK_LIBRARIES OpenGLES3::OpenGLES3)
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 Magnum::${_component} APPEND PROPERTY
INTERFACE_LINK_OPTIONS "SHELL:-s USE_WEBGL2=1")
endif()
endif()
# MaterialTools library
@ -1047,24 +1054,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

12
src/CMakeLists.txt

@ -29,18 +29,6 @@ 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 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.
# 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 CMAKE_VERSION VERSION_LESS 3.13 AND MAGNUM_WITH_GL AND NOT MAGNUM_TARGET_GLES2)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s USE_WEBGL2=1")
endif()
# On Windows enable UNICODE/_UNICODE macros to avoid accidentally passing UTF-8
# values to ANSI functions
if(CORRADE_TARGET_WINDOWS)

9
src/Magnum/GL/CMakeLists.txt

@ -233,6 +233,12 @@ elseif(MAGNUM_TARGET_GLES2)
target_link_libraries(MagnumGL PUBLIC OpenGLES2::OpenGLES2)
else()
target_link_libraries(MagnumGL PUBLIC OpenGLES3::OpenGLES3)
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()
target_link_options(MagnumGL PUBLIC "SHELL:-s USE_WEBGL2=1")
endif()
endif()
install(TARGETS MagnumGL
@ -316,6 +322,9 @@ if(MAGNUM_BUILD_TESTS)
target_link_libraries(MagnumGLTestLib PUBLIC OpenGLES2::OpenGLES2)
else()
target_link_libraries(MagnumGLTestLib PUBLIC OpenGLES3::OpenGLES3)
if(CORRADE_TARGET_EMSCRIPTEN)
target_link_options(MagnumGLTestLib PUBLIC "SHELL:-s USE_WEBGL2=1")
endif()
endif()
if(MAGNUM_BUILD_GL_TESTS)

25
src/Magnum/Platform/Test/CMakeLists.txt

@ -44,15 +44,19 @@ if(MAGNUM_WITH_ANDROIDAPPLICATION)
endif()
if(MAGNUM_WITH_EMSCRIPTENAPPLICATION)
if(CMAKE_VERSION VERSION_LESS 3.13)
message(FATAL_ERROR "CMake 3.13+ is required in order to specify Emscripten linker options")
endif()
add_executable(PlatformEmscriptenApplicationTest EmscriptenApplicationTest.cpp)
target_link_libraries(PlatformEmscriptenApplicationTest PRIVATE
MagnumEmscriptenApplication MagnumGL
MagnumEmscriptenApplication MagnumGL)
target_link_options(PlatformEmscriptenApplicationTest PRIVATE
# Test that the canvas and keylistener can be found with both the old
# and the new Emscripten target behaviors
# TODO: use target_link_options() once we can require CMake 3.13
"-s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=0"
"SHELL:-s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=0"
# Enable memory runtime checks
"-s ASSERTIONS=2 -s SAFE_HEAP=1")
"SHELL:-s ASSERTIONS=2"
"SHELL:-s SAFE_HEAP=1")
add_custom_command(TARGET PlatformEmscriptenApplicationTest POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_CURRENT_SOURCE_DIR}/../WebApplication.css"
@ -64,11 +68,14 @@ if(MAGNUM_WITH_EMSCRIPTENAPPLICATION)
add_executable(PlatformMultipleEmscriptenApplicationTest EmscriptenApplicationTest.cpp)
target_link_libraries(PlatformMultipleEmscriptenApplicationTest PRIVATE
MagnumEmscriptenApplication MagnumGL
# TODO: use target_link_options() once we can require CMake 3.13
"-s MODULARIZE -s EXPORT_NAME=createModule"
"-s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1"
"-s ASSERTIONS=2 -s SAFE_HEAP=1")
MagnumEmscriptenApplication MagnumGL)
target_link_options(PlatformMultipleEmscriptenApplicationTest PRIVATE
# Test that the canvas and keylistener can be found with both the old
# and the new Emscripten target behaviors
"SHELL:-s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1"
# Enable memory runtime checks
"SHELL:-s ASSERTIONS=2"
"SHELL:-s SAFE_HEAP=1")
target_compile_definitions(PlatformMultipleEmscriptenApplicationTest PRIVATE CUSTOM_CLEAR_COLOR=0x3bd267_rgbf)
add_custom_command(TARGET PlatformMultipleEmscriptenApplicationTest POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different

Loading…
Cancel
Save