From 8df104940f1a39b4346ca57c880f619b94bd8ea5 Mon Sep 17 00:00:00 2001 From: Adam <5292991+adam-ce@users.noreply.github.com> Date: Tue, 20 Jun 2023 18:56:20 +0200 Subject: [PATCH] Add a CMake function to include the OpenSSL libs for specific targets (#48) Changes include: * Rename CMakeLists.txt to android_openssl.cmake * Move the CMake code into a function android_add_openssl_to_targets(), so that the caller can decide what targets get the OpenSSL libs * update README --- CMakeLists.txt | 18 ------------------ README.md | 35 ++++++++++++++++++++++++++++++----- android_openssl.cmake | 20 ++++++++++++++++++++ 3 files changed, 50 insertions(+), 23 deletions(-) delete mode 100644 CMakeLists.txt create mode 100644 android_openssl.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 2571e44..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -if (CMAKE_BUILD_TYPE STREQUAL "Debug") - set (SSL_ROOT_PATH ${CMAKE_CURRENT_LIST_DIR}/no-asm) -else() - set (SSL_ROOT_PATH ${CMAKE_CURRENT_LIST_DIR}) -endif() - -if (Qt6_VERSION VERSION_GREATER_EQUAL 6.5.0) - list(APPEND ANDROID_EXTRA_LIBS - ${SSL_ROOT_PATH}/ssl_3/${CMAKE_ANDROID_ARCH_ABI}/libcrypto_3.so - ${SSL_ROOT_PATH}/ssl_3/${CMAKE_ANDROID_ARCH_ABI}/libssl_3.so) -else() - list(APPEND ANDROID_EXTRA_LIBS - ${SSL_ROOT_PATH}/ssl_1.1/${CMAKE_ANDROID_ARCH_ABI}/libcrypto_1_1.so - ${SSL_ROOT_PATH}/ssl_1.1/${CMAKE_ANDROID_ARCH_ABI}/libssl_1_1.so) -endif() - -set_target_properties(${PROJECT_NAME} PROPERTIES - QT_ANDROID_EXTRA_LIBS "${ANDROID_EXTRA_LIBS}") diff --git a/README.md b/README.md index 1b83b72..207cce1 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,51 @@ # Android OpenSSL support for Qt OpenSSL scripts and binaries for Android (useful for Qt Android apps) -In this repo you can find the prebuilt OpenSSL libs for Android and a qmake include project `.pri` file that can be used integrated with Qt projects. +In this repo you can find the prebuilt OpenSSL libs for Android, a QMake include project `.pri` file that can be used integrated with Qt projects, and a `.cmake` file for CMake based projects. The following directories are available * `ssl_3`: used for Qt 6.5.0+. * `ssl_1_1`: for Qt Qt 5.12.5+, 5.13.1+, 5.14.0+, 5.15.0+, Qt 6.x.x up to 6.4.x ## How to use it - -To add OpenSSL in your QMake project, append the following to your `.pro` project file: +### QMake based projects +To add OpenSSL to your QMake project, append the following to your `.pro` project file: ``` android: include(/android_openssl.cmake) +``` + +Then + +``` +qt_add_executable(your_target_name ..) +qt_add_executable(your_second_target_name ..) + +if (ANDROID) + add_android_openssl_libraries(your_target_name your_second_target_name) +endif() + ``` ## Build Script diff --git a/android_openssl.cmake b/android_openssl.cmake new file mode 100644 index 0000000..072f355 --- /dev/null +++ b/android_openssl.cmake @@ -0,0 +1,20 @@ +function(add_android_openssl_libraries) + if (CMAKE_BUILD_TYPE STREQUAL "Debug") + set (ssl_root_path ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/no-asm) + else() + set (ssl_root_path ${CMAKE_CURRENT_FUNCTION_LIST_DIR}) + endif() + + if (Qt6_VERSION VERSION_GREATER_EQUAL 6.5.0) + list(APPEND android_extra_libs + ${ssl_root_path}/ssl_3/${CMAKE_ANDROID_ARCH_ABI}/libcrypto_3.so + ${ssl_root_path}/ssl_3/${CMAKE_ANDROID_ARCH_ABI}/libssl_3.so) + else() + list(APPEND android_extra_libs + ${ssl_root_path}/ssl_1.1/${CMAKE_ANDROID_ARCH_ABI}/libcrypto_1_1.so + ${ssl_root_path}/ssl_1.1/${CMAKE_ANDROID_ARCH_ABI}/libssl_1_1.so) + endif() + + set_target_properties(${ARGN} PROPERTIES + QT_ANDROID_EXTRA_LIBS "${android_extra_libs}") +endfunction()