Browse Source

Rework Android toolchain support.

* Making use of the builtin support in CMake 3.7, the old toolchain
   files are no longer needed and thus removed.
 * Switched to Clang and libc++, as it has better C++11 support. GCC
   toolchain support will phase out in the following commits.
 * Having only one PKGBUILD, building for Android ARM64 now.
 * Updated the building docs to reflect this.
pull/205/head
Vladimír Vondruš 8 years ago
parent
commit
87ba0bb265
  1. 57
      doc/building.dox
  2. 8
      doc/changelog.dox
  3. 26
      package/archlinux/PKGBUILD-android-arm64
  4. 45
      package/archlinux/PKGBUILD-android-x86
  5. 5
      src/Magnum/Platform/CMakeLists.txt
  6. 2
      toolchains

57
doc/building.dox

@ -802,44 +802,41 @@ to make it available to depending projects.
See @ref Platform::Sdl2Application documentation for more information about See @ref Platform::Sdl2Application documentation for more information about
building your projects for iOS. building your projects for iOS.
@subsection building-cross-android Cross-compiling for Android ARM and x86 @subsection building-cross-android Crosscompiling for Android
You will need [Android NDK](https://developer.android.com/tools/sdk/ndk/index.html) You will need [Android NDK](https://developer.android.com/ndk/) installed and
installed and configured and @ref building-corrade-cross-android "Corrade built for Android". configured and @ref building-corrade-cross-android "Corrade built for Android".
CMake 3.7 is required, as it has Android support builtin. The supported
toolchain is now Clang with libc++, GCC is not supported anymore.
Don't forget to adapt `ANDROID_NDK_ROOT` in `generic/Android-*.cmake` to a path Create a build directory and run `cmake` and the build command in it. Set
where NDK is installed. Default is `/opt/android-ndk`. Adapt also `CMAKE_SYSTEM_NAME` to `Android` to enable the crosscompilation,
`ANDROID_SYSROOT` to your preferred API level. You might also need to update `CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION` and `CMAKE_ANDROID_STL_TYPE` to use Clang
`ANDROID_TOOLCHAIN_PREFIX` and `ANDROID_TOOLCHAIN_ROOT` to fit your system. with libc++, `CMAKE_SYSTEM_VERSION` to minimal API version level you wish to
use and `CMAKE_ANDROID_ARCH_ABI` to target platform ABI. Check the
[CMake Android cross-compiling documentation](https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling-for-android)
for further information.
Then create a build directory and run `cmake` and the build command in it. Be If you set `CMAKE_INSTALL_PREFIX` to `/usr` subdirectory of the particular
sure to set `CMAKE_INSTALL_PREFIX` to `/usr` subdirectory of `ANDROID_SYSROOT` Android sysroot, the package will get found automatically when compiling
and specify path where Corrade is installed in `CMAKE_PREFIX_PATH`. subprojects, otherwise you may need to explicitly set `CMAKE_PREFIX_PATH`.
Note that `BUILD_STATIC` is implicitly enabled, because manually loading all Note that `BUILD_STATIC` is implicitly enabled, because manually loading all
depending shared libraries using JNI would be too inconvenient. The engine is depending shared libraries using JNI would be too inconvenient. The engine is
built for OpenGL ES 2.0 by default, switch to 3.0 by disabling `TARGET_GLES2`. built for OpenGL ES 2.0 by default, switch to 3.0 by disabling `TARGET_GLES2`.
@code{.sh} @code{.sh}
mkdir build-android-arm && cd build-android-arm mkdir build-android-arm64 && cd build-android-arm64
cmake .. \ cmake .. \
-DCMAKE_TOOLCHAIN_FILE="../toolchains/generic/Android-ARM.cmake" \ -DCMAKE_SYSTEM_NAME=Android \
-DCMAKE_SYSTEM_VERSION=22 \
-DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \
-DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang \
-DCMAKE_ANDROID_STL_TYPE=c++_static \
-DCMAKE_BUILD_TYPE=Release \ -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH=/opt/android-ndk/platforms/android-19/arch-arm/usr \ -DCMAKE_PREFIX_PATH=/opt/android-ndk/platforms/android-22/arch-arm/usr \
-DCMAKE_INSTALL_PREFIX=/opt/android-ndk/platforms/android-19/arch-arm/usr \ -DCMAKE_INSTALL_PREFIX=/opt/android-ndk/platforms/android-22/arch-arm/usr \
-DTARGET_GLES=ON -DTARGET_GLES2=OFF \ -DTARGET_GLES2=OFF \
-DWITH_ANDROIDAPPLICATION=ON
cmake --build .
@endcode
@code{.sh}
mkdir build-android-x86 && cd build-android-x86
cmake .. \
-DCMAKE_TOOLCHAIN_FILE="../toolchains/generic/Android-x86.cmake" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH=/opt/android-ndk/platforms/android-19/arch-x86/usr \
-DCMAKE_INSTALL_PREFIX=/opt/android-ndk/platforms/android-19/arch-x86/usr \
-DTARGET_GLES=ON -DTARGET_GLES2=OFF \
-DWITH_ANDROIDAPPLICATION=ON -DWITH_ANDROIDAPPLICATION=ON
cmake --build . cmake --build .
@endcode @endcode
@ -847,9 +844,9 @@ cmake --build .
Then you can install the library using @cb{.sh} cmake --build . --target install @ce Then you can install the library using @cb{.sh} cmake --build . --target install @ce
to make it available to depending projects. to make it available to depending projects.
For ArchLinux there are also prepared package files in `package/archlinux`, For ArchLinux there is also a prepared package file in `package/archlinux/`,
named `PKGBUILD-android-arm` and `PKGBUILD-android-x86`, see named `PKGBUILD-android-arm64`; see @ref building-packages-arch "above" for
@ref building-packages-arch "above" for more information. more information.
@attention @attention
On Windows it's possible that you get the following CMake error when On Windows it's possible that you get the following CMake error when

8
doc/changelog.dox

@ -38,6 +38,14 @@ See also:
@section changelog-latest Changes since 2018.02 @section changelog-latest Changes since 2018.02
@subsection changelog-latest-dependencies Dependency changes
- Building for Android now requires CMake 3.7 with builtin Android
crosscompilation support, the old toolchains were removed. Only the Clang
and libc++ toolchain is now supported, support for GCC and libstdc++ was
dropped, as it was still missing some important C++11 functionality. See
@ref building-cross-android for more information.
@subsection changelog-latest-new New features @subsection changelog-latest-new New features
- Initial support for OpenGL ES 3.2 and OpenGL 4.6 - Initial support for OpenGL ES 3.2 and OpenGL 4.6

26
package/archlinux/PKGBUILD-android-arm → package/archlinux/PKGBUILD-android-arm64

@ -1,34 +1,36 @@
# Author: mosra <mosra@centrum.cz> # Author: mosra <mosra@centrum.cz>
pkgname=android-arm-magnum pkgname=android-arm64-magnum
pkgver=dev pkgver=dev
pkgrel=1 pkgrel=1
pkgdesc="C++11/C++14 graphics middleware for games and data visualization (Android ARM)" pkgdesc="C++11/C++14 graphics middleware for games and data visualization (Android ARM64)"
arch=('any') arch=('any')
url="http://magnum.graphics" url="http://magnum.graphics"
license=('MIT') license=('MIT')
depends=('android-arm-corrade') depends=('android-arm64-corrade')
makedepends=('cmake' 'ninja' 'android-ndk' 'corrade') makedepends=('cmake' 'ninja' 'android-ndk' 'corrade')
options=('!strip' '!buildflags') options=('!strip' '!buildflags')
_rootdir=$startdir/../../ _rootdir=$startdir/../../
build() { build() {
if [ ! -d "$_rootdir/build-android-arm" ] ; then if [ ! -d "$_rootdir/build-android-arm64" ] ; then
mkdir "$_rootdir/build-android-arm" mkdir "$_rootdir/build-android-arm64"
cd "$_rootdir/build-android-arm" cd "$_rootdir/build-android-arm64"
cmake .. \ cmake .. \
-DCMAKE_TOOLCHAIN_FILE="$_rootdir/toolchains/generic/Android-ARM.cmake" \ -DCMAKE_SYSTEM_NAME=Android \
-DTARGET_GLES=ON \ -DCMAKE_SYSTEM_VERSION=22 \
-DTARGET_GLES2=ON \ -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \
-DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang \
-DCMAKE_ANDROID_STL_TYPE=c++_static \
-G Ninja -G Ninja
fi fi
cd "$_rootdir/build-android-arm" cd "$_rootdir/build-android-arm64"
cmake .. \ cmake .. \
-DCMAKE_BUILD_TYPE=Release \ -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/opt/android-ndk/platforms/android-19/arch-arm/usr \ -DCMAKE_INSTALL_PREFIX=/opt/android-ndk/platforms/android-22/arch-arm64/usr \
-DWITH_MAGNUMFONT=ON \ -DWITH_MAGNUMFONT=ON \
-DWITH_OBJIMPORTER=ON \ -DWITH_OBJIMPORTER=ON \
-DWITH_TGAIMAGECONVERTER=ON \ -DWITH_TGAIMAGECONVERTER=ON \
@ -40,6 +42,6 @@ build() {
} }
package() { package() {
cd "$_rootdir/build-android-arm" cd "$_rootdir/build-android-arm64"
DESTDIR="$pkgdir/" ninja install/strip DESTDIR="$pkgdir/" ninja install/strip
} }

45
package/archlinux/PKGBUILD-android-x86

@ -1,45 +0,0 @@
# Author: mosra <mosra@centrum.cz>
pkgname=android-x86-magnum
pkgver=dev
pkgrel=1
pkgdesc="C++11/C++14 graphics middleware for games and data visualization (Android x86)"
arch=('any')
url="http://magnum.graphics"
license=('MIT')
depends=('android-x86-corrade')
makedepends=('cmake' 'ninja' 'android-ndk 'corrade'')
options=('!strip' '!buildflags')
_rootdir=$startdir/../../
build() {
if [ ! -d "$_rootdir/build-android-x86" ] ; then
mkdir "$_rootdir/build-android-x86"
cd "$_rootdir/build-android-x86"
cmake .. \
-DCMAKE_TOOLCHAIN_FILE="$_rootdir/toolchains/generic/Android-x86.cmake" \
-DTARGET_GLES=ON \
-DTARGET_GLES2=ON \
-G Ninja
fi
cd "$_rootdir/build-android-x86"
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/opt/android-ndk/platforms/android-19/arch-x86/usr \
-DWITH_MAGNUMFONT=ON \
-DWITH_OBJIMPORTER=ON \
-DWITH_TGAIMAGECONVERTER=ON \
-DWITH_TGAIMPORTER=ON \
-DWITH_ANDROIDAPPLICATION=ON \
-DWITH_EGLCONTEXT=ON \
-DBUILD_TESTS=ON
ninja
}
package() {
cd "$_rootdir/build-android-x86"
DESTDIR="$pkgdir/" ninja install/strip
}

5
src/Magnum/Platform/CMakeLists.txt

@ -71,7 +71,7 @@ if(WITH_ANDROIDAPPLICATION)
Implementation/Egl.h) Implementation/Egl.h)
add_library(MagnumAndroidApplicationGlue OBJECT add_library(MagnumAndroidApplicationGlue OBJECT
${ANDROID_NATIVE_APP_GLUE_SRC}) "${CMAKE_ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c")
set_target_properties(MagnumAndroidApplicationGlue PROPERTIES set_target_properties(MagnumAndroidApplicationGlue PROPERTIES
CORRADE_USE_PEDANTIC_FLAGS OFF CORRADE_USE_PEDANTIC_FLAGS OFF
FOLDER "Magnum/Platform") FOLDER "Magnum/Platform")
@ -85,7 +85,8 @@ if(WITH_ANDROIDAPPLICATION)
${MagnumAndroidApplication_HEADERS} ${MagnumAndroidApplication_HEADERS}
${MagnumAndroidApplication_PRIVATE_HEADERS} ${MagnumAndroidApplication_PRIVATE_HEADERS}
$<TARGET_OBJECTS:MagnumAndroidApplicationGlue>) $<TARGET_OBJECTS:MagnumAndroidApplicationGlue>)
target_include_directories(MagnumAndroidApplication PUBLIC ${ANDROID_NATIVE_APP_GLUE_INCLUDE_DIR}) target_include_directories(MagnumAndroidApplication PUBLIC
"${CMAKE_ANDROID_NDK}/sources/android/native_app_glue/")
set_target_properties(MagnumAndroidApplication PROPERTIES set_target_properties(MagnumAndroidApplication PROPERTIES
DEBUG_POSTFIX "-d" DEBUG_POSTFIX "-d"
FOLDER "Magnum/Platform") FOLDER "Magnum/Platform")

2
toolchains

@ -1 +1 @@
Subproject commit 12407edb4a7f907a7252328e846d6007b4ccede5 Subproject commit 89a277ea8ac41b949d068fae98e6da91a28ca053
Loading…
Cancel
Save