Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add_android_openssl_libraries: Automatically link OpenSSL on argument… #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions android_openssl.cmake
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
function(add_android_openssl_libraries)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(ssl_root_path ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/no-asm)
set(SSL_ROOT_PATH ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/no-asm)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep local variable as lowercase

else()
set(ssl_root_path ${CMAKE_CURRENT_FUNCTION_LIST_DIR})
set(SSL_ROOT_PATH ${CMAKE_CURRENT_FUNCTION_LIST_DIR})
endif()

if(Qt6_VERSION VERSION_GREATER_EQUAL 6.5.0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit simpler re-write for this could be:
`
if(Qt6_VERSION VERSION_GREATER_EQUAL 6.5.0)
set(OPENSSL_CRYPTO_LIBRARY ${ssl_root_path}/ssl_3/${CMAKE_ANDROID_ARCH_ABI}/libcrypto_3.so)
set(OPENSSL_SSL_LIBRARY ${ssl_root_path}/ssl_3/${CMAKE_ANDROID_ARCH_ABI}/libssl_3.so)
set(OPENSSL_INCLUDE_DIR ${ssl_root_path}/ssl_3/include)
else()
set(OPENSSL_CRYPTO_LIBRARY ${ssl_root_path}/ssl_1.1/${CMAKE_ANDROID_ARCH_ABI}/libcrypto_1_1.so)
set(OPENSSL_SSL_LIBRARY ${ssl_root_path}/ssl_1.1/${CMAKE_ANDROID_ARCH_ABI}/libssl_1_1.so)
set(OPENSSL_INCLUDE_DIR ${ssl_root_path}/ssl_1.1/include)
endif()

find_package(OpenSSL REQUIRED)

foreach(TARGET ${ARGN})
if (TARGET ${TARGET})
set_target_properties(${TARGET} PROPERTIES APPEND
QT_ANDROID_EXTRA_LIBS ${OPENSSL_CRYPTO_LIBRARY} ${OPENSSL_SSL_LIBRARY})
target_link_libraries(${TARGET} PUBLIC OpenSSL::OpenSSL)
endif()
endforeach()
`

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually the set_target_properties() line can be changed to
set_property(TARGET ${TARGET} APPEND PROPERTY QT_ANDROID_EXTRA_LIBS ${OPENSSL_CRYPTO_LIBRARY} ${OPENSSL_SSL_LIBRARY})

if(NOT OPENSSL_ROOT_DIR)
set(OPENSSL_ROOT_DIR ${SSL_ROOT_PATH}/ssl_3/${CMAKE_ANDROID_ARCH_ABI})
endif()
list(APPEND android_extra_libs
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we no longer need to assign this android_extra_libs list if we're doing it for OPENSSL_SSL_LIBRARY and OPENSSL_INCLUDE_DIR, we can use those latter two variables directly for QT_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)
${SSL_ROOT_PATH}/ssl_3/${CMAKE_ANDROID_ARCH_ABI}/libcrypto_3.so
${SSL_ROOT_PATH}/ssl_3/${CMAKE_ANDROID_ARCH_ABI}/libssl_3.so)
set(OPENSSL_CRYPTO_LIBRARY ${SSL_ROOT_PATH}/ssl_3/${CMAKE_ANDROID_ARCH_ABI}/libcrypto_3.so)
set(OPENSSL_SSL_LIBRARY ${SSL_ROOT_PATH}/ssl_3/${CMAKE_ANDROID_ARCH_ABI}/libssl_3.so)
set(OPENSSL_INCLUDE_DIR ${SSL_ROOT_PATH}/ssl_3/include)
else()
if(NOT OPENSSL_ROOT_DIR)
set(OPENSSL_ROOT_DIR ${SSL_ROOT_PATH}/ssl_1.1/${CMAKE_ANDROID_ARCH_ABI})
endif()
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)
${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)
set(OPENSSL_CRYPTO_LIBRARY ${SSL_ROOT_PATH}/ssl_1.1/${CMAKE_ANDROID_ARCH_ABI}/libcrypto_1_1.so)
set(OPENSSL_SSL_LIBRARY ${SSL_ROOT_PATH}/ssl_1.1/${CMAKE_ANDROID_ARCH_ABI}/libssl_1_1.so)
set(OPENSSL_INCLUDE_DIR ${SSL_ROOT_PATH}/ssl_1.1/include)
endif()

set_target_properties(${ARGN} PROPERTIES QT_ANDROID_EXTRA_LIBS
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can also be under the ${ARGN} loop

"${android_extra_libs}")
find_package(OpenSSL REQUIRED)
foreach(TARGET ${ARGN})
target_link_libraries(${TARGET} PUBLIC OpenSSL::OpenSSL)
endforeach()
endfunction()