Skip to content

BUG: Only create library if target does not exist#34

Open
agirault wants to merge 1 commit intoqt:devfrom
agirault:patch-1
Open

BUG: Only create library if target does not exist#34
agirault wants to merge 1 commit intoqt:devfrom
agirault:patch-1

Conversation

@agirault
Copy link

@agirault agirault commented Jan 20, 2020

With CMake 3.15 and Qt 5.14, the following command:

find_package(Qt5 5.14 CONFIG REQUIRED COMPONENTS Gui)

results in these errors:

CMake Error at /.../qt5/lib/cmake/Qt5Gui/Qt5Gui_QSvgPlugin.cmake:3 (add_library):
  add_library cannot create imported target "Qt5::QSvgPlugin" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /.../qt5/lib/cmake/Qt5Gui/Qt5GuiConfig.cmake:337 (include)
  /.../qt5/lib/cmake/Qt5/Qt5Config.cmake:28 (find_package)

and

CMake Error at /.../qt5/lib/cmake/Qt5Svg/Qt5Svg_QSvgIconPlugin.cmake:2 (add_library):
  add_library cannot create imported target "Qt5::QSvgIconPlugin" because
  another target with the same name already exists.
Call Stack (most recent call first):
  /.../qt5/lib/cmake/Qt5Svg/Qt5SvgConfig.cmake:337 (include)
  /.../qt5/lib/cmake/Qt5Gui/Qt5Gui_QSvgIconPlugin.cmake:8 (find_package)
  /.../qt5/lib/cmake/Qt5Gui/Qt5GuiConfig.cmake:337 (include)
  /.../qt5/lib/cmake/Qt5/Qt5Config.cmake:28 (find_package)

because the following targets are defined in two files:

  • QSvgIconPlugin: Qt5Gui_QSvgIconPlugin.cmake and Qt5Svg_QSvgIconPlugin.cmake
  • QSvgPlugin: Qt5Gui_QSvgPlugin.cmake and Qt5Svg_QSvgPlugin.cmake

Note: Qt 5.14 was retrieved as the official commercial build, not built from source.

With CMake 3.15 and Qt 5.14, the following command:
```cmake
find_package(Qt5 5.14 CONFIG REQUIRED COMPONENTS Gui)
```
results in these errors:
```
CMake Error at /.../qt5/lib/cmake/Qt5Gui/Qt5Gui_QSvgPlugin.cmake:3 (add_library):
  add_library cannot create imported target "Qt5::QSvgPlugin" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /.../qt5/lib/cmake/Qt5Gui/Qt5GuiConfig.cmake:337 (include)
  /.../qt5/lib/cmake/Qt5/Qt5Config.cmake:28 (find_package)
```
and
```
CMake Error at /.../qt5/lib/cmake/Qt5Svg/Qt5Svg_QSvgIconPlugin.cmake:2 (add_library):
  add_library cannot create imported target "Qt5::QSvgIconPlugin" because
  another target with the same name already exists.
Call Stack (most recent call first):
  /.../qt5/lib/cmake/Qt5Svg/Qt5SvgConfig.cmake:337 (include)
  /.../qt5/lib/cmake/Qt5Gui/Qt5Gui_QSvgIconPlugin.cmake:8 (find_package)
  /.../qt5/lib/cmake/Qt5Gui/Qt5GuiConfig.cmake:337 (include)
```
@agirault
Copy link
Author

cc: @KyleFromKitware, @alcroito

@KyleFromKitware
Copy link
Contributor

+1

@KyleFromKitware
Copy link
Contributor

@agirault This is only a mirror - see https://wiki.qt.io/Qt_Contribution_Guidelines for instructions on how to contribute.

@cla-assistant
Copy link

cla-assistant bot commented Nov 15, 2024

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

qtprojectorg pushed a commit that referenced this pull request Feb 14, 2025
Similar to commit 12d4bf1, which was
for QLocale. Like it, QResource can be used very late in the execution,
like for example the logging system. For example (simplified):

 #9  0x00007ffff759d497 in resourceMutex () at /io/qresource.cpp:188
 #10 0x00007ffff759d615 in QResourcePrivate::load (this=0x41c940, file=...) at /io/qresource.cpp:333
 #11 0x00007ffff759dc19 in QResourcePrivate::ensureInitialized (this=0x41c940) at /io/qresource.cpp:386
 #14 0x00007ffff75011a9 in QLibrarySettings::load() at /global/qlibraryinfo.cpp:80
 #22 0x00007ffff7501756 in havePaths () at /global/qlibraryinfo.cpp:149
 #23 0x00007ffff75028e3 in QLibraryInfoPrivate::paths (p=QLibraryInfo::DataPath, usageMode=QLibraryInfoPrivate::RegularUsage) at /global/qlibraryinfo.cpp:613
 #26 0x00007ffff758e4f0 in QLoggingRegistry::initializeRules () at /io/qloggingregistry.cpp:309
 #34 0x00007ffff758f007 in QLoggingRegistry::instance () at io/qloggingregistry.cpp:424
 #35 0x00007ffff758c50b in QLoggingCategory::init () at io/qloggingcategory.cpp:188
 #43 0x00007ffff758c6bb in QLoggingCategory::defaultCategory () at io/qloggingcategory.cpp:317
 #44 0x00007ffff750ff8e in qt_message_print (msgType=QtWarningMsg, context=..., message=...) at global/qlogging.cpp:2036
 #45 0x00007ffff7509515 in qt_message(msgType=QtWarningMsg, context=..., msg=...) at global/qlogging.cpp:360
 #46 0x00007ffff750a712 in QMessageLogger::warning (this=0x7fffffffd8b0, msg=...) at global/qlogging.cpp:600
 #47 0x00007ffff790e083 in QThreadStorageData::finish (p=0x41b588) at thread/qthreadstorage.cpp:160
 #50 0x00007ffff78ed423 in QThreadPrivate::finish (this=0x41b5e0) at thread/qthread_unix.cpp:404
 #51 0x00007ffff78ec8ed in destroy_current_thread_data (p=0x41b520) at thread/qthread_unix.cpp:154
 #52 0x00007ffff78ec9ec in Cleanup::~Cleanup () at thread/qthread_unix.cpp:204

Task-number: QTBUG-133206
Task-number: QTBUG-133500
Pick-to: 6.9 6.8
Change-Id: I7b653afb1b41ef3c1c9afffdaa93e6558740016b
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
qtprojectorg pushed a commit that referenced this pull request Feb 15, 2025
Similar to commit 12d4bf1, which was
for QLocale. Like it, QResource can be used very late in the execution,
like for example the logging system. For example (simplified):

 #9  0x00007ffff759d497 in resourceMutex () at /io/qresource.cpp:188
 #10 0x00007ffff759d615 in QResourcePrivate::load (this=0x41c940, file=...) at /io/qresource.cpp:333
 #11 0x00007ffff759dc19 in QResourcePrivate::ensureInitialized (this=0x41c940) at /io/qresource.cpp:386
 #14 0x00007ffff75011a9 in QLibrarySettings::load() at /global/qlibraryinfo.cpp:80
 #22 0x00007ffff7501756 in havePaths () at /global/qlibraryinfo.cpp:149
 #23 0x00007ffff75028e3 in QLibraryInfoPrivate::paths (p=QLibraryInfo::DataPath, usageMode=QLibraryInfoPrivate::RegularUsage) at /global/qlibraryinfo.cpp:613
 #26 0x00007ffff758e4f0 in QLoggingRegistry::initializeRules () at /io/qloggingregistry.cpp:309
 #34 0x00007ffff758f007 in QLoggingRegistry::instance () at io/qloggingregistry.cpp:424
 #35 0x00007ffff758c50b in QLoggingCategory::init () at io/qloggingcategory.cpp:188
 #43 0x00007ffff758c6bb in QLoggingCategory::defaultCategory () at io/qloggingcategory.cpp:317
 #44 0x00007ffff750ff8e in qt_message_print (msgType=QtWarningMsg, context=..., message=...) at global/qlogging.cpp:2036
 #45 0x00007ffff7509515 in qt_message(msgType=QtWarningMsg, context=..., msg=...) at global/qlogging.cpp:360
 #46 0x00007ffff750a712 in QMessageLogger::warning (this=0x7fffffffd8b0, msg=...) at global/qlogging.cpp:600
 #47 0x00007ffff790e083 in QThreadStorageData::finish (p=0x41b588) at thread/qthreadstorage.cpp:160
 #50 0x00007ffff78ed423 in QThreadPrivate::finish (this=0x41b5e0) at thread/qthread_unix.cpp:404
 #51 0x00007ffff78ec8ed in destroy_current_thread_data (p=0x41b520) at thread/qthread_unix.cpp:154
 #52 0x00007ffff78ec9ec in Cleanup::~Cleanup () at thread/qthread_unix.cpp:204

Task-number: QTBUG-133206
Task-number: QTBUG-133500
Pick-to: 6.8
Change-Id: I7b653afb1b41ef3c1c9afffdaa93e6558740016b
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
(cherry picked from commit ba18ae3)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
qtprojectorg pushed a commit that referenced this pull request Feb 15, 2025
Similar to commit 12d4bf1, which was
for QLocale. Like it, QResource can be used very late in the execution,
like for example the logging system. For example (simplified):

 #9  0x00007ffff759d497 in resourceMutex () at /io/qresource.cpp:188
 #10 0x00007ffff759d615 in QResourcePrivate::load (this=0x41c940, file=...) at /io/qresource.cpp:333
 #11 0x00007ffff759dc19 in QResourcePrivate::ensureInitialized (this=0x41c940) at /io/qresource.cpp:386
 #14 0x00007ffff75011a9 in QLibrarySettings::load() at /global/qlibraryinfo.cpp:80
 #22 0x00007ffff7501756 in havePaths () at /global/qlibraryinfo.cpp:149
 #23 0x00007ffff75028e3 in QLibraryInfoPrivate::paths (p=QLibraryInfo::DataPath, usageMode=QLibraryInfoPrivate::RegularUsage) at /global/qlibraryinfo.cpp:613
 #26 0x00007ffff758e4f0 in QLoggingRegistry::initializeRules () at /io/qloggingregistry.cpp:309
 #34 0x00007ffff758f007 in QLoggingRegistry::instance () at io/qloggingregistry.cpp:424
 #35 0x00007ffff758c50b in QLoggingCategory::init () at io/qloggingcategory.cpp:188
 #43 0x00007ffff758c6bb in QLoggingCategory::defaultCategory () at io/qloggingcategory.cpp:317
 #44 0x00007ffff750ff8e in qt_message_print (msgType=QtWarningMsg, context=..., message=...) at global/qlogging.cpp:2036
 #45 0x00007ffff7509515 in qt_message(msgType=QtWarningMsg, context=..., msg=...) at global/qlogging.cpp:360
 #46 0x00007ffff750a712 in QMessageLogger::warning (this=0x7fffffffd8b0, msg=...) at global/qlogging.cpp:600
 #47 0x00007ffff790e083 in QThreadStorageData::finish (p=0x41b588) at thread/qthreadstorage.cpp:160
 #50 0x00007ffff78ed423 in QThreadPrivate::finish (this=0x41b5e0) at thread/qthread_unix.cpp:404
 #51 0x00007ffff78ec8ed in destroy_current_thread_data (p=0x41b520) at thread/qthread_unix.cpp:154
 #52 0x00007ffff78ec9ec in Cleanup::~Cleanup () at thread/qthread_unix.cpp:204

Task-number: QTBUG-133206
Task-number: QTBUG-133500
Change-Id: I7b653afb1b41ef3c1c9afffdaa93e6558740016b
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
(cherry picked from commit ba18ae3)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit c6fdf95)
qtprojectorg pushed a commit that referenced this pull request Mar 28, 2025
When the test functions runs off the end (or returns from a failed
QCOMPARE/QVERIFY), `activeMenu` is destroyed while it's the
QMenuBarPrivate::activeMenu, and the following focusInEvent() on the
QMenuBar causes QMenuBarPrivate::setCurrentAction() to access
`activeMenu` when it has already ceased to be a QMenu.

Says UBSan:

  qpointer.h:75:14: runtime error: downcast of address 0x7fff87934860 which does not point to an object of type 'QMenu'
  0x7fff87934860: note: object is of type 'QWidget'
   00 00 00 00  08 f1 0e be 17 7f 00 00  80 c8 00 00 90 61 00 00  b8 f2 0e be 17 7f 00 00  00 00 62 c6
                ^~~~~~~~~~~~~~~~~~~~~~~
                vptr for 'QWidget'
    #0 0x7f17baf57be5 in QPointer<QMenu>::data() const qpointer.h:75
    #1 0x7f17baf57be5 in QPointer<QMenu>::operator QMenu*() const qpointer.h:83
    #2 0x7f17baf57be5 in QMenuBarPrivate::setCurrentAction(QAction*, bool, bool) qmenubar.cpp:351
    #3 0x7f17baf5a200 in QMenuBarPrivate::focusFirstAction() qmenubar.cpp:245
    #4 0x7f17baf5b727 in QMenuBarPrivate::focusFirstAction() qmenubar.cpp:1260
    #5 0x7f17baf5b727 in QMenuBar::focusInEvent(QFocusEvent*) qmenubar.cpp:1259
    [...]
    #34 0x7f17b93373d6 in QWidget::~QWidget() qwidget.cpp:1508
    #35 0x7f17badb4658 in QMenu::~QMenu() qmenu.cpp:1789

Since I couldn't fix the problem on short notice, I created
QTBUG-135151 to track it.

For now, simply close the QMenuBar on all exists from the test
function to avoid this code path.

Task-number: QTBUG-135151
Pick-to: 6.9 6.8 6.5
Change-Id: Id8c9ee090d8bbc5ec22ce3f2ff7485766640ab43
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
qtprojectorg pushed a commit that referenced this pull request Mar 28, 2025
When the test functions runs off the end (or returns from a failed
QCOMPARE/QVERIFY), `activeMenu` is destroyed while it's the
QMenuBarPrivate::activeMenu, and the following focusInEvent() on the
QMenuBar causes QMenuBarPrivate::setCurrentAction() to access
`activeMenu` when it has already ceased to be a QMenu.

Says UBSan:

  qpointer.h:75:14: runtime error: downcast of address 0x7fff87934860 which does not point to an object of type 'QMenu'
  0x7fff87934860: note: object is of type 'QWidget'
   00 00 00 00  08 f1 0e be 17 7f 00 00  80 c8 00 00 90 61 00 00  b8 f2 0e be 17 7f 00 00  00 00 62 c6
                ^~~~~~~~~~~~~~~~~~~~~~~
                vptr for 'QWidget'
    #0 0x7f17baf57be5 in QPointer<QMenu>::data() const qpointer.h:75
    #1 0x7f17baf57be5 in QPointer<QMenu>::operator QMenu*() const qpointer.h:83
    #2 0x7f17baf57be5 in QMenuBarPrivate::setCurrentAction(QAction*, bool, bool) qmenubar.cpp:351
    #3 0x7f17baf5a200 in QMenuBarPrivate::focusFirstAction() qmenubar.cpp:245
    #4 0x7f17baf5b727 in QMenuBarPrivate::focusFirstAction() qmenubar.cpp:1260
    #5 0x7f17baf5b727 in QMenuBar::focusInEvent(QFocusEvent*) qmenubar.cpp:1259
    [...]
    #34 0x7f17b93373d6 in QWidget::~QWidget() qwidget.cpp:1508
    #35 0x7f17badb4658 in QMenu::~QMenu() qmenu.cpp:1789

Since I couldn't fix the problem on short notice, I created
QTBUG-135151 to track it.

For now, simply close the QMenuBar on all exists from the test
function to avoid this code path.

Task-number: QTBUG-135151
Pick-to: 6.8 6.5
Change-Id: Id8c9ee090d8bbc5ec22ce3f2ff7485766640ab43
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
(cherry picked from commit 83af06b)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
qtprojectorg pushed a commit that referenced this pull request Mar 29, 2025
When the test functions runs off the end (or returns from a failed
QCOMPARE/QVERIFY), `activeMenu` is destroyed while it's the
QMenuBarPrivate::activeMenu, and the following focusInEvent() on the
QMenuBar causes QMenuBarPrivate::setCurrentAction() to access
`activeMenu` when it has already ceased to be a QMenu.

Says UBSan:

  qpointer.h:75:14: runtime error: downcast of address 0x7fff87934860 which does not point to an object of type 'QMenu'
  0x7fff87934860: note: object is of type 'QWidget'
   00 00 00 00  08 f1 0e be 17 7f 00 00  80 c8 00 00 90 61 00 00  b8 f2 0e be 17 7f 00 00  00 00 62 c6
                ^~~~~~~~~~~~~~~~~~~~~~~
                vptr for 'QWidget'
    #0 0x7f17baf57be5 in QPointer<QMenu>::data() const qpointer.h:75
    #1 0x7f17baf57be5 in QPointer<QMenu>::operator QMenu*() const qpointer.h:83
    #2 0x7f17baf57be5 in QMenuBarPrivate::setCurrentAction(QAction*, bool, bool) qmenubar.cpp:351
    #3 0x7f17baf5a200 in QMenuBarPrivate::focusFirstAction() qmenubar.cpp:245
    #4 0x7f17baf5b727 in QMenuBarPrivate::focusFirstAction() qmenubar.cpp:1260
    #5 0x7f17baf5b727 in QMenuBar::focusInEvent(QFocusEvent*) qmenubar.cpp:1259
    [...]
    #34 0x7f17b93373d6 in QWidget::~QWidget() qwidget.cpp:1508
    #35 0x7f17badb4658 in QMenu::~QMenu() qmenu.cpp:1789

Since I couldn't fix the problem on short notice, I created
QTBUG-135151 to track it.

For now, simply close the QMenuBar on all exists from the test
function to avoid this code path.

Task-number: QTBUG-135151
Pick-to: 6.5
Change-Id: Id8c9ee090d8bbc5ec22ce3f2ff7485766640ab43
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
(cherry picked from commit 83af06b)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit c6ae521)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants