From f7267453824e912cc3a6ed49d8b8db6446caaffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 21 May 2019 22:55:20 +0200 Subject: [PATCH] package/ci: test also GL stuff via SwiftShader. --- modules/FindOpenGLES2.cmake | 86 +++++++++++++++++++++++++ modules/FindOpenGLES3.cmake | 100 ++++++++++++++++++++++++++++++ package/ci/travis-desktop-gles.sh | 76 +++++++++++++++++++++++ package/ci/travis.yml | 46 +++++++++++++- 4 files changed, 307 insertions(+), 1 deletion(-) create mode 100644 modules/FindOpenGLES2.cmake create mode 100644 modules/FindOpenGLES3.cmake create mode 100755 package/ci/travis-desktop-gles.sh diff --git a/modules/FindOpenGLES2.cmake b/modules/FindOpenGLES2.cmake new file mode 100644 index 0000000..dad7442 --- /dev/null +++ b/modules/FindOpenGLES2.cmake @@ -0,0 +1,86 @@ +#.rst: +# Find OpenGL ES 2 +# ---------------- +# +# Finds the OpenGL ES 2 library. This module defines: +# +# OpenGLES2_FOUND - True if OpenGL ES 2 library is found +# OpenGLES2::OpenGLES2 - OpenGL ES 2 imported target +# +# Additionally these variables are defined for internal usage: +# +# OPENGLES2_LIBRARY - OpenGL ES 2 library +# OPENGLES2_INCLUDE_DIR - Include dir +# + +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 +# Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + +# In Emscripten OpenGL ES 2 is linked automatically, thus no need to find the +# library. +if(NOT CORRADE_TARGET_EMSCRIPTEN) + find_library(OPENGLES2_LIBRARY NAMES + GLESv2 + + # ANGLE (CMake doesn't search for lib prefix on Windows) + libGLESv2 + + # iOS + OpenGLES) + set(OPENGLES2_LIBRARY_NEEDED OPENGLES2_LIBRARY) +endif() + +# Include dir +find_path(OPENGLES2_INCLUDE_DIR NAMES + GLES2/gl2.h + + # iOS + ES2/gl.h) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(OpenGLES2 DEFAULT_MSG + ${OPENGLES2_LIBRARY_NEEDED} + OPENGLES2_INCLUDE_DIR) + +if(NOT TARGET OpenGLES2::OpenGLES2) + if(OPENGLES2_LIBRARY_NEEDED) + # Work around BUGGY framework support on macOS + # http://public.kitware.com/pipermail/cmake/2016-April/063179.html + if(CORRADE_TARGET_APPLE AND ${OPENGLES2_LIBRARY} MATCHES "\\.framework$") + add_library(OpenGLES2::OpenGLES2 INTERFACE IMPORTED) + set_property(TARGET OpenGLES2::OpenGLES2 APPEND PROPERTY + INTERFACE_LINK_LIBRARIES ${OPENGLES2_LIBRARY}) + else() + add_library(OpenGLES2::OpenGLES2 UNKNOWN IMPORTED) + set_property(TARGET OpenGLES2::OpenGLES2 PROPERTY + IMPORTED_LOCATION ${OPENGLES2_LIBRARY}) + endif() + else() + add_library(OpenGLES2::OpenGLES2 INTERFACE IMPORTED) + endif() + + set_property(TARGET OpenGLES2::OpenGLES2 PROPERTY + INTERFACE_INCLUDE_DIRECTORIES ${OPENGLES2_INCLUDE_DIR}) +endif() diff --git a/modules/FindOpenGLES3.cmake b/modules/FindOpenGLES3.cmake new file mode 100644 index 0000000..413be61 --- /dev/null +++ b/modules/FindOpenGLES3.cmake @@ -0,0 +1,100 @@ +#.rst: +# Find OpenGL ES 3 +# ---------------- +# +# Finds the OpenGL ES 3 library. This module defines: +# +# OpenGLES3_FOUND - True if OpenGL ES 3 library is found +# OpenGLES3::OpenGLES3 - OpenGL ES 3 imported target +# +# Additionally these variables are defined for internal usage: +# +# OPENGLES3_LIBRARY - OpenGL ES 3 library +# OPENGLES3_INCLUDE_DIR - Include dir +# + +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 +# Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + +# In Emscripten OpenGL ES 3 is linked automatically, thus no need to find the +# library. +if(NOT CORRADE_TARGET_EMSCRIPTEN) + find_library(OPENGLES3_LIBRARY NAMES + GLESv3 + + # On some platforms (e.g. desktop emulation with Mesa or NVidia) ES3 + # support is provided in ES2 lib + GLESv2 + + # ANGLE (CMake doesn't search for lib prefix on Windows) + libGLESv2 + + # iOS + OpenGLES) + set(OPENGLES3_LIBRARY_NEEDED OPENGLES3_LIBRARY) +endif() + +# Include dir +find_path(OPENGLES3_INCLUDE_DIR NAMES + GLES3/gl3.h + + # iOS + ES3/gl.h) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args("OpenGLES3" DEFAULT_MSG + ${OPENGLES3_LIBRARY_NEEDED} + OPENGLES3_INCLUDE_DIR) + +if(NOT TARGET OpenGLES3::OpenGLES3) + if(OPENGLES3_LIBRARY_NEEDED) + # Work around BUGGY framework support on macOS + # http://public.kitware.com/pipermail/cmake/2016-April/063179.html + if(CORRADE_TARGET_APPLE AND ${OPENGLES3_LIBRARY} MATCHES "\\.framework$") + add_library(OpenGLES3::OpenGLES3 INTERFACE IMPORTED) + set_property(TARGET OpenGLES3::OpenGLES3 APPEND PROPERTY + INTERFACE_LINK_LIBRARIES ${OPENGLES3_LIBRARY}) + else() + add_library(OpenGLES3::OpenGLES3 UNKNOWN IMPORTED) + set_property(TARGET OpenGLES3::OpenGLES3 PROPERTY + IMPORTED_LOCATION ${OPENGLES3_LIBRARY}) + endif() + else() + add_library(OpenGLES3::OpenGLES3 INTERFACE IMPORTED) + endif() + + 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() diff --git a/package/ci/travis-desktop-gles.sh b/package/ci/travis-desktop-gles.sh new file mode 100755 index 0000000..a4f3e18 --- /dev/null +++ b/package/ci/travis-desktop-gles.sh @@ -0,0 +1,76 @@ +#!/bin/bash +set -ev + +# Corrade +git clone --depth 1 git://github.com/mosra/corrade.git +cd corrade +mkdir build && cd build +cmake .. \ + -DCMAKE_INSTALL_PREFIX=$HOME/deps \ + -DCMAKE_INSTALL_RPATH=$HOME/deps/lib \ + -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_DEPRECATED=$BUILD_DEPRECATED \ + -DWITH_INTERCONNECT=OFF \ + -DWITH_PLUGINMANAGER=OFF \ + -DWITH_TESTSUITE=OFF \ + -G Ninja +ninja install +cd ../.. + +# Magnum +git clone --depth 1 git://github.com/mosra/magnum.git +cd magnum +mkdir build && cd build +cmake .. \ + -DCMAKE_INSTALL_PREFIX=$HOME/deps \ + -DCMAKE_INSTALL_RPATH=$HOME/deps/lib \ + -DCMAKE_BUILD_TYPE=Release \ + -DEGL_LIBRARY=$HOME/swiftshader/libEGL.so \ + -DOPENGLES2_LIBRARY=$HOME/swiftshader/libGLESv2.so \ + -DOPENGLES3_LIBRARY=$HOME/swiftshader/libGLESv2.so \ + -DCMAKE_INSTALL_RPATH=$HOME/swiftshader \ + -DTARGET_GLES=ON \ + -DTARGET_GLES2=$TARGET_GLES2 \ + -DWITH_AUDIO=OFF \ + -DWITH_DEBUGTOOLS=OFF \ + -DWITH_GL=ON \ + -DWITH_MESHTOOLS=OFF \ + -DWITH_PRIMITIVES=OFF \ + -DWITH_SCENEGRAPH=ON \ + -DWITH_SHADERS=ON \ + -DWITH_TEXT=OFF \ + -DWITH_TEXTURETOOLS=OFF \ + -DWITH_TRADE=OFF \ + -DWITH_VK=OFF \ + -DWITH_WINDOWLESSEGLAPPLICATION=ON \ + -DBUILD_DEPRECATED=OFF \ + -G Ninja +ninja install +cd ../.. + +# Build the thing +mkdir build && cd build +cmake .. \ + -DCMAKE_CXX_FLAGS="--coverage" \ + -DCMAKE_INSTALL_PREFIX=$HOME/deps \ + -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_PREFIX_PATH=$HOME/pybind11 \ + -DEGL_LIBRARY=$HOME/swiftshader/libEGL.so \ + -DOPENGLES2_LIBRARY=$HOME/swiftshader/libGLESv2.so \ + -DOPENGLES3_LIBRARY=$HOME/swiftshader/libGLESv2.so \ + -DCMAKE_INSTALL_RPATH=$HOME/swiftshader \ + -DPYBIND11_PYTHON_VERSION=3.6 \ + -DWITH_PYTHON=ON \ + -G Ninja +ninja + +# Verify the setuptools install +cd src/python +python3 setup.py install --root="$TRAVIS_BUILD_DIR/install" --prefix=/usr + +# Run tests & gather coverage +cd ../../../src/python/corrade +coverage run -m unittest -v && cp .coverage ../.coverage.corrade + +cd ../magnum +coverage run -m unittest -v && cp .coverage ../.coverage.magnum diff --git a/package/ci/travis.yml b/package/ci/travis.yml index 40639a5..48603dd 100644 --- a/package/ci/travis.yml +++ b/package/ci/travis.yml @@ -15,12 +15,50 @@ matrix: compiler: gcc env: - JOBID=linux-gl + - TARGET=desktop - LCOV_EXTRA_OPTS="--gcov-tool /usr/bin/gcov-4.8" + - language: python + python: 3.6 + os: linux + dist: xenial + compiler: gcc + env: + - JOBID=linux-gles2 + - TARGET=desktop-gles + - TARGET_GLES2=ON + - CMAKE_CXX_FLAGS="--coverage" + - LCOV_EXTRA_OPTS="--gcov-tool /usr/bin/gcov-4.8" + addons: + apt: + packages: + - g++-4.8 + - ninja-build + - lcov + - libgles2-mesa-dev + - language: python + python: 3.6 + os: linux + dist: xenial + compiler: gcc + env: + - JOBID=linux-gles3 + - TARGET=desktop-gles + - TARGET_GLES2=OFF + - CMAKE_CXX_FLAGS="--coverage" + - LCOV_EXTRA_OPTS="--gcov-tool /usr/bin/gcov-4.8" + addons: + apt: + packages: + - g++-4.8 + - ninja-build + - lcov + - libgles2-mesa-dev - language: cpp os: osx compiler: clang env: - JOBID=macos-gl + - TARGET=desktop notifications: webhooks: @@ -32,6 +70,7 @@ notifications: cache: directories: + - $HOME/swiftshader - $HOME/cmake - $HOME/pybind11 @@ -53,11 +92,16 @@ install: - if [ "$TRAVIS_OS_NAME" == "linux" ] && [ ! -e "$HOME/pybind11/bin" ]; then $TRAVIS_BUILD_DIR/package/ci/setup-pybind11.sh; fi - if [ "$TRAVIS_OS_NAME" == "osx" ]; then HOMEBREW_NO_AUTO_UPDATE=1 brew install pybind11; fi +# SwiftShader on Linux (cached). Taken from Chromium snapshot 587878 +# (swiftshader-bin Arch package). +- if [ "$TRAVIS_OS_NAME" == "linux" ] && [ "$TARGET" == "desktop-gles" ] && [ ! -e "$HOME/swiftshader/libEGL.so" ]; then cd $HOME ; wget https://ci.magnum.graphics/swiftshader-chromium-587878.tar.gz && mkdir -p swiftshader && cd swiftshader && tar -xzf ../swiftshader-chromium-587878.tar.gz && cd $TRAVIS_BUILD_DIR ; fi + # lcov on macOS - if [ "$TRAVIS_OS_NAME" == "osx" ]; then HOMEBREW_NO_AUTO_UPDATE=1 brew install lcov; fi script: -- if [ "$TRAVIS_OS_NAME" == "linux" ] || [ "$TRAVIS_OS_NAME" == "osx" ]; then ./package/ci/travis-desktop.sh; fi +- if [ "$TARGET" == "desktop" ] && ( [ "$TRAVIS_OS_NAME" == "linux" ] || [ "$TRAVIS_OS_NAME" == "osx" ] ); then ./package/ci/travis-desktop.sh; fi +- if [ "$TARGET" == "desktop-gles" ] && ( [ "$TRAVIS_OS_NAME" == "linux" ] || [ "$TRAVIS_OS_NAME" == "osx" ] ); then ./package/ci/travis-desktop-gles.sh; fi # Travis somehow is not able to gather all output, try to force it using this - sync