Use libc++ instead of libstdc++ when compiling with android-clang mkspec

clang+libc++ is the only supported way by Google nowadays.
libstdc++ is too old and already fails to build some C++11 apps
e.g. missing std::to_string().

android-g++ mkspec still uses libstdc++ and g++.

Use -isystem to include system headers instead of QMAKE_INCDIR_POST (-I).

Task-number: QTBUG-60455
Change-Id: Iba8b04594c2e5e2832e6cf480e4e52ff31ad4106
Reviewed-by: Sérgio Martins <sergio.martins@kdab.com>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
This commit is contained in:
BogDan Vatra 2017-07-28 16:52:31 +03:00 committed by Sérgio Martins
parent 2740584e6d
commit 09ea013ae1
5 changed files with 49 additions and 39 deletions

View File

@ -15,20 +15,34 @@ QMAKE_CC = $$NDK_LLVM_PATH/bin/clang
QMAKE_CXX = $$NDK_LLVM_PATH/bin/clang++
equals(ANDROID_TARGET_ARCH, armeabi-v7a): \
QMAKE_CFLAGS = -target armv7-none-linux-androideabi
QMAKE_CFLAGS += -target armv7-none-linux-androideabi
else: equals(ANDROID_TARGET_ARCH, armeabi): \
QMAKE_CFLAGS = -target armv5te-none-linux-androideabi
QMAKE_CFLAGS += -target armv5te-none-linux-androideabi
else: equals(ANDROID_TARGET_ARCH, arm64-v8a): \
QMAKE_CFLAGS = -target aarch64-none-linux-android
QMAKE_CFLAGS += -target aarch64-none-linux-android
else: equals(ANDROID_TARGET_ARCH, x86): \
QMAKE_CFLAGS = -target i686-none-linux-android
QMAKE_CFLAGS += -target i686-none-linux-android
else: equals(ANDROID_TARGET_ARCH, x86_64): \
QMAKE_CFLAGS = -target x86_64-none-linux-android
QMAKE_CFLAGS += -target x86_64-none-linux-android
else: equals(ANDROID_TARGET_ARCH, mips): \
QMAKE_CFLAGS += -target mipsel-none-linux-android
else: equals(ANDROID_TARGET_ARCH, mips64): \
QMAKE_CFLAGS = -target mips64el-none-linux-android
QMAKE_CFLAGS += -target mips64el-none-linux-android
QMAKE_LINK = $$QMAKE_CXX $$QMAKE_CFLAGS -gcc-toolchain $$NDK_TOOLCHAIN_PATH
QMAKE_CFLAGS += -gcc-toolchain $$NDK_TOOLCHAIN_PATH
QMAKE_LINK = $$QMAKE_CXX $$QMAKE_CFLAGS -Wl,--exclude-libs,libgcc.a
QMAKE_CFLAGS += -DANDROID_HAS_WSTRING --sysroot=$$NDK_ROOT/sysroot \
-isystem $$NDK_ROOT/sysroot/usr/include/$$NDK_TOOLS_PREFIX \
-isystem $$NDK_ROOT/sources/cxx-stl/llvm-libc++/include \
-isystem $$NDK_ROOT/sources/android/support/include \
-isystem $$NDK_ROOT/sources/cxx-stl/llvm-libc++abi/include
ANDROID_SOURCES_CXX_STL_LIBDIR = $$NDK_ROOT/sources/cxx-stl/llvm-libc++/libs/$$ANDROID_TARGET_ARCH
ANDROID_STDCPP_PATH = $$ANDROID_SOURCES_CXX_STL_LIBDIR/libc++_shared.so
ANDROID_CXX_STL_LIBS = -lc++
QMAKE_ARM_CFLAGS_RELEASE = -Oz
QMAKE_ARM_CFLAGS_RELEASE_WITH_DEBUGINFO = -g -Oz
include(../common/android-base-tail.conf)

View File

@ -10,9 +10,24 @@ include(../common/gcc-base-unix.conf)
include(../common/android-base-head.conf)
QMAKE_CC = $$NDK_TOOLCHAIN_PATH/bin/$$NDK_TOOLS_PREFIX-gcc
QMAKE_CXX = $$QMAKE_GCC
QMAKE_CXX = $$NDK_TOOLCHAIN_PATH/bin/$$NDK_TOOLS_PREFIX-g++
QMAKE_LINK = $$QMAKE_CXX
QMAKE_CFLAGS =
QMAKE_LINK = $$QMAKE_GCC
ANDROID_SOURCES_CXX_STL_LIBDIR = $$NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$$NDK_TOOLCHAIN_VERSION/libs/$$ANDROID_TARGET_ARCH
ANDROID_STDCPP_PATH = $$ANDROID_SOURCES_CXX_STL_LIBDIR/libgnustl_shared.so
ANDROID_CXX_STL_LIBS = -lgnustl_shared -lgcc
QMAKE_CFLAGS += --sysroot=$$ANDROID_PLATFORM_ROOT_PATH \
-isystem $$NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$$NDK_TOOLCHAIN_VERSION/include \
-isystem $$ANDROID_SOURCES_CXX_STL_LIBDIR/include
equals(ANDROID_TARGET_ARCH, armeabi)|equals(ANDROID_TARGET_ARCH, armeabi-v7a): \
LIBGCC_PATH_FULL = $$system("$$QMAKE_CXX -mthumb-interwork -print-libgcc-file-name")
else: \
LIBGCC_PATH_FULL = $$system("$$QMAKE_CXX -print-libgcc-file-name")
ANDROID_SOURCES_CXX_STL_LIBDIR += $$dirname(LIBGCC_PATH_FULL)
QMAKE_ARM_CFLAGS_RELEASE = -Os
QMAKE_ARM_CFLAGS_RELEASE_WITH_DEBUGINFO = -g -Os
include(../common/android-base-tail.conf)

View File

@ -66,17 +66,11 @@ isEmpty(ANDROID_SDK_BUILD_TOOLS_REVISION) {
}
CONFIG += $$ANDROID_PLATFORM
QMAKE_CFLAGS = -D__ANDROID_API__=$$replace(ANDROID_PLATFORM, "android-", "")
ANDROID_PLATFORM_ROOT_PATH = $$NDK_ROOT/platforms/$$ANDROID_PLATFORM/arch-$$ANDROID_ARCHITECTURE/
ANDROID_PLATFORM_PATH = $$ANDROID_PLATFORM_ROOT_PATH/usr
# used to compile platform plugins for android-4 and android-5
QMAKE_ANDROID_PLATFORM_INCDIR = $$ANDROID_PLATFORM_PATH/include
QMAKE_ANDROID_PLATFORM_LIBDIR = $$ANDROID_PLATFORM_PATH/lib
ANDROID_SOURCES_CXX_STL_LIBDIR = $$NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$$NDK_TOOLCHAIN_VERSION/libs/$$ANDROID_TARGET_ARCH
ANDROID_SOURCES_CXX_STL_INCDIR = $$NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$$NDK_TOOLCHAIN_VERSION/include $$ANDROID_SOURCES_CXX_STL_LIBDIR/include
equals(ANDROID_TARGET_ARCH, x86_64)|equals(ANDROID_TARGET_ARCH, mips64): \
QMAKE_ANDROID_PLATFORM_LIBDIR = $${QMAKE_ANDROID_PLATFORM_LIBDIR}64
QMAKE_GCC = $$NDK_TOOLCHAIN_PATH/bin/$$NDK_TOOLS_PREFIX-g++

View File

@ -11,18 +11,11 @@ else: equals(ANDROID_TARGET_ARCH, armeabi): \
QMAKE_CFLAGS += -march=armv5te -mtune=xscale -msoft-float -fno-builtin-memmove
# -fno-builtin-memmove is used to workaround https://code.google.com/p/android/issues/detail?id=81692
QMAKE_CFLAGS += --sysroot=$$ANDROID_PLATFORM_ROOT_PATH
QMAKE_CFLAGS_WARN_ON = -Wall -W
QMAKE_CFLAGS_WARN_OFF =
equals(ANDROID_TARGET_ARCH, armeabi-v7a) | equals(ANDROID_TARGET_ARCH, armeabi) {
contains(QMAKE_COMPILER, clang) {
QMAKE_CFLAGS_RELEASE = -Oz
QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO = -g -Oz
} else {
QMAKE_CFLAGS_RELEASE = -Os
QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO = -g -Os
}
QMAKE_CFLAGS_RELEASE = $$QMAKE_ARM_CFLAGS_RELEASE
QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO = $$QMAKE_ARM_CFLAGS_RELEASE_WITH_DEBUGINFO
QMAKE_CFLAGS_DEBUG = -g -marm -O0
equals(ANDROID_TARGET_ARCH, armeabi):if(equals(NDK_TOOLCHAIN_VERSION, 4.8)|equals(NDK_TOOLCHAIN_VERSION, 4.9)) {
DEFINES += QT_OS_ANDROID_GCC_48_WORKAROUND
@ -73,19 +66,12 @@ QMAKE_STRIP =
QMAKE_RANLIB = $$NDK_TOOLCHAIN_PATH/bin/$$NDK_TOOLS_PREFIX-ranlib
equals(ANDROID_TARGET_ARCH, armeabi)|equals(ANDROID_TARGET_ARCH, armeabi-v7a): \
LIBGCC_PATH_FULL = $$system("$$QMAKE_GCC -mthumb-interwork -print-libgcc-file-name")
else: \
LIBGCC_PATH_FULL = $$system("$$QMAKE_GCC -print-libgcc-file-name")
LIBGCC_PATH = $$dirname(LIBGCC_PATH_FULL)
QMAKE_INCDIR_POST = $$ANDROID_SOURCES_CXX_STL_INCDIR $$QMAKE_ANDROID_PLATFORM_INCDIR
QMAKE_LIBDIR_POST = $$ANDROID_SOURCES_CXX_STL_LIBDIR $$QMAKE_ANDROID_PLATFORM_LIBDIR $$LIBGCC_PATH
QMAKE_INCDIR_POST =
QMAKE_LIBDIR_POST = $$ANDROID_SOURCES_CXX_STL_LIBDIR
QMAKE_INCDIR_X11 =
QMAKE_LIBDIR_X11 =
QMAKE_INCDIR_OPENGL = $$QMAKE_ANDROID_PLATFORM_INCDIR
QMAKE_LIBDIR_OPENGL = $$QMAKE_ANDROID_PLATFORM_LIBDIR
QMAKE_INCDIR_OPENGL =
QMAKE_LIBDIR_OPENGL =
QMAKE_LINK_SHLIB = $$QMAKE_LINK
QMAKE_LFLAGS = --sysroot=$$ANDROID_PLATFORM_ROOT_PATH
@ -97,7 +83,7 @@ QMAKE_LFLAGS_NOUNDEF = -Wl,--no-undefined
QMAKE_LFLAGS_RPATH = -Wl,-rpath=
QMAKE_LFLAGS_RPATHLINK = -Wl,-rpath-link=
QMAKE_LIBS_PRIVATE = -lgnustl_shared -llog -lz -lm -ldl -lc -lgcc
QMAKE_LIBS_PRIVATE = $$ANDROID_CXX_STL_LIBS -llog -lz -lm -ldl -lc
QMAKE_LIBS_X11 =
QMAKE_LIBS_THREAD =
QMAKE_LIBS_EGL = -lEGL

View File

@ -62,6 +62,7 @@ contains(TEMPLATE, ".*app"):!build_pass: {
isEmpty(QML_ROOT_PATH): \
QML_ROOT_PATH = $$_PRO_FILE_PWD_
FILE_CONTENT += " \"qml-root-path\": $$emitString($$QML_ROOT_PATH),"
FILE_CONTENT += " \"stdcpp-path\": $$emitString($$ANDROID_STDCPP_PATH),"
FILE_CONTENT += " \"application-binary\": $$emitString($$absolute_path($$DESTDIR, $$OUT_PWD)/$$TARGET)"
FILE_CONTENT += "}"