git-svn-id: svn://db.shs.com.ru/pip@1013 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2020-04-14 16:59:01 +00:00
parent eee93e1783
commit 84e0e3539c
5 changed files with 290 additions and 159 deletions

View File

@@ -1,112 +1,114 @@
# Important! You should include this file
# in your top-level CMakeLists.txt
#
#
#
#
# set_version(<target> [MAJOR <value>] [MINOR <value>] [REVISION <value>] [SUFFIX <value>] [BUILD <value>] [OUTPUT <file>])
#
# Set target version, optionally creates file
#
# Create variable <target>_VERSION with full version name
#
# If OUTPUT then generate header <file> with
# version macros - <target>_VERSION_<NAME>
# Also create macro <target>_VERSION_NAME with full string version
# Attention: macro <target>_VERSION is byte-packed integer version!
#
#
#
#
# set_lang(<target> <lang> [<lang> [...]])
#
# Set target translations, e.g. "ru" "fr"
#
#
#
#
# import_version(<target> <source_target>)
#
# Copy all version components and languages from <source_target>
#
#
#
#
# set_deploy_property(<target> [SHARED | STATIC] NAME <value> [NAME <value> [...]])
#
# Set target deploy property, where NAME one of:
# * LABEL - application icon name
# * FULLNAME - package name in format "*.*.*"
# * COMPANY - company name
# * ICON - icon file path
# * INFO - additional info
#
# Specify SHARED or STATIC if your target is library
# You can setup several properties in one command
#
#
#
#
# deploy_target(<target> [DEPLOY_DIR <dir>] [DESTINATION <dir>]
# [RESOURCES <dir|file> [<dir|file> ...]]
# [PLUGINS <dir|file> [<dir|file> ...]]
# [FILES <dir|file> [<dir|file> ...]]
# [OPTIONS <flag> ...] [VERBOSE])
#
# Create make target "deploy_<target>", depends on target "deploy"
# On this target create release package, containing all dependencies:
# *.zip on Windows, *.deb on Linux and *.dmg an MacOS
#
# You should set version and deploy properties
# before call this macro, see
# "set_version()" and "set_deploy_property()"
#
# Example:
# deploy_target(my_app DESTINATION packages)
#
#
# DEPLOY_DIR - dir where you install
# * executable on Windows, Linux
# * <T>.app directory with executable on MacOS
#
# DESTINATION - dir where macro place package
# RESOURCES, PLUGINS and FILES - list of directories and files, copied to:
#
# | Windows | Linux | MacOS
# ----------|---------|---------------------------|-------------------
# RESOURCES | root | /usr/share/COMPANY/target | Contents/Resources
# PLUGINS | root | /usr/lib/COMPANY/target | Contents/PlugIns
# FILES | root | /usr/bin | Contents/MacOS
#
# Relative paths are taken from DEPLOY_DIR
# Also check library dependencies from PLUGINS and FILES
#
#
# This macro using "deploy_tool" from PIP,
# so make sure it can be executed from shell
# OPTIONS allow you to pass custom flags to "deploy_tool"
# You can see flags by launch "deploy_tool" without arguments
#
# Using CMAKE_LDD, CMAKE_OTOOL or CMAKE_OBJDUMP variable,
# depends on target platform
#
# DEPLOY_ADD_LIBPATH variable used as additional
# library search path
#
#
#
#
# make_rc(<target> <rc_out_file>)
#
# Generate Windows *.rc file from deploy properties
# and return file path to <rc_out_file>
# On other platforms this variable set to empty
#
# You should set version and deploy properties
# before call this macro, see
# "set_version()" and "set_deploy_property()"
#
#
#[[
Important! You should include this file
in your top-level CMakeLists.txt
set_version(<target> [MAJOR <value>] [MINOR <value>] [REVISION <value>] [SUFFIX <value>] [BUILD <value>] [OUTPUT <file>])
Set target version, optionally creates file
Create variable <target>_VERSION with full version name
If OUTPUT then generate header <file> with
version macros - <target>_VERSION_<NAME>
Also create macro <target>_VERSION_NAME with full string version
Attention: macro <target>_VERSION is byte-packed integer version!
set_lang(<target> <lang> [<lang> [...] ])
Set target translations, e.g. "ru" "fr"
import_version(<target> <source_target>)
Copy all version components and languages from <source_target>
set_deploy_property(<target> [SHARED | STATIC] NAME <value> [NAME <value> [...] ])
Set target deploy property, where NAME one of:
* LABEL - application icon name
* FULLNAME - package name in format "*.*.*"
* COMPANY - company name
* ICON - icon file path
* INFO - additional info
Specify SHARED or STATIC if your target is library
You can setup several properties in one command
deploy_target(<target> [DEPLOY_DIR <dir>] [DESTINATION <dir>]
[RESOURCES <dir|file> [<dir|file> ...] ]
[PLUGINS <dir|file> [<dir|file> ...] ]
[FILES <dir|file> [<dir|file> ...] ]
[OPTIONS <flag> ...] [VERBOSE])
Create make target "deploy_<target>", depends on target "deploy"
On this target create release package, containing all dependencies:
*.zip on Windows, *.deb on Linux and *.dmg an MacOS
You should set version and deploy properties
before call this macro, see
"set_version()" and "set_deploy_property()"
Example:
deploy_target(my_app DESTINATION packages)
DEPLOY_DIR - dir where you install
* executable on Windows, Linux
* <T>.app directory with executable on MacOS
DESTINATION - dir where macro place package
RESOURCES, PLUGINS and FILES - list of directories and files, copied to:
| Windows | Linux | MacOS
----------|---------|---------------------------|-------------------
RESOURCES | root | /usr/share/COMPANY/target | Contents/Resources
PLUGINS | root | /usr/lib/COMPANY/target | Contents/PlugIns
FILES | root | /usr/bin | Contents/MacOS
Relative paths are taken from DEPLOY_DIR
Also check library dependencies from PLUGINS and FILES
This macro using "deploy_tool" from PIP,
so make sure it can be executed from shell
OPTIONS allow you to pass custom flags to "deploy_tool"
You can see flags by launch "deploy_tool" without arguments
Using CMAKE_LDD, CMAKE_OTOOL or CMAKE_OBJDUMP variable,
depends on target platform
DEPLOY_ADD_LIBPATH variable used as additional
library search path
make_rc(<target> <rc_out_file>)
Generate Windows *.rc file from deploy properties
and return file path to <rc_out_file>
On other platforms this variable set to empty
You should set version and deploy properties
before call this macro, see
"set_version()" and "set_deploy_property()"
]]
cmake_policy(SET CMP0011 NEW) # don`t affect includer policies
@@ -117,6 +119,7 @@ if (POLICY CMP0053)
cmake_policy(SET CMP0053 NEW)
endif()
set(__prop_names "LABEL;FULLNAME;COMPANY;ICON;INFO")
list(APPEND __prop_names "ANDROID_TARGET_SDK;ANDROID_STORE_FILE;ANDROID_STORE_PASSWORD;ANDROID_KEY_PASSWORD;ANDROID_KEY_ALIAS")
set(__version_names "MAJOR;MINOR;REVISION;BUILD;SUFFIX")
include(TargetArch)
if (NOT MY_ARCH)
@@ -409,6 +412,24 @@ macro(__make_copy _cmd _dirs _files _dest)
endforeach()
endif()
endmacro()
#defaultConfig {
# resConfigs "ru"
#}
set(__gradle_sign
" signingConfigs {
release {
storeFile file(RELEASE_STORE_FILE)
storePassword RELEASE_STORE_PASSWORD
keyPassword RELEASE_KEY_PASSWORD
keyAlias RELEASE_KEY_ALIAS
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}")
# Help macros end
@@ -466,7 +487,7 @@ macro(deploy_target _T)
#message("depend on ${_L}")
get_target_property(_LT ${_L} TYPE)
if ("x${_LT}" STREQUAL "xSHARED_LIBRARY")
set(_DEP_LIBPATH "${_DEP_LIBPATH};$<TARGET_FILE_DIR:${_L}>")
set(_DEP_LIBPATH "${_DEP_LIBPATH}!$<TARGET_FILE_DIR:${_L}>")
set(_DEP_LIBS_CS "${_DEP_LIBS_CS};$<TARGET_FILE_DIR:${_L}>/$<TARGET_FILE_NAME:${_L}>")
set(_DEP_LIBS "${_DEP_LIBS}" "$<TARGET_FILE_DIR:${_L}>/$<TARGET_FILE_NAME:${_L}>")
endif()
@@ -576,7 +597,7 @@ macro(deploy_target _T)
# gather dir
${_CMD_}
COMMAND deploy_tool ${_VERB} ${_OPTIONS} -W "\"${CMAKE_OBJDUMP}\"" -P windows,minimal -S windows -q "\"${Qt5_ROOT}\"" -s "\"${CMAKE_PREFIX_PATH}/bin;${MINGW_BIN};${DEPLOY_ADD_LIBPATH}${_DEP_LIBPATH}\"" -o ${_AGD} -p ${_AGD} "\"${_AGD}${_T}.exe\"" ${_ADD_DEPS}
COMMAND deploy_tool ${_VERB} ${_OPTIONS} -W "\"${CMAKE_OBJDUMP}\"" -P windows,minimal -S windows -q "\"${Qt5_ROOT}\"" -s "\"${CMAKE_PREFIX_PATH}/bin!${MINGW_BIN}!${DEPLOY_ADD_LIBPATH}${_DEP_LIBPATH}\"" -o ${_AGD} -p ${_AGD} "\"${_AGD}${_T}.exe\"" ${_ADD_DEPS}
# zip
COMMAND cd "\"${_DEPLOY_DIR}\"" "&&" zip -q -r "\"${_DESTINATION}/${_TV}.zip\"" "\"${_TV}_win_${MY_ARCH}\""
COMMENT "Generating ${_TV}.zip"
@@ -610,7 +631,7 @@ macro(deploy_target _T)
${_CMD_}
#COMMAND cp ${_ICON_FN} ${_AGD}/Contents/Resources
#COMMAND cp -r ${_DEPLOY_DIR}/lang ${_AGD}/Contents/Resources
COMMAND deploy_tool ${_VERB} ${_OPTIONS} -M "${CMAKE_OTOOL}" -P cocoa,minimal -S mac -q ${Qt5_ROOT} -s "\"${CMAKE_PREFIX_PATH}/lib;${DEPLOY_ADD_LIBPATH}${_DEP_LIBPATH}\"" -o ${_AGD}/Contents/Frameworks -p ${_AGD}/Contents/PlugIns ${_AGD}/Contents/MacOS/${_T} ${_ADD_DEPS}
COMMAND deploy_tool ${_VERB} ${_OPTIONS} -M "${CMAKE_OTOOL}" -P cocoa,minimal -S mac -q ${Qt5_ROOT} -s "\"${CMAKE_PREFIX_PATH}/lib!${DEPLOY_ADD_LIBPATH}${_DEP_LIBPATH}\"" -o ${_AGD}/Contents/Frameworks -p ${_AGD}/Contents/PlugIns ${_AGD}/Contents/MacOS/${_T} ${_ADD_DEPS}
# prepare dmg dir
COMMAND rm -rf ${_DMG}
COMMAND mkdir ${_VERB} -p ${_DMG}
@@ -622,33 +643,57 @@ macro(deploy_target _T)
)
set(_has_deploy 1)
elseif (DEFINED ANDROID_PLATFORM)
set(_res_files)
set(_res_files "${_res_files}\n <qresource prefix=\"/\">")
foreach (_f ${_RES_FILES})
set(_res_files "${_res_files}\n <file>${_f}</file>")
endforeach()
set(_res_files "${_res_files}\n </qresource>")
foreach (_d ${_RES_DIRS})
file(GLOB_RECURSE _df "${_d}/*")
#message("FILES ${_d} = ${_df}")
get_filename_component(_dn "${_d}" NAME)
set(_res_files "${_res_files}\n <qresource prefix=\"${_dn}\">")
foreach (_f ${_df})
get_filename_component(_fn "${_f}" NAME)
set(_res_files "${_res_files}\n <file alias=\"${_fn}\">${_f}</file>")
endforeach()
set(_res_files "${_res_files}\n </qresource>")
endforeach()
set(_res_qrc "${CMAKE_CURRENT_BINARY_DIR}/android_res.qrc")
file(WRITE "${_res_qrc}" "<RCC>${_res_files}\n</RCC>")
#__make_copy(_CMD_ _RES_DIRS _RES_FILES "${_AGD}/res")
#__make_copy(_CMD_ _FILE_DIRS _FILE_FILES "${_AGD}/Contents/MacOS")
set(_AT ${_T}_lib)
set(_ATA ${_AT}_${ANDROID_ABI})
get_target_property(_sources ${_T} SOURCES)
get_target_property(_libs ${_T} LINK_LIBRARIES)
get_target_property(_incs ${_T} INCLUDE_DIRECTORIES)
add_library(${_ATA} SHARED ${_sources})
qt5_add_resources(_res_out "${_res_qrc}")
add_library(${_ATA} SHARED ${_sources} ${_res_out})
target_link_libraries(${_ATA} ${_libs})
target_include_directories(${_ATA} PRIVATE ${_incs})
set_target_properties(${_T} PROPERTIES EXCLUDE_FROM_ALL 1)
#message("create new target ${_ATA} ${_sources} ${_libs}")
set(_AGD "${_DEPLOY_DIR}/${_T}.android")
set(_file)
__make_dir(_CMD_ "${_AGD}")
set(_dir "${CMAKE_BINARY_DIR}/android-build/libs")
__make_copy(_CMD_ _dir _file "${_AGD}")
set(_dir "${CMAKE_CURRENT_SOURCE_DIR}/android/res")
__make_copy(_CMD_ _dir _file "${_AGD}")
set(_dir "${CMAKE_CURRENT_SOURCE_DIR}/android/src")
set(_file)
set(_dir "${CMAKE_BINARY_DIR}/android-build/libs" "${CMAKE_CURRENT_SOURCE_DIR}/android/res" "${CMAKE_CURRENT_SOURCE_DIR}/android/src")
__make_copy(_CMD_ _dir _file "${_AGD}")
set(_dir)
set(_file "${Qt5_ROOT}/src/android/templates/res/values/libs.xml")
__make_copy(_CMD_ _dir _file "${_AGD}/res/values")
__make_copy(_CMD_ _RES_DIRS _RES_FILES "${_AGD}/res")
set(_dir "${Qt5_ROOT}/src/3rdparty/gradle/gradle")
set(_file "${Qt5_ROOT}/src/3rdparty/gradle/gradlew"
"${Qt5_ROOT}/src/3rdparty/gradle/gradlew.bat")
__make_copy(_CMD_ _dir _file "${_AGD}")
#__make_copy(_CMD_ _PLUG_DIRS _PLUG_FILES "${_AGD}/")
#__make_copy(_CMD_ _FILE_DIRS _FILE_FILES "${_AGD}/Contents/MacOS")
message("bindir = ${CMAKE_CURRENT_SOURCE_DIR}")
#message("bindir = ${CMAKE_CURRENT_SOURCE_DIR}")
#get_target_property(_LL ${_T} )
set(SDK_ROOT "$ENV{ANDROID_SDK_ROOT}")
if("x${SDK_ROOT}" STREQUAL "x")
set(SDK_ROOT "$ENV{ANDROID_HOME}")
endif()
set(__archs "armeabi-v7a" "arm64-v8a" "x86" "x86_64")
set(QT_ANDROID_ARCHITECTURES)
find_library(_lib_ c++_shared)
@@ -672,7 +717,7 @@ macro(deploy_target _T)
string(REPLACE "${ANDROID_SYSROOT_${ANDROID_ABI}}" "${ANDROID_SYSROOT_${_a}}" _lib_${_a} "${_lib_}")
#message("search = ${_a_prefix}/lib")
__make_copy(_CMD_ _empty _lib_${_a} "${_AGD}/libs/${_a}")
set(_CMD_ ${_CMD_} COMMAND deploy_tool ${_VERB} ${_OPTIONS} -W "\"${CMAKE_OBJDUMP}\"" -s "\"${_a_prefix}/lib\"" -o "\"${_AGD}/libs/${_a}\"" --ignore "\"c:m:dl\"" "\"${_AGD}/libs/${_a}/lib${_AT}_${_a}.so\"" ${_ADD_DEPS})
set(_CMD_ ${_CMD_} COMMAND deploy_tool ${_VERB} ${_OPTIONS} -W "\"${CMAKE_OBJDUMP}\"" -s "${_a_prefix}/lib!${Qt5_ROOT}/lib" -o "\"${_AGD}/libs/${_a}\"" --ignore "\"c!m!dl\"" "\"${_AGD}/libs/${_a}/lib${_AT}_${_a}.so\"" ${_ADD_DEPS})
#message("c++_${_a} -> ${_lib_${_a}}")
endif()
endforeach()
@@ -683,11 +728,38 @@ macro(deploy_target _T)
set(ANDROID_VERSION "${${_T}_VERSION}")
set(ANDROID_BUILD "${${_T}_VERSION_BUILD}")
set(ANDROID_PACKAGE "${${_T}_FULLNAME}")
set(ANDROID_TARGET_SDK "${${_T}_ANDROID_TARGET_SDK}")
set(ANDROID_STORE_FILE "${${_T}_ANDROID_STORE_FILE}")
set(ANDROID_STORE_PASSWORD "${${_T}_ANDROID_STORE_PASSWORD}")
set(ANDROID_KEY_PASSWORD "${${_T}_ANDROID_KEY_PASSWORD}")
set(ANDROID_KEY_ALIAS "${${_T}_ANDROID_KEY_ALIAS}")
if (NOT IS_ABSOLUTE "${ANDROID_STORE_FILE}")
set(ANDROID_STORE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/android/${ANDROID_STORE_FILE}")
endif()
set(QT_DIR ${Qt5_ROOT})
set(_out_json "${CMAKE_CURRENT_BINARY_DIR}/${_T}_android_deployment_settings.json")
configure_file("${CMAKE_BINARY_DIR}/android_deployment_settings.json.in" "${_out_json}")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/android/AndroidManifest.xml.in" "${_AGD}/AndroidManifest.xml")
configure_file("${CMAKE_ROOT}/Modules/gradle.properties.in" "${_AGD}/gradle.properties")
set(_depstr)
foreach (_d ${ANDROID_GRADLE_DEPENDENCIES})
set(_depstr "${_depstr}\n ${_d}")
endforeach()
file(READ "${Qt5_ROOT}/src/android/templates/build.gradle" _file)
string(REPLACE "\ndependencies {" "\ndependencies {${_depstr}" _file "${_file}")
string(REPLACE "\nandroid {" "\nandroid {\n${__gradle_sign}" _file "${_file}")
string(REPLACE "['resources']" "['res']" _file "${_file}")
file(WRITE "${_AGD}/build.gradle" "${_file}")
set(_out_json "${CMAKE_CURRENT_BINARY_DIR}/${_T}_android_deployment_settings.json")
set(_CMD_ ${_CMD_} COMMAND "${SDK_ROOT}/tools/android" update project --path "\"${_AGD}\"" --target android-${ANDROID_TARGET_SDK} --name QtApp)
set(_CMD_ ${_CMD_} COMMAND "${Qt5_BIN}/androiddeployqt" --aux-mode --android-platform ${ANDROID_PLATFORM} --output "\"${_AGD}\"" --input "\"${_out_json}\"")
set(_CMD_ ${_CMD_} COMMAND "${_AGD}/gradlew" --no-daemon -p "\"${_AGD}\"" assembleDebug)
set(_CMD_ ${_CMD_} COMMAND "${_AGD}/gradlew" --no-daemon -p "\"${_AGD}\"" bundleRelease)
set(_dir)
set(_file "${_AGD}/build/outputs/apk/debug/${_T}.android-debug.apk")
if (ANDROID_STORE_FILE)
list(APPEND _file "${_AGD}/build/outputs/bundle/release/${_T}.android-release.aab")
endif()
__make_copy(_CMD_ _dir _file "${_DESTINATION}")
add_custom_target(deploy_${_T}
# gather .app dir
${_CMD_}