Integrate android openssl fetch support

qt6-cmake-android
Simon Stürz 2025-10-10 11:09:12 +02:00 committed by Simon Stürz
parent e647ac58fc
commit 444faebc6a
4 changed files with 17 additions and 24 deletions

View File

@ -43,10 +43,17 @@ find_package(Qt6 REQUIRED COMPONENTS
Nfc
)
find_package(OpenSSL QUIET)
if(ANDROID)
find_package(OpenSSL REQUIRED)
else()
find_package(OpenSSL QUIET)
include(FetchContent)
FetchContent_Declare(
android_openssl
DOWNLOAD_EXTRACT_TIMESTAMP true
URL https://github.com/KDAB/android_openssl/archive/refs/heads/master.zip
)
FetchContent_MakeAvailable(android_openssl)
include(${android_openssl_SOURCE_DIR}/android_openssl.cmake)
endif()
# Make config.h available to all targets

View File

@ -35,13 +35,13 @@ Optional configuration flags to be passed to qmake:
> Enables building the testrunner target
## Android
When targeting Android, make sure a cross-compiled build of OpenSSL is
available to CMake (for example by setting `OPENSSL_ROOT_DIR` when
configuring). The CMake build will automatically package the resolved
`libssl` and `libcrypto` shared libraries inside the Android bundle, following
the Qt for Android OpenSSL deployment guidelines. Other platforms will build
without explicitly linking to OpenSSL if the development package is not
installed.
When targeting Android, the build will download the KDAB
[`android_openssl`](https://github.com/KDAB/android_openssl) package at
configure time and automatically bundle the provided `libssl` and `libcrypto`
shared libraries inside the APK. An active internet connection is therefore
required the first time you configure an Android build directory. Other
platforms will build without explicitly linking to OpenSSL if the development
package is not installed.
## Windows

View File

@ -99,8 +99,6 @@ target_link_libraries(nymea-app-core
if(TARGET OpenSSL::SSL AND TARGET OpenSSL::Crypto)
target_link_libraries(nymea-app-core PUBLIC OpenSSL::SSL OpenSSL::Crypto)
elseif(ANDROID)
message(FATAL_ERROR "OpenSSL libraries are required for Android builds but were not found.")
else()
message(WARNING "OpenSSL development libraries not found; continuing without explicit OpenSSL linkage.")
endif()

View File

@ -111,15 +111,3 @@ if(WIN32)
target_compile_definitions(nymea-app PRIVATE NOMINMAX)
endif()
if(ANDROID)
if(TARGET OpenSSL::SSL AND TARGET OpenSSL::Crypto)
# Ship the OpenSSL shared libraries inside the Android package as
# described in the Qt documentation so SSL works out of the box.
set_property(TARGET nymea-app APPEND PROPERTY QT_ANDROID_EXTRA_LIBS
$<TARGET_FILE:OpenSSL::SSL>
$<TARGET_FILE:OpenSSL::Crypto>
)
else()
message(WARNING "OpenSSL libraries not available; the Android package will miss SSL support.")
endif()
endif()