Skip to content

Commit 98be1a1

Browse files
Merge pull request #46 from Dushistov/apk-build-type
make possible to set apk build type
2 parents f52de83 + a1b0cce commit 98be1a1

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

AddQtAndroidApk.cmake

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ include(CMakeParseArguments)
6767
macro(add_qt_android_apk TARGET SOURCE_TARGET)
6868

6969
# parse the macro arguments
70-
cmake_parse_arguments(ARG "INSTALL" "NAME;VERSION_CODE;PACKAGE_NAME;PACKAGE_SOURCES;KEYSTORE_PASSWORD" "DEPENDS;KEYSTORE" ${ARGN})
70+
cmake_parse_arguments(ARG "INSTALL" "NAME;VERSION_CODE;PACKAGE_NAME;PACKAGE_SOURCES;KEYSTORE_PASSWORD" "DEPENDS;KEYSTORE;APK_BUILD_TYPE" ${ARGN})
7171

7272
# extract the full path of the source target binary
7373
set(QT_ANDROID_APP_PATH "$<TARGET_FILE:${SOURCE_TARGET}>") # full file path to the app's main shared library
@@ -277,12 +277,19 @@ macro(add_qt_android_apk TARGET SOURCE_TARGET)
277277
endif()
278278

279279
# determine the build type to pass to androiddeployqt
280-
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug" AND NOT ARG_KEYSTORE)
280+
string(STRIP "${ARG_APK_BUILD_TYPE}" ARG_APK_BUILD_TYPE)
281+
string(TOLOWER "${ARG_APK_BUILD_TYPE}" ARG_APK_BUILD_TYPE)
282+
if (NOT ARG_APK_BUILD_TYPE OR "${ARG_APK_BUILD_TYPE}" STREQUAL "auto")
283+
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug" AND NOT ARG_KEYSTORE)
281284
set(QT_ANDROID_BUILD_TYPE --debug)
282-
else()
285+
else()
283286
set(QT_ANDROID_BUILD_TYPE --release)
284-
endif()
285-
287+
endif()
288+
elseif ("${ARG_APK_BUILD_TYPE}" STREQUAL "debug" OR "${ARG_APK_BUILD_TYPE}" STREQUAL "release")
289+
set(QT_ANDROID_BUILD_TYPE "--${ARG_APK_BUILD_TYPE}")
290+
else ()
291+
message(FATAL_ERROR "Unsupport APK_BUILD_TYPE ${ARG_APK_BUILD_TYPE}")
292+
endif ()
286293
# create a custom command that will run the androiddeployqt utility to prepare the Android package
287294
add_custom_target(
288295
${TARGET}

readme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ add_qt_android_apk(my_app_apk my_app
180180
)
181181
```
182182

183+
### APK_BUILD_TYPE
184+
185+
Android (.apk) build type: "release" or "debug". Possible values: "auto", "debug" and "release". By default, without setting `APK_BUILD_TYPE` explicitly value is "auto".
186+
"auto" cause setting `APK_BUILD_TYPE` depend on `CMAKE_BUILD_TYPE`.
187+
183188
### INSTALL
184189

185190
If this option is given, the created APK will be deployed to a connected Android device. By default, the chosen device is the default one, i.e. the first one of the ADB device list.

0 commit comments

Comments
 (0)