2019-06-05 10:07:42 +00:00
#
2019-06-06 12:29:31 +00:00
# Self contained Platform Settings for Android
#
# Note: This file is used both by the internal and public builds.
#
#
# Public variables:
# QT_ANDROID_JAR
# Location of the adroid sdk jar for java code
# QT_ANDROID_APIVERSION
# Android API version
# QT_ANDROID_SDK_BUILD_TOOLS_VERSION
# Detected Android sdk build tools version
# QT_ANDROID_NDK_STDLIB_PATH
# Detected path to the c++ stl lib shared library
#
# Public functions:
#
2019-06-12 08:21:40 +00:00
# qt_android_generate_deployment_settings()
# Generate the deployment settings json file for a cmake target.
2019-06-05 10:07:42 +00:00
#
if ( NOT DEFINED ANDROID_SDK_ROOT )
2019-06-06 12:29:31 +00:00
message ( FATAL_ERROR "Please provide the location of the Android SDK directory via -DANDROID_SDK_ROOT=<path to Adndroid SDK>" )
2019-06-05 10:07:42 +00:00
endif ( )
if ( NOT IS_DIRECTORY "${ANDROID_SDK_ROOT}" )
message ( FATAL_ERROR "Could not find ANDROID_SDK_ROOT or path is not a directory: ${ANDROID_SDK_ROOT}" )
endif ( )
# Minimum recommend android SDK api version
2019-06-06 12:29:31 +00:00
set ( QT_ANDROID_API_VERSION "android-21" )
2019-06-05 10:07:42 +00:00
# Locate android.jar
2019-06-06 12:29:31 +00:00
set ( QT_ANDROID_JAR "${ANDROID_SDK_ROOT}/platforms/${QT_ANDROID_API_VERSION}/android.jar" )
if ( NOT EXISTS "${QT_ANDROID_JAR}" )
2019-06-05 10:07:42 +00:00
# Locate the highest available platform
file ( GLOB android_platforms
L I S T _ D I R E C T O R I E S t r u e
R E L A T I V E " $ { A N D R O I D _ S D K _ R O O T } / p l a t f o r m s "
" $ { A N D R O I D _ S D K _ R O O T } / p l a t f o r m s / * " )
# If list is not empty
if ( android_platforms )
list ( SORT android_platforms )
list ( REVERSE android_platforms )
list ( GET android_platforms 0 android_platform_latest )
2019-06-06 12:29:31 +00:00
set ( QT_ANDROID_API_VERSION ${ android_platform_latest } )
set ( QT_ANDROID_JAR "${ANDROID_SDK_ROOT}/platforms/${QT_ANDROID_API_VERSION}/android.jar" )
2019-06-05 10:07:42 +00:00
endif ( )
endif ( )
2019-06-06 12:29:31 +00:00
if ( NOT EXISTS "${QT_ANDROID_JAR}" )
message ( FATAL_ERROR "No suitable Android SDK platform found. Minimum version is ${QT_ANDROID_API_VERSION}" )
2019-06-05 10:07:42 +00:00
endif ( )
2019-06-06 12:29:31 +00:00
message ( STATUS "Using Android SDK API ${QT_ANDROID_API_VERSION} from ${ANDROID_SDK_ROOT}/platforms" )
2019-06-05 10:07:42 +00:00
# Locate Java
include ( UseJava )
# Find JDK 8.0
find_package ( Java 1.8 COMPONENTS Development REQUIRED )
2019-06-06 12:29:31 +00:00
# Locate newest android sdk build tools
if ( NOT QT_ANDROID_SDK_BUILD_TOOLS_VERSION )
file ( GLOB android_build_tools
L I S T _ D I R E C T O R I E S t r u e
R E L A T I V E " $ { A N D R O I D _ S D K _ R O O T } / b u i l d - t o o l s "
" $ { A N D R O I D _ S D K _ R O O T } / b u i l d - t o o l s / * " )
if ( NOT android_build_tools )
message ( FATAL_ERROR "Could not locate Android SDK build tools under \" ${ ANDROID_SDK } /build-tools\ "" )
endif ( )
list ( SORT android_build_tools )
list ( REVERSE android_build_tools )
list ( GET android_build_tools 0 android_build_tools_latest )
set ( qt_QT_ANDROID_SDK_BUILD_TOOLS_VERSION ${ android_build_tools_latest } )
endif ( )
# Ensure we are using the shared version of libc++
if ( NOT ANDROID_STL STREQUAL c++_shared )
message ( FATAL_ERROR "The Qt libraries on Android only supports the shared library configuration of stl. Please use -DANDROID_STL=\" c++_shared\ " as configuration argument." )
endif ( )
# Location of stdlibc++
set ( QT_ANDROID_NDK_STDLIB_PATH "${ANDROID_NDK}/sources/cxx-stl/llvm-libc++/libs/${ANDROID_ABI}/libc++_shared.so" )
# Target properties required for android deploy tool
define_property ( TARGET
P R O P E R T Y
Q T _ A N D R O I D _ D E P L O Y M E N T _ D E P E N D E N C I E S
B R I E F _ D O C S
" S p e c i f y a d d i t i o n a l p l u g i n s t h a t n e e d t o b e d e p l o y e d w i t h t h e c u r r e n t a n d r o i d a p p l i c a t i o n "
F U L L _ D O C S
" B y d e f a u l t , a n d r o i d d e p l o y q t w i l l d e t e c t t h e d e p e n d e n c i e s o f y o u r a p p l i c a t i o n . B u t s i n c e r u n - t i m e u s a g e o f p l u g i n s c a n n o t b e d e t e c t e d , t h e r e c o u l d b e f a l s e p o s i t i v e s , a s y o u r a p p l i c a t i o n w i l l d e p e n d o n a n y p l u g i n s t h a t a r e p o t e n t i a l d e p e n d e n c i e s . I f y o u w a n t t o m i n i m i z e t h e s i z e o f y o u r A P K , i t ' s p o s s i b l e t o o v e r r i d e t h e a u t o m a t i c d e t e c t i o n u s i n g t h e A N D R O I D _ D E P L O Y M E N T _ D E P E N D E N C I E S v a r i a b l e . T h i s s h o u l d c o n t a i n a l i s t o f a l l Q t f i l e s w h i c h n e e d t o b e i n c l u d e d , w i t h p a t h s r e l a t i v e t o t h e Q t i n s t a l l r o o t . N o t e t h a t o n l y t h e Q t f i l e s s p e c i f i e d h e r e w i l l b e i n c l u d e d . F a i l i n g t o i n c l u d e t h e c o r r e c t f i l e s c a n r e s u l t i n c r a s h e s . I t ' s a l s o i m p o r t a n t t o m a k e s u r e t h e f i l e s a r e l i s t e d i n t h e c o r r e c t l o a d i n g o r d e r . T h i s v a r i a b l e p r o v i d e s a w a y t o o v e r r i d e t h e a u t o m a t i c d e t e c t i o n e n t i r e l y , s o i f a l i b r a r y i s l i s t e d b e f o r e i t s d e p e n d e n c i e s , i t w i l l f a i l t o l o a d o n s o m e d e v i c e s . "
)
define_property ( TARGET
P R O P E R T Y
Q T _ A N D R O I D _ E X T R A _ L I B S
B R I E F _ D O C S
" A l i s t o f e x t e r n a l l i b r a r i e s t h a t w i l l b e c o p i e d i n t o y o u r a p p l i c a t i o n ' s l i b r a r y f o l d e r a n d l o a d e d o n s t a r t - u p . "
F U L L _ D O C S
" A l i s t o f e x t e r n a l l i b r a r i e s t h a t w i l l b e c o p i e d i n t o y o u r a p p l i c a t i o n ' s l i b r a r y f o l d e r a n d l o a d e d o n s t a r t - u p . T h i s c a n b e u s e d , f o r i n s t a n c e , t o e n a b l e O p e n S S L i n y o u r a p p l i c a t i o n . S i m p l y s e t t h e p a t h s t o t h e r e q u i r e d l i b s s l . s o a n d l i b c r y p t o . s o l i b r a r i e s h e r e a n d O p e n S S L s h o u l d b e e n a b l e d a u t o m a t i c a l l y . "
)
define_property ( TARGET
P R O P E R T Y
Q T _ A N D R O I D _ E X T R A _ P L U G I N S
B R I E F _ D O C S
" T h i s v a r i a b l e c a n b e u s e d t o s p e c i f y d i f f e r e n t r e s o u r c e s t h a t y o u r p r o j e c t h a s t o b u n d l e b u t c a n n o t b e d e l i v e r e d t h r o u g h t h e a s s e t s s y s t e m , s u c h a s q m l p l u g i n s . "
F U L L _ D O C S
" T h i s v a r i a b l e c a n b e u s e d t o s p e c i f y d i f f e r e n t r e s o u r c e s t h a t y o u r p r o j e c t h a s t o b u n d l e b u t c a n n o t b e d e l i v e r e d t h r o u g h t h e a s s e t s s y s t e m , s u c h a s q m l p l u g i n s . W h e n u s i n g t h i s v a r i a b l e , a n d r o i d d e p l o y q t w i l l m a k e s u r e e v e r y t h i n g i s p a c k a g e d a n d d e p l o y e d p r o p e r l y . "
)
define_property ( TARGET
P R O P E R T Y
Q T _ A N D R O I D _ P A C K A G E _ S O U R C E _ D I R
B R I E F _ D O C S
" T h i s v a r i a b l e c a n b e u s e d t o s p e c i f y a d i r e c t o r y w h e r e a d d i t i o n s a n d m o d i f i c a t i o n s c a n b e m a d e t o t h e d e f a u l t A n d r o i d p a c k a g e t e m p l a t e . "
F U L L _ D O C S
" T h i s v a r i a b l e c a n b e u s e d t o s p e c i f y a d i r e c t o r y w h e r e a d d i t i o n s a n d m o d i f i c a t i o n s c a n b e m a d e t o t h e d e f a u l t A n d r o i d p a c k a g e t e m p l a t e . T h e a n d r o i d d e p l o y q t t o o l w i l l c o p y t h e a p p l i c a t i o n t e m p l a t e f r o m Q t i n t o t h e b u i l d d i r e c t o r y , a n d t h e n i t w i l l c o p y t h e c o n t e n t s o f t h e A N D R O I D _ P A C K A G E _ S O U R C E _ D I R o n t o p o f t h i s , o v e r w r i t i n g a n y e x i s t i n g f i l e s . T h e u p d a t e s t e p w h e r e p a r t s o f t h e s o u r c e f i l e s a r e m o d i f i e d a u t o m a t i c a l l y t o r e f l e c t y o u r o t h e r s e t t i n g s i s t h e n r u n o n t h e r e s u l t i n g m e r g e d p a c k a g e . I f y o u , f o r i n s t a n c e , w a n t t o m a k e a c u s t o m A n d r o i d M a n i f e s t . x m l f o r y o u r a p p l i c a t i o n , t h e n p l a c e t h i s d i r e c t l y i n t o t h e f o l d e r s p e c i f i e d i n t h i s v a r i a b l e . Y o u c a n a l s o a d d c u s t o m J a v a f i l e s i n A N D R O I D _ P A C K A G E _ S O U R C E _ D I R / s r c . "
)
define_property ( TARGET
P R O P E R T Y
Q T _ A N D R O I D _ D E P L O Y M E N T _ S E T T I N G S _ F I L E
B R I E F _ D O C S
" "
F U L L _ D O C S
" "
)
# Generate deployment tool json
2019-06-12 08:21:40 +00:00
function ( qt_android_generate_deployment_settings target )
2019-06-06 12:29:31 +00:00
# Information extracted from mkspecs/features/android/android_deployment_settings.prf
if ( NOT TARGET ${ target } )
message ( SEND_ERROR "${target} is not a cmake target" )
return ( )
endif ( )
get_target_property ( target_type ${ target } TYPE )
if ( NOT "${target_type}" STREQUAL "MODULE_LIBRARY" )
2019-06-12 08:21:40 +00:00
message ( SEND_ERROR "QT_ANDROID_GENERATE_DEPLOYMENT_SETTINGS only works on Module targets" )
2019-06-06 12:29:31 +00:00
return ( )
endif ( )
get_target_property ( target_source_dir ${ target } SOURCE_DIR )
get_target_property ( target_binary_dir ${ target } BINARY_DIR )
get_target_property ( target_output_name ${ target } OUTPUT_NAME )
if ( NOT target_output_name )
set ( target_output_name ${ target } )
endif ( )
set ( deploy_file "${target_binary_dir}/android-lib${target_output_name}.so-deployment-settings.json" )
file ( WRITE ${ deploy_file } "{\n" )
# content begin
file ( APPEND ${ deploy_file }
" \ " d e s c r i p t i o n \ " : \ " T h i s f i l e i s g e n e r a t e d b y c m a k e t o b e r e a d b y a n d r o i d d e p l o y q t a n d s h o u l d n o t b e m o d i f i e d b y h a n d . \ " , \ n " )
# Host Qt Android install path
2019-06-12 08:21:40 +00:00
if ( NOT QT_BUILDING_QT )
2019-06-06 12:29:31 +00:00
set ( file_check "${Qt5_DIR}/plugins/platforms/android/libqtforandroid.so" )
if ( NOT EXISTS ${ file_check } )
2019-06-12 08:21:40 +00:00
message ( SEND_ERROR "Detected Qt installation does not contain libqtforandroid.so. This is most likely due to the installation not being a build of Qt for Android. Please update your settings." )
2019-06-06 12:29:31 +00:00
return ( )
endif ( )
set ( qt_android_install_dir ${ Qt5_Dir } )
else ( )
# Building from source, use the same install prefix
set ( qt_android_install_dir ${ CMAKE_INSTALL_PREFIX } )
endif ( )
file ( TO_NATIVE_PATH "${qt_android_install_dir}" qt_android_install_dir_native )
file ( APPEND ${ deploy_file }
" \ " q t \ " : \ " $ { q t _ a n d r o i d _ i n s t a l l _ d i r _ n a t i v e } \ " , \ n " )
# Android SDK path
file ( TO_NATIVE_PATH "${ANDROID_SDK_ROOT}" android_sdk_root_native )
file ( APPEND ${ deploy_file }
" \ " s d k \ " : \ " $ { a n d r o i d _ s d k _ r o o t _ n a t i v e } \ " , \ n " )
# Android SDK Build Tools Revision
file ( APPEND ${ deploy_file }
" \ " s d k B u i l d T o o l s R e v i s i o n \ " : \ " $ { Q T _ A N D R O I D _ S D K _ B U I L D _ T O O L S _ V E R S I O N } \ " , \ n " )
# Android NDK
file ( TO_NATIVE_PATH "${ANDROID_NDK}" android_ndk_root_native )
file ( APPEND ${ deploy_file }
" \ " n d k \ " : \ " $ { a n d r o i d _ n d k _ r o o t _ n a t i v e } \ " , \ n " )
# Setup LLVM toolchain
file ( APPEND ${ deploy_file }
" \ " t o o l c h a i n - p r e f i x \ " : \ " l l v m \ " , \ n " )
file ( APPEND ${ deploy_file }
" \ " t o o l - p r e f i x \ " : \ " l l v m \ " , \ n " )
file ( APPEND ${ deploy_file }
" \ " u s e L L V M \ " : t r u e , \ n " )
# NDK Toolchain Version
file ( APPEND ${ deploy_file }
" \ " t o o l c h a i n - v e r s i o n \ " : \ " $ { C M A K E _ A N D R O I D _ N D K _ T O O L C H A I N _ V E R S I O N } \ " , \ n " )
# NDK Host
file ( APPEND ${ deploy_file }
" \ " n d k - h o s t \ " : \ " $ { A N D R O I D _ N D K _ H O S T _ S Y S T E M _ N A M E } \ " , \ n " )
# Architecture
file ( APPEND ${ deploy_file }
" \ " t a r g e t - a r c h i t e c t u r e \ " : \ " $ { C M A K E _ A N D R O I D _ A R C H _ A B I } \ " , \ n " )
# deployment dependencies
get_target_property ( android_deployment_dependencies
$ { t a r g e t } Q T _ A N D R O I D _ D E P L O Y M E N T _ D E P E N D E N C I E S )
if ( android_deployment_dependencies )
list ( JOIN android_deployment_dependencies "," android_deployment_dependencies )
file ( APPEND ${ deploy_file }
" \ " d e p l o y m e n t - d e p e n d e n c i e s \ " : \ " $ { a n d r o i d _ d e p l o y m e n t _ d e p e n d e n c i e s } \ " , \ n " )
endif ( )
# Extra plugins
get_target_property ( android_extra_plugins
$ { t a r g e t } Q T _ A N D R O I D _ E X T R A _ P L U G I N S )
if ( android_extra_plugins )
list ( JOIN android_extra_plugins "," android_extra_plugins )
file ( APPEND ${ deploy_file }
" \ " a n d r o i d - e x t r a - p l u g i n s \ " : \ " $ { a n d r o i d _ e x t r a _ p l u g i n s } \ " , \ n " )
endif ( )
# Extra libs
get_target_property ( android_extra_libs
$ { t a r g e t } Q T _ A N D R O I D _ E X T R A _ L I B S )
if ( android_extra_libs )
list ( JOIN android_extra_libs "," android_extra_libs )
file ( APPEND ${ deploy_file }
" \ " a n d r o i d - e x t r a - l i b s \ " : \ " $ { a n d r o i d _ e x t r a _ l i b s } \ " , \ n " )
endif ( )
# package source dir
get_target_property ( android_package_source_dir
$ { t a r g e t } Q T _ A N D R O I D _ P A C K A G E _ S O U R C E _ D I R )
if ( android_package_source_dir )
file ( TO_NATIVE_PATH "${android_package_source_dir}" android_package_source_dir_native )
file ( APPEND ${ deploy_file }
" \ " a n d r o i d - p a c k a g e - s o u r c e - d i r e c t o r y \ " : \ " $ { a n d r o i d _ p a c k a g e _ s o u r c e _ d i r _ n a t i v e } \ " , \ n " )
endif ( )
#TODO: ANDROID_VERSION_NAME, doesn't seem to be used?
#TODO: ANDROID_VERSION_CODE, doesn't seem to be used?
#TODO: QML import path, could be a property? Example below:
#get_target_property(qml_import_path ${target} QT_QML_IMPORT_PATH)
#if (qml_import_path)
# file(TO_NATIVE_PATH "${qml_import_path}" qml_import_path_native)
# file(APPEND ${deploy_file}
# " \"qml-import-path\": \"${qml_import_path_native}\",\n")
#endif()
#TODO: QML root path, could be a property? Example below:
#get_target_property(qml_root_path ${target} QT_QML_ROOT_PATH)
#if(NOT qml_root_path)
# set(qml_root_path "${target_source_dir}")
#endif()
#file(TO_NATIVE_PATH "${qml_root_path}" qml_root_path_native)
#file(APPEND ${deploy_file}
# " \"qml-root-path\": \"${qml_root_path_native}\",\n")
# App binary
file ( TO_NATIVE_PATH "${target_binary_dir}/lib${target_output_name}.so" target_binary_dir_native )
file ( APPEND ${ deploy_file }
" \ " a p p l i c a t i o n - b i n a r y \ " : \ " $ { t a r g e t _ b i n a r y _ d i r _ n a t i v e } \ " , \ n " )
# Lats item in json file
file ( APPEND ${ deploy_file }
" \ " s t d c p p - p a t h \ " : \ " $ { Q T _ A N D R O I D _ N D K _ S T D L I B _ P A T H } \ " \ n " )
# content end
file ( APPEND ${ deploy_file } "}\n" )
set_target_properties ( ${ target }
P R O P E R T I E S
Q T _ A N D R O I D _ D E P L O Y M E N T _ S E T T I N G S _ F I L E $ { d e p l o y _ f i l e }
)
endfunction ( )