diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2022-05-31 10:49:17 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2022-07-11 17:44:27 +0200 |
commit | 0bd09910a7bc00c2d2a1c9e9e36239beee8f3b51 (patch) | |
tree | acf4bbc304047838bd2b8f956cd0aa61945b9a6e | |
parent | b7591d5cb9f22c0b71c4c1f05294b26edefe8010 (diff) |
CMake: Fix No target "OpenSSL::SSL" error during prl generation
The OpenSSL non-global imported target would sometimes only be created
in the opcua module subdirectory scope, which made it unavailable for
prl processing in the plugin and qml directory scopes. Only sometimes,
because it depends on whether QtNetwork was built with openssl support
or not.
Move the find_package call higher in the directory scope tree so that
it can be seen by all libraries that need it.
In the case when QtNetwork is built with openssl support, the openssl
targets would be created in the root scope, which would cause target
global promotion issues.
To work around the issues, we first look for the openssl packages with
regular find_package, mark the targets not to be promoted, and then
use qt_find_package. The qt_find_package is needed to ensure proper
dependency registration in static builds, which was missing before due
to the missing PROVIDED_TARGETS option.
Task-number: QTBUG-96283
Task-number: QTBUG-102883
Task-number: QTBUG-103905
Change-Id: I9f7249ebcf558007abfcd269b5f42b322e1fb17e
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
(cherry picked from commit b66e1e6e5d6d444862f26f162dcb7ae12964bcc8)
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
-rw-r--r-- | src/CMakeLists.txt | 30 | ||||
-rw-r--r-- | src/opcua/configure.cmake | 4 | ||||
-rw-r--r-- | src/plugins/opcua/open62541/CMakeLists.txt | 4 |
3 files changed, 30 insertions, 8 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ed8b148..9375f5e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,3 +1,33 @@ + +# Find OpenSSL at a directory scope which is common to both the module and plugin +if (NOT CMAKE_SYSTEM_NAME STREQUAL "Windows" OR NOT CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64" + OR NOT CMAKE_SYSTEM_VERSION STREQUAL "10") + + set(_qt_opcua_openssl_version "1.1") + + # First make the openssl package and its targets available, without using qt_find_package. + # This is needed because we can't set properties on not yet existing targets. + if(NOT TARGET WrapOpenSSL::WrapOpenSSL) + find_package(WrapOpenSSL ${_qt_opcua_openssl_version}) + endif() + + # Then make sure not to promote the imported targets to global when we call qt_find_package, + # if the targets were created in the root scope when looking for the Network package + # in a static build. + foreach(_qt_ssl_target WrapOpenSSLHeaders::WrapOpenSSLHeaders + WrapOpenSSL::WrapOpenSSL) + if(TARGET ${_qt_ssl_target}) + qt_internal_disable_find_package_global_promotion(${_qt_ssl_target}) + endif() + endforeach() + + # Finally call qt_find_package with PROVIDED_TARGETS to ensure the package dependency + # is recorded for static builds. + qt_find_package(WrapOpenSSL ${_qt_opcua_openssl_version} + PROVIDED_TARGETS WrapOpenSSL::WrapOpenSSL + MODULE_NAME network QMAKE_LIB openssl) +endif() + add_subdirectory(opcua) add_subdirectory(plugins) if(TARGET Qt::Quick) diff --git a/src/opcua/configure.cmake b/src/opcua/configure.cmake index 965054d..04fa5c7 100644 --- a/src/opcua/configure.cmake +++ b/src/opcua/configure.cmake @@ -14,10 +14,6 @@ if (INPUT_open62541 STREQUAL "system") qt_find_package(Open62541 PROVIDED_TARGETS open62541) endif() qt_find_package(Uacpp PROVIDED_TARGETS uacpp) - -if (NOT CMAKE_SYSTEM_NAME STREQUAL "Windows" OR NOT CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64" OR NOT CMAKE_SYSTEM_VERSION STREQUAL "10") - find_package(WrapOpenSSL 1.1) -endif() # special case end #### Tests diff --git a/src/plugins/opcua/open62541/CMakeLists.txt b/src/plugins/opcua/open62541/CMakeLists.txt index d5c5316..7dca64a 100644 --- a/src/plugins/opcua/open62541/CMakeLists.txt +++ b/src/plugins/opcua/open62541/CMakeLists.txt @@ -51,10 +51,6 @@ qt_internal_extend_target(QOpen62541Plugin CONDITION QT_FEATURE_open62541 AND NO #special case end # special case begin -if (QT_FEATURE_open62541_security AND NOT QT_FEATURE_system_open62541) - find_package(WrapOpenSSL 1.1) -endif() - qt_internal_extend_target(QOpen62541Plugin CONDITION QT_FEATURE_open62541_security AND WrapOpenSSL_FOUND AND QT_FEATURE_open62541 AND NOT QT_FEATURE_system_open62541 DEFINES UA_ENABLE_ENCRYPTION |