From ef74730a59fcfd4fff5b719c0310e817737e0efb Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Thu, 20 Jun 2019 17:38:47 +0200 Subject: CMake: Prevent creation of library target when it already exists MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When doing plugin auto-importing as part of a Qt static build, it can happen that the same module FooConfig.cmake file is loaded twice. Make sure not to create the same target twice if it was already created previously. Task-number: QTBUG-38913 Change-Id: I734c83ff3c0bb9e3ee9bff37971209c57abaa2b9 Reviewed-by: Jörg Bornemann --- mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in b/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in index d4fd057682..2b7c1d28c4 100644 --- a/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in +++ b/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in @@ -317,6 +317,22 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME}) list(REMOVE_DUPLICATES Qt5$${CMAKE_MODULE_NAME}_EXECUTABLE_COMPILE_FLAGS) !!ENDIF // TEMPLATE != aux + # It can happen that the same FooConfig.cmake file is included when calling find_package() + # on some Qt component. An example of that is when using a Qt static build with auto inclusion + # of plugins: + # + # Qt5WidgetsConfig.cmake -> Qt5GuiConfig.cmake -> Qt5Gui_QSvgIconPlugin.cmake -> + # Qt5SvgConfig.cmake -> Qt5WidgetsConfig.cmake -> + # finish processing of second Qt5WidgetsConfig.cmake -> + # return to first Qt5WidgetsConfig.cmake -> + # add_library cannot create imported target "Qt5::Widgets". + # + # Make sure to return early in the original Config inclusion, because the target has already + # been defined as part of the second inclusion. + if(TARGET Qt5::$${CMAKE_MODULE_NAME}) + return() + endif() + set(_Qt5$${CMAKE_MODULE_NAME}_LIB_DEPENDENCIES \"$${CMAKE_QT5_MODULE_DEPS}\") !!IF !isEmpty(CMAKE_INTERFACE_QT5_MODULE_DEPS) -- cgit v1.2.3