android_openssl icon indicating copy to clipboard operation
android_openssl copied to clipboard

QT_VERSION is empty in cmakelists.txt

Open Markus43 opened this issue 3 years ago • 0 comments

In recent versions of Qt, ANDROID_EXTRA_LIBS must be defined before the first call of FindPackage(Qt5 ...), this is at least what the example projects suggest.

So it is very likely that users have an include(android_openssl/cmakelists.txt) before any calls to FindPackage(Qt5). In this case, QT_VERSION is not defined yet when the include file is parsed.

Anyhow, the version detection currently is working, even if it doesn't look like this: All comparisons with the undefined variable return false, and this way if (NOT (QT_VERSION LESS 5.14.0)) is the if branch that finally succeeds.

I believe that the following code at the beginning of cmakelists.txt would solve the issue:

if(NOT DEFINED QT_VERSION)
find_program(QMAKE_EXE NAMES qmake)
execute_process(COMMAND ${QMAKE_EXE} -query QT_VERSION OUTPUT_VARIABLE QT_VERSION)
endif()

Note that find_program will work here because CMAKE_PREFIX_PATH must contain the base directory of Qt according to the Qt documentation, so this solution is independent of Qt Creator.

I do not have the old versions of Qt available here so I cannot test this code, and I didn't want to create a PR for code that I could not try out.

Markus43 avatar Jan 26 '21 08:01 Markus43