Add auto detection routines for android
Add QtAutoDectect cmake which has routines to handle the vcpkg detection as well as set up some android configuration parameters. The latter will contribute towards keeping the cmake configuration commands shorter when targeting android. Change-Id: I721291c8dce39b5c298565a46867ddcab2df90e8 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
parent
20bf867a72
commit
ccc581c9fd
@ -1,24 +1,7 @@
|
||||
cmake_minimum_required(VERSION 3.15.0)
|
||||
|
||||
if(DEFINED ENV{VCPKG_ROOT})
|
||||
set(vcpkg_toolchain_file "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
|
||||
get_filename_component(vcpkg_toolchain_file "${vcpkg_toolchain_file}" ABSOLUTE)
|
||||
|
||||
if(DEFINED CMAKE_TOOLCHAIN_FILE)
|
||||
get_filename_component(supplied_toolchain_file "${CMAKE_TOOLCHAIN_FILE}" ABSOLUTE)
|
||||
if(NOT supplied_toolchain_file STREQUAL vcpkg_toolchain_file)
|
||||
set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${CMAKE_TOOLCHAIN_FILE}" CACHE STRING "")
|
||||
endif()
|
||||
unset(supplied_toolchain_file)
|
||||
endif()
|
||||
set(CMAKE_TOOLCHAIN_FILE "${vcpkg_toolchain_file}" CACHE STRING "" FORCE)
|
||||
message(STATUS "Using vcpkg from $ENV{VCPKG_ROOT}")
|
||||
if(DEFINED ENV{VCPKG_DEFAULT_TRIPLET} AND NOT DEFINED VCPKG_TARGET_TRIPLET)
|
||||
set(VCPKG_TARGET_TRIPLET "$ENV{VCPKG_DEFAULT_TRIPLET}" CACHE STRING "")
|
||||
message(STATUS "Using vcpkg triplet ${VCPKG_TARGET_TRIPLET}")
|
||||
endif()
|
||||
unset(vcpkg_toolchain_file)
|
||||
endif()
|
||||
# Run auto detection routines
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/QtAutoDetect.cmake)
|
||||
|
||||
project(QtBase
|
||||
VERSION 6.0.0
|
||||
|
57
cmake/QtAutoDetect.cmake
Normal file
57
cmake/QtAutoDetect.cmake
Normal file
@ -0,0 +1,57 @@
|
||||
#
|
||||
# Collection of auto dection routines to improve the user eperience when
|
||||
# building Qt from source.
|
||||
#
|
||||
|
||||
function(qt_auto_detect_android)
|
||||
if(DEFINED CMAKE_TOOLCHAIN_FILE AND NOT DEFINED QT_AUTODETECT_ANDROID)
|
||||
|
||||
file(READ ${CMAKE_TOOLCHAIN_FILE} toolchain_file_content OFFSET 0 LIMIT 80)
|
||||
string(FIND ${toolchain_file_content} "The Android Open Source Project" find_result REVERSE)
|
||||
if (NOT ${find_result} EQUAL -1)
|
||||
set(android_detected TRUE)
|
||||
else()
|
||||
set(android_detected FALSE)
|
||||
endif()
|
||||
|
||||
if(android_detected)
|
||||
message(STATUS "Android toolchain file detected, checking configuration defaults...")
|
||||
if(NOT DEFINED ANDROID_NATIVE_API_LEVEL)
|
||||
message(STATUS "ANDROID_NATIVE_API_LEVEL was not specified, using API level 21 as default")
|
||||
set(ANDROID_NATIVE_API_LEVEL 21 CACHE STRING "")
|
||||
endif()
|
||||
if(NOT DEFINED ANDROID_STL)
|
||||
set(ANDROID_STL "c++_shared" CACHE STRING "")
|
||||
endif()
|
||||
endif()
|
||||
set(QT_AUTODETECT_ANDROID ${android_detected} CACHE STRING "")
|
||||
elseif (QT_AUTODETECT_ANDROID)
|
||||
message(STATUS "Android toolchain file detected")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(qt_auto_detect_vpckg)
|
||||
if(DEFINED ENV{VCPKG_ROOT})
|
||||
set(vcpkg_toolchain_file "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
|
||||
get_filename_component(vcpkg_toolchain_file "${vcpkg_toolchain_file}" ABSOLUTE)
|
||||
|
||||
if(DEFINED CMAKE_TOOLCHAIN_FILE)
|
||||
get_filename_component(supplied_toolchain_file "${CMAKE_TOOLCHAIN_FILE}" ABSOLUTE)
|
||||
if(NOT supplied_toolchain_file STREQUAL vcpkg_toolchain_file)
|
||||
set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${CMAKE_TOOLCHAIN_FILE}" CACHE STRING "")
|
||||
endif()
|
||||
unset(supplied_toolchain_file)
|
||||
endif()
|
||||
set(CMAKE_TOOLCHAIN_FILE "${vcpkg_toolchain_file}" CACHE STRING "" FORCE)
|
||||
message(STATUS "Using vcpkg from $ENV{VCPKG_ROOT}")
|
||||
if(DEFINED ENV{VCPKG_DEFAULT_TRIPLET} AND NOT DEFINED VCPKG_TARGET_TRIPLET)
|
||||
set(VCPKG_TARGET_TRIPLET "$ENV{VCPKG_DEFAULT_TRIPLET}" CACHE STRING "")
|
||||
message(STATUS "Using vcpkg triplet ${VCPKG_TARGET_TRIPLET}")
|
||||
endif()
|
||||
unset(vcpkg_toolchain_file)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
|
||||
qt_auto_detect_android()
|
||||
qt_auto_detect_vpckg()
|
@ -90,6 +90,10 @@ elseif(WIN32)
|
||||
# build gcc is picked up from %PATH%.
|
||||
list(APPEND init_platform "set(CMAKE_CXX_COMPILER \"${CMAKE_CXX_COMPILER}\" CACHE STRING \"\")")
|
||||
list(APPEND init_platform "set(CMAKE_C_COMPILER \"${CMAKE_C_COMPILER}\" CACHE STRING \"\")")
|
||||
elseif(ANDROID)
|
||||
list(APPEND init_platform "set(ANDROID_NATIVE_API_LEVEL \"${ANDROID_NATIVE_API_LEVEL}\" CACHE STRING \"\")")
|
||||
list(APPEND init_platform "set(ANDROID_STL \"${ANDROID_STL}\" CACHE STRING \"\")")
|
||||
list(APPEND init_platform "set(ANDROID_ABI \"${ANDROID_ABI}\" CACHE STRING \"\")")
|
||||
endif()
|
||||
|
||||
string(REPLACE ";" "\n" init_vcpkg "${init_vcpkg}")
|
||||
|
@ -147,13 +147,15 @@ Vcpkg for Android can be set up using the following steps:
|
||||
* Set the ``ANDROID_SDK_HOME`` environment variable to the path where you have installed the Android SDK.
|
||||
* Build Qt dependencies: ``vcpkg install @qt-packages-android.txt``
|
||||
|
||||
When running cmake in qtbase, pass ``-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake -DQT_HOST_PATH=/path/to/your/host/build -DANDROID_NATIVE_API_LEVEL=21 -DANDROID_SDK_ROOT=$ANDROID_SDK_HOME -DANDROID_STL=c++_shared -DCMAKE_INSTALL_PREFIX=$INSTALL_PATH``
|
||||
When running cmake in qtbase, pass ``-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake -DQT_HOST_PATH=/path/to/your/host/build -DANDROID_SDK_ROOT=$ANDROID_SDK_HOME -DCMAKE_INSTALL_PREFIX=$INSTALL_PATH``
|
||||
|
||||
If you don't supply the configuration argument ``-DANDROID_ABI=...``, it will default to ``armeabi-v7a``. To target other architectures, use on of the following values:
|
||||
* arm64: ``-DANDROID_ABI=arm64-v8``
|
||||
* x86: ``-DANDROID_ABI=x86``
|
||||
* x86_64: ``-DANDROID_ABI=x86_64``
|
||||
|
||||
By default we set the android API level to 21. Should you need to change this supply the following configuration argument to the above CMake call: ``-DANDROID_NATIVE_API_LEVEL=${API_LEVEL}``
|
||||
|
||||
# Debugging CMake files
|
||||
|
||||
CMake allows specifying the ``--trace`` and ``--trace-expand`` options, which work like ``qmake -d -d``: As the cmake code is evaluated, the values of parameters and variables is shown. This can be a lot of output, so you may want to redirect it to a file.
|
||||
|
Loading…
x
Reference in New Issue
Block a user