aboutsummaryrefslogtreecommitdiff
path: root/toolchain
diff options
context:
space:
mode:
authorFriedrich W. H. Kossebau <kossebau@kde.org>2016-12-11 21:42:17 +0100
committerFriedrich W. H. Kossebau <kossebau@kde.org>2016-12-19 20:01:11 +0100
commit5f17bf2c0c65b60cf8b7c3090c026be26375a33b (patch)
tree7e289afd683ef27cc52ad5846ec58ca4ae079623 /toolchain
parent957e00fe3d3230882b95e2068cce8fcef8acd6a3 (diff)
downloadextra-cmake-modules-5f17bf2c0c65b60cf8b7c3090c026be26375a33b.tar.gz
extra-cmake-modules-5f17bf2c0c65b60cf8b7c3090c026be26375a33b.tar.bz2
Ignore host libs/includes/cmakeconfig files in Android toolchain
Summary: Currently (since 123d0d14017a25fb387efd8fe3c2c1323f9c3815) any find_library() and find_path() calls look both at the host and the toolchain paths, which often results in includes and/or libraries wrongly being picked up from the host system, which then results in a failed build. CMake config files have always been also looked for on the host, which most often also is not wanted and resulting in a failed build. This patch fixes that by changing the mode for finding libraries, includes & packages to ONLY (again), as also recommended in the cmake-toolchains documentation. While before CMAKE_PREFIX_PATH was recommended to let cmake e.g. discover the Qt5 for Android libs, this patch wants a custom variable ECM_ADDITIONAL_FIND_ROOT_PATH to be used instead. Reason is that CMAKE_PREFIX_PATH would be subject to the root handling, while here instead the root paths themselves are wanted. This patch does not add backward compatibility for still passing the Qt5 install prefix via CMAKE_PREFIX_PATH, as there are not that many users known yet and the old code did not work for many anyway, so the extra code hassle is not worth it. Instead the few build instructions would need to be updated (and should ask to use latest ECM in any case). Test Plan: Building Marble now works without trying to use stuff from the host system. Reviewers: #frameworks, #gcompris, #minuet, mutlaqja, sandsmark, cordlandwehr, nienhueser, apol Reviewed By: cordlandwehr, nienhueser, apol Differential Revision: https://phabricator.kde.org/D3646
Diffstat (limited to 'toolchain')
-rw-r--r--toolchain/Android.cmake50
1 files changed, 36 insertions, 14 deletions
diff --git a/toolchain/Android.cmake b/toolchain/Android.cmake
index 3dcde854..45b70849 100644
--- a/toolchain/Android.cmake
+++ b/toolchain/Android.cmake
@@ -51,6 +51,24 @@
# ``ANDROID_SDK_BUILD_TOOLS_REVISION``
# The build tools version to use. Default: ``21.1.1``.
#
+# For integrating other libraries which are not part of the Android toolchain,
+# like Qt5, and installed to a separate prefix on the host system, the install
+# prefixes of those libraries would be passed as alternative roots as list via
+# ``ECM_ADDITIONAL_FIND_ROOT_PATH``. Since 5.30.0.
+#
+# For example, for integrating a Qt5 for Android with armv7 target present at
+# ``/opt/android/Qt5/5.7/android_armv7`` and some other libraries installed to
+# the prefix ``/opt/android/foo``, you would use:
+#
+# cmake \
+# -DCMAKE_TOOLCHAIN_FILE=/usr/share/ECM/toolchain/AndroidToolchain.cmake \
+# -DECM_ADDITIONAL_FIND_ROOT_PATH="/opt/android/Qt5/5.7/android_armv7;/opt/android/foo"
+#
+# If your project uses ``find_package()`` to locate build tools on the host
+# system, make sure to pass ``CMAKE_FIND_ROOT_PATH_BOTH`` or
+# ``NO_CMAKE_FIND_ROOT_PATH`` as argument in the call. See the
+# ``find_package()`` documentation for more details.
+#
# Deploying Qt Applications
# =========================
#
@@ -142,10 +160,23 @@ endif()
SET(CMAKE_SYSTEM_NAME Android)
SET(CMAKE_SYSTEM_VERSION 1)
+SET(CMAKE_FIND_ROOT_PATH ${ANDROID_NDK} ${ECM_ADDITIONAL_FIND_ROOT_PATH})
+SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
+
set(ANDROID_TOOLCHAIN_ROOT "${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN}-${ANDROID_GCC_VERSION}/prebuilt/${_HOST}/bin")
set(ANDROID_LIBS_ROOT "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_GCC_VERSION}")
-set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM "${ANDROID_TOOLCHAIN_ROOT}")
+# includes
+include_directories(SYSTEM
+ "${CMAKE_SYSROOT}/usr/include"
+ "${ANDROID_LIBS_ROOT}/include/"
+ "${ANDROID_LIBS_ROOT}/libs/${ANDROID_ABI}/include"
+)
+
+# libraries
set(ANDROID_LIBRARIES_PATH
"${CMAKE_SYSROOT}/usr/lib")
set(CMAKE_SYSTEM_LIBRARY_PATH
@@ -164,25 +195,12 @@ find_library(GNUSTL_SHARED gnustl_shared)
if(NOT GNUSTL_SHARED)
message(FATAL_ERROR "Selected Android platform does not provide gnustl_shared: ${CMAKE_SYSTEM_LIBRARY_PATH}")
endif()
-include_directories(SYSTEM
- "${CMAKE_SYSROOT}/usr/include"
- "${ANDROID_LIBS_ROOT}/include/"
- "${ANDROID_LIBS_ROOT}/libs/${ANDROID_ABI}/include"
-)
-
-# needed for Qt to define Q_OS_ANDROID
-add_definitions(-DANDROID)
link_directories(${CMAKE_SYSTEM_LIBRARY_PATH})
set(CMAKE_C_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN}-gcc")
set(CMAKE_CXX_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN}-g++")
-SET(CMAKE_FIND_ROOT_PATH ${ANDROID_NDK})
-SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
-SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
-SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
-
set(CMAKE_EXE_LINKER_FLAGS "${GNUSTL_SHARED} -Wl,-rpath-link,${ANDROID_LIBRARIES_PATH} -llog -lz -lm -ldl -lc -lgcc" CACHE STRING "")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}" CACHE STRING "")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}" CACHE STRING "")
@@ -192,6 +210,10 @@ set(CMAKE_CXX_LINK_EXECUTABLE
"<CMAKE_CXX_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>"
)
+# needed for Qt to define Q_OS_ANDROID
+add_definitions(-DANDROID)
+
+
######### generation
set(CREATEAPK_TARGET_NAME "create-apk-${QTANDROID_EXPORTED_TARGET}")