Browse Source

Adapt to BUILD_MULTITHREADED being part of Corrade now.

If building with deprecated features enabled, the buildsystem checks if
the option is still set and is inconsistent with what Corrade reports
and reports a deprecation warning. For backwards compatibility the
MAGNUM_BUILD_MULTITHREADED CMake variable and preprocessor macro are
still provided as well.
pull/362/head
Vladimír Vondruš 7 years ago
parent
commit
a3c7968e64
  1. 13
      CMakeLists.txt
  2. 10
      doc/building.dox
  3. 4
      doc/changelog.dox
  4. 9
      doc/cmake.dox
  5. 5
      doc/platform.dox
  6. 15
      modules/FindMagnum.cmake
  7. 8
      src/Magnum/GL/Context.cpp
  8. 14
      src/Magnum/GL/Context.h
  9. 6
      src/Magnum/GL/Test/ContextGLTest.cpp
  10. 13
      src/Magnum/Magnum.h
  11. 6
      src/Magnum/Platform/gl-info.cpp
  12. 9
      src/Magnum/configure.h.cmake

13
CMakeLists.txt

@ -165,9 +165,16 @@ if(BUILD_DEPRECATED)
set(MAGNUM_BUILD_DEPRECATED 1)
endif()
option(BUILD_MULTITHREADED "Build in a way that makes it possible to use multiple thread-local Magnum contexts" ON)
if(BUILD_MULTITHREADED)
set(MAGNUM_BUILD_MULTITHREADED 1)
# BUILD_MULTITHREADED got moved to Corrade itself. In case we're building with
# deprecated features enabled, print a warning in case it's set but Corrade
# reports a different value. We can't print a warning in case it's set because
# that would cause false positives when both Corrade and Magnum are subprojects
# (and thus this option is visible to both). Otherwise it's silent --- for
# non-deprecated builds CMake will at most warn about "variable being unused".
if(MAGNUM_BUILD_DEPRECATED)
if(DEFINED BUILD_MULTITHREADED AND ((NOT CORRADE_BUILD_MULTITHREADED AND BUILD_MULTITHREADED) OR (CORRADE_BUILD_MULTITHREADED AND NOT BUILD_MULTITHREADED)))
message(DEPRECATION "BUILD_MULTITHREADED (set to ${BUILD_MULTITHREADED}) is now ignored — you need to set it when building Corrade instead (there it's ${CORRADE_BUILD_MULTITHREADED} now)")
endif()
endif()
set(MAGNUM_DEPLOY_PREFIX "."

10
doc/building.dox

@ -475,9 +475,9 @@ available for desktop OpenGL only, see @ref requires-gl.
@ref Vk library itself.
By default the engine is built in a way that allows having multiple independent
thread-local Magnum contents. This might cause some performance penalties ---
if you are sure that you will never need such feature, you can disable it via
the `BUILD_MULTITHREADED` option.
thread-local Magnum contents. This is inherited from the
@ref CORRADE_BUILD_MULTITHREADED option --- if you are sure that you will never
need such feature, disable it when building Corrade itself.
The features used can be conveniently detected in depending projects both in
CMake and C++ sources, see @ref cmake and @ref Magnum/Magnum.h for more
@ -925,10 +925,6 @@ static libraries. Dynamically loaded plugins are not supported on iOS at the
moment, thus `BUILD_PLUGINS_STATIC` is implicitly enabled. OpenGL ES 2.0 is
enabled by default, switch to 3.0 by disabling `TARGET_GLES2`.
Please note that `BUILD_MULTITHREADED` is supported only since Xcode 7.3 and
doesn't work on `i386` iOS Simulator, you need to disable it in order to build
for older platforms.
@code{.sh}
mkdir build-ios && cd build-ios
cmake .. \

4
doc/changelog.dox

@ -512,6 +512,10 @@ See also:
@cb{.js} 'module' @ce)
- and for CSS files, all references to @cb{.css} #module @ce need to be
@cb{.css} #canvas @ce now
- The `BUILD_MULTITHREADED` CMake option and `MAGNUM_BUILD_MULTITHREADED`
CMake / preprocessor variable has been moved to Corrade --- you need to
toggle it when building Corrade and use @ref CORRADE_BUILD_MULTITHREADED
instead
@section changelog-2019-01 2019.01

9
doc/cmake.dox

@ -226,8 +226,6 @@ are also available as preprocessor variables if including
included
- `MAGNUM_BUILD_STATIC` --- Defined if compiled as static libraries. Default
are shared libraries.
- `MAGNUM_BUILD_MULTITHREADED` --- Defined if compiled in a way that allows
having multiple thread-local Magnum contexts. The default.
- `MAGNUM_TARGET_GL` --- Defined if compiled with OpenGL interoperability
enabled
- `MAGNUM_TARGET_GLES` --- Defined if compiled for OpenGL ES
@ -241,6 +239,13 @@ are also available as preprocessor variables if including
- `MAGNUM_TARGET_VK` --- Defined if compiled with Vulkan interoperability
enabled
The following variables are provided for backwards compatibility purposes only
when @ref MAGNUM_BUILD_DEPRECATED is defined and will be removed in a future
release:
- `MAGNUM_BUILD_MULTITHREADED` --- Alias to `CORRADE_BUILD_MULTITHREADED`.
Use @ref CORRADE_BUILD_MULTITHREADED instead.
Corrade library provides also its own set of CMake macros and variables, see
@ref corrade-cmake "its documentation" for more information.
@ref cmake-plugins "Plugins repository", @ref cmake-integration "Integration repository"

5
doc/platform.dox

@ -236,8 +236,9 @@ The main purpose of windowless contexts is threaded OpenGL, used for example
for background data processing. The workflow is to create the windowless
context on the main thread, but make it current in the worker thread. This way
the main thread state isn't affected so it can have any other GL context
current (for example for the main application rendering). See also
@ref MAGNUM_BUILD_MULTITHREADED.
current (for example for the main application rendering). See
@ref GL-Context-multithreading and @ref CORRADE_BUILD_MULTITHREADED for more
information.
@note Context creation is not thread safe on all platforms, that's why it still
has to be done on the main thread.

15
modules/FindMagnum.cmake

@ -127,8 +127,6 @@
# MAGNUM_BUILD_DEPRECATED - Defined if compiled with deprecated APIs
# included
# MAGNUM_BUILD_STATIC - Defined if compiled as static libraries
# MAGNUM_BUILD_MULTITHREADED - Defined if compiled in a way that allows
# having multiple thread-local Magnum contexts
# MAGNUM_TARGET_GL - Defined if compiled with OpenGL interop
# MAGNUM_TARGET_GLES - Defined if compiled for OpenGL ES
# MAGNUM_TARGET_GLES2 - Defined if compiled for OpenGL ES 2.0
@ -139,6 +137,13 @@
# MAGNUM_TARGET_HEADLESS - Defined if compiled for headless machines
# MAGNUM_TARGET_VK - Defined if compiled with Vulkan interop
#
# The following variables are provided for backwards compatibility purposes
# only when MAGNUM_BUILD_DEPRECATED is enabled and will be removed in a future
# release:
#
# MAGNUM_BUILD_MULTITHREADED - Alias to CORRADE_BUILD_MULTITHREADED. Use
# CORRADE_BUILD_MULTITHREADED instead.
#
# Additionally these variables are defined for internal usage:
#
# MAGNUM_INCLUDE_DIR - Root include dir (w/o dependencies)
@ -246,7 +251,6 @@ set(_magnumFlags
# So far that's not a problem, but might become an issue for new flags.
BUILD_DEPRECATED
BUILD_STATIC
BUILD_MULTITHREADED
TARGET_GL
TARGET_GLES
TARGET_GLES2
@ -262,6 +266,11 @@ foreach(_magnumFlag ${_magnumFlags})
endif()
endforeach()
# For compatibility only, to be removed at some point
if(MAGNUM_BUILD_DEPRECATED AND CORRADE_BUILD_MULTITHREADED)
set(MAGNUM_BUILD_MULTITHREADED 1)
endif()
# OpenGL library preference. Prefer to use GLVND, since that's the better
# approach nowadays, but allow the users to override it from outside in case
# it is broken for some reason (Nvidia drivers in Debian's testing (Buster) --

8
src/Magnum/GL/Context.cpp

@ -443,12 +443,8 @@ Containers::ArrayView<const Extension> Extension::extensions(Version version) {
}
namespace {
#ifdef MAGNUM_BUILD_MULTITHREADED
#ifndef CORRADE_TARGET_APPLE
thread_local
#else
__thread
#endif
#ifdef CORRADE_BUILD_MULTITHREADED
CORRADE_THREAD_LOCAL
#endif
Context* currentContext = nullptr;
}

14
src/Magnum/GL/Context.h

@ -146,6 +146,14 @@ Note that all options are prefixed with `--magnum-` to avoid conflicts with
options passed to the application itself. Options that don't have this prefix
are completely ignored, see documentation of the
@ref Utility-Arguments-delegating "Utility::Arguments" class for details.
@section GL-Context-multithreading Thread safety
If Corrade is compiled with @ref CORRADE_BUILD_MULTITHREADED (the default), the
@ref hasCurrent() and @ref current() accessors are thread-local, matching the
OpenGL context thread locality. This might cause some performance penalties ---
if you are sure that you never need to have multiple independent thread-local
Magnum context, build Corrade with the option disabled.
*/
class MAGNUM_GL_EXPORT Context {
public:
@ -396,7 +404,7 @@ class MAGNUM_GL_EXPORT Context {
/**
* @brief Whether there is any current context
*
* If Magnum is built with @ref MAGNUM_BUILD_MULTITHREADED, current
* If Corrade is built with @ref CORRADE_BUILD_MULTITHREADED, current
* context is thread-local instead of global (the default).
* @see @ref current()
*/
@ -405,8 +413,8 @@ class MAGNUM_GL_EXPORT Context {
/**
* @brief Current context
*
* Expect that there is current context. If Magnum is built with
* @ref MAGNUM_BUILD_MULTITHREADED, current context is thread-local
* Expect that there is current context. If Corrade is built with
* @ref CORRADE_BUILD_MULTITHREADED, current context is thread-local
* instead of global (the default).
* @see @ref hasCurrent()
*/

6
src/Magnum/GL/Test/ContextGLTest.cpp

@ -79,8 +79,8 @@ void ContextGLTest::multithreaded() {
CORRADE_VERIFY(otherThreadHasCurrent);
Debug{} << "MAGNUM_BUILD_MULTITHREADED defined:" <<
#ifdef MAGNUM_BUILD_MULTITHREADED
Debug{} << "CORRADE_BUILD_MULTITHREADED defined:" <<
#ifdef CORRADE_BUILD_MULTITHREADED
true
#else
false
@ -89,7 +89,7 @@ void ContextGLTest::multithreaded() {
Debug{} << "Current context visible in another thread:" << *otherThreadHasCurrent;
#ifdef MAGNUM_BUILD_MULTITHREADED
#ifdef CORRADE_BUILD_MULTITHREADED
CORRADE_VERIFY(!*otherThreadHasCurrent);
#else
CORRADE_VERIFY(*otherThreadHasCurrent);

13
src/Magnum/Magnum.h

@ -66,16 +66,13 @@ Defined if built as static libraries. Default are shared libraries.
#define MAGNUM_BUILD_STATIC
#undef MAGNUM_BUILD_STATIC
/**
@brief Multi-threaded build
Defined if the library is built in a way that allows multiple thread-local
Magnum contexts. Enabled by default.
@see @ref building, @ref cmake,
@ref Magnum::GL::Context::current() "GL::Context::current()"
*/
#ifdef MAGNUM_BUILD_DEPRECATED
/** @brief Multi-threaded build
* @deprecated Use @ref CORRADE_BUILD_MULTITHREADED instead.
*/
#define MAGNUM_BUILD_MULTITHREADED
#undef MAGNUM_BUILD_MULTITHREADED
#endif
/**
@brief OpenGL interoperability

6
src/Magnum/Platform/gl-info.cpp

@ -241,6 +241,9 @@ MagnumInfo::MagnumInfo(const Arguments& arguments): Platform::WindowlessApplicat
#ifdef CORRADE_BUILD_STATIC
Debug() << " CORRADE_BUILD_STATIC";
#endif
#ifdef CORRADE_BUILD_MULTITHREADED
Debug() << " CORRADE_BUILD_MULTITHREADED";
#endif
#ifdef CORRADE_TARGET_UNIX
Debug() << " CORRADE_TARGET_UNIX";
#endif
@ -289,9 +292,6 @@ MagnumInfo::MagnumInfo(const Arguments& arguments): Platform::WindowlessApplicat
#ifdef MAGNUM_BUILD_STATIC
Debug() << " MAGNUM_BUILD_STATIC";
#endif
#ifdef MAGNUM_BUILD_MULTITHREADED
Debug() << " MAGNUM_BUILD_MULTITHREADED";
#endif
#ifdef MAGNUM_TARGET_GLES
Debug() << " MAGNUM_TARGET_GLES";
#endif

9
src/Magnum/configure.h.cmake

@ -27,7 +27,6 @@
#cmakedefine MAGNUM_BUILD_DEPRECATED
#cmakedefine MAGNUM_BUILD_STATIC
#cmakedefine MAGNUM_BUILD_MULTITHREADED
#cmakedefine MAGNUM_TARGET_GL
#cmakedefine MAGNUM_TARGET_GLES
#cmakedefine MAGNUM_TARGET_GLES2
@ -37,4 +36,12 @@
#cmakedefine MAGNUM_TARGET_HEADLESS
#cmakedefine MAGNUM_TARGET_VK
#ifdef MAGNUM_BUILD_DEPRECATED
#include "Corrade/configure.h"
#ifdef CORRADE_BUILD_MULTITHREADED
/* For compatibility only, to be removed at some point */
#define MAGNUM_BUILD_MULTITHREADED
#endif
#endif
#endif

Loading…
Cancel
Save