-
Notifications
You must be signed in to change notification settings - Fork 157
add_android_openssl_libraries: Automatically link OpenSSL on argument… #67
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
base: master
Are you sure you want to change the base?
Conversation
For the record, |
android_openssl.cmake
Outdated
@@ -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) |
There was a problem hiding this comment.
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
android_openssl.cmake
Outdated
${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 |
There was a problem hiding this comment.
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_openssl.cmake
Outdated
endif() | ||
|
||
if(Qt6_VERSION VERSION_GREATER_EQUAL 6.5.0) | ||
if(NOT OPENSSL_ROOT_DIR) | ||
set(OPENSSL_ROOT_DIR ${SSL_ROOT_PATH}/ssl_3/${CMAKE_ANDROID_ARCH_ABI}) | ||
endif() | ||
list(APPEND android_extra_libs |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the record,
OpenSSL::OpenSSL
is not really the right target.FindOpenSSL
will actually createOpenSSL::crypto
andOpenSSL::ssl
, however linking against those targets is still generating errors at the CMake generation step. Couldn't figure out why yet.
This doesn't work for me, I get an error:
CMake Error at ~/Library/Android/sdk/android_openssl/android_openssl.cmake:24 (target_link_libraries):
Target "tst_openssl" links to:OpenSSL::OpenSSL
but the target was not found. Possible reasons include:
* There is a typo in the target name. * A find_package call is missing for an IMPORTED target. * An ALIAS target is missing.
Call Stack (most recent call first):
CMakeLists.txt:17 (add_android_openssl_libraries)
@aambrosano btw the commit message doesn't explain why such patch is needed, is it trying to fix some bug? |
@aambrosano on this
It doesn't work because the targets should be OpenSSL::Crypto and OpenSSL::SSL not OpenSSL::crypto and OpenSSL::ssl. |
@Issam-b it just made sense that we linked against OpenSSL in the targets we passed to
|
I was just typing targets names off the top of my head when commenting, but was using the right names when coding. That will not work anyway because for some reason targets found within a function are not available outside of the scope of the function. Trying to link against
Even when converting the function to a macro (which has its own caveats anyway) the listing will produce the same error. Will have to think about this one a bit more. |
@aambrosano do you still have the issue above? things work right on my side with this PR, I'd like to check that before submitting this. |
android_openssl.cmake
Outdated
endif() | ||
|
||
set_target_properties(${ARGN} PROPERTIES QT_ANDROID_EXTRA_LIBS | ||
"${android_extra_libs}") | ||
find_package(OpenSSL REQUIRED GLOBAL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 comments here
-
GLOBAL
option was introduced in cmake 3.24. Any project using a lower cmake version would not be able to use this function anymore. This includes also latest Qt projects, which require a minimum of 3.22. -
Even if the cmake verison was not an issue, creating global targets is generally not great, because it prevents being able to create local (directory-scoped) targets with the same name, but in different directories.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took the liberty to remove that, in the last commit, @alcroito does the patch look good for you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, i don't think it looks good, but i'm not the maintainer.
aambrosano mentioned that without GLOBAL
, the targets are not available in certain cases. I believe him. So for some use cases it likely won't work. Probably has to do with the scope where the function is called, and where the app is created.
Furthermore, doing find_package
inside functions is frowned upon, because all the variables that find_package
sets won't be available outside.
Also, I find it strange to do find_package(OpenSSL) to create the targets with pre-filled input from the computed variables.
At that point you could just create the imported targets manually, and avoid the find_package
call altogether.
And minor formatting.
If the OpenSSL targets are not defined, add them with add_library() and set OPENSSL_LIB_DIR and OPENSSL_INCLUDE_DIR and store the paths to the shared libraries in the cache so that add_android_openssl_libraries() can re-use them later if OpenSSL targets are already defined.
I pushed a new version that avoids the issues pointed out by @alcroito. This is working correctly for me, @aambrosano does it work in the cases that were problematic for you before? |
… targets