CMake build: Make Qt6::Core5Compat available in a portable way

While porting to Qt6 we'll need the compat library at some places.
Add a custom Qt6Core5Compat target that we can unconditionally use.
For Qt5 it refers to a dummy target.
For Qt6 it refers to the actual compat library.

Task-number: QTCREATORBUG-24098
Change-Id: Idd2b9f285352f685cfe715eee3fa046dfb468873
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
Eike Ziller
2020-09-07 09:50:15 +02:00
parent 7e8c3e91a1
commit 102d8d48db
2 changed files with 16 additions and 2 deletions

View File

@@ -42,10 +42,13 @@ endif()
find_package(Qt5
${IDE_QT_VERSION_MIN}
COMPONENTS Concurrent Core Gui Network PrintSupport Qml Quick
QuickWidgets Sql Widgets Xml ${QT_TEST_COMPONENT}
QuickWidgets Sql Widgets Xml Core5Compat ${QT_TEST_COMPONENT}
REQUIRED
)
find_package(Qt5 COMPONENTS LinguistTools)
if (Qt5_VERSION VERSION_LESS 6.0.0)
install(TARGETS Qt6Core5Compat EXPORT QtCreator)
endif()
find_package(Qt5 COMPONENTS LinguistTools QUIET)
find_package(Qt5 COMPONENTS Designer DesignerComponents Help SerialPort Svg QUIET)
find_package(Threads)

View File

@@ -24,7 +24,13 @@ endif()
find_package(Qt6 ${Qt5_FIND_VERSION} CONFIG COMPONENTS Core QUIET)
if (NOT Qt6_FOUND)
# remove Core5Compat from components to find in Qt5, but add a dummy target,
# which unfortunately cannot start with "Qt6::"
list(REMOVE_ITEM Qt5_FIND_COMPONENTS Core5Compat)
find_package(Qt5 ${Qt5_FIND_VERSION} CONFIG ${__arguments} ${Qt5_FIND_COMPONENTS})
if (NOT TARGET Qt6Core5Compat)
add_library(Qt6Core5Compat INTERFACE)
endif()
# Remove Qt6 from the not found packages in Qt5 mode
get_property(not_found_packages GLOBAL PROPERTY "PACKAGES_NOT_FOUND")
@@ -50,6 +56,11 @@ foreach(comp IN LISTS Qt5_FIND_COMPONENTS)
endif()
endforeach()
# alias Qt6::Core5Compat to Qt6Core5Compat to make consistent with Qt5 path
if (TARGET Qt6::Core5Compat AND NOT TARGET Qt6CoreCompat)
add_library(Qt6Core5Compat ALIAS Qt6::Core5Compat)
endif()
set(Qt5_FOUND ${Qt6_FOUND})
set(Qt5_VERSION ${Qt6_VERSION})