Report human-readable error if Qt5Widgets is required but is not found
ClosedPublic

Authored by aspotashev on Mar 23 2019, 8:01 PM.

Details

Summary

If I have

find_package(KF5I18n ${KF5_MIN_VERSION} CONFIG REQUIRED)

in CMakeLists.txt, cmake failed with the following error:

get_target_property() called with non-existent target "Qt5::uic".

referencing the following line in KF5I18nMacros.cmake:

get_target_property(QT_UIC_EXECUTABLE Qt5::uic LOCATION)
Test Plan

Run cmake on a project with the following lines:

find_package(KF5I18n ${KF5_MIN_VERSION} CONFIG REQUIRED)
ki18n_wrap_ui(foo_SRCS bar.ui)

Diff Detail

Repository
R249 KI18n
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
aspotashev created this revision.Mar 23 2019, 8:01 PM
Restricted Application added a subscriber: kde-frameworks-devel. · View Herald TranscriptMar 23 2019, 8:01 PM
aspotashev requested review of this revision.Mar 23 2019, 8:01 PM

I'm not sure about this because

  1. Not a find_package() guru
  2. We may need to add Qt5Widgets as a new dependency of ki18n. For now ki18n won't pull qtwidgets, and your projects may fail compiling which is not very developer-friendly.
aacid added a subscriber: aacid.Mar 24 2019, 12:48 AM

That not ideal, ki18n should be usable for projects that don't use widgets too.

I'd say the bug is on the calling cmake side, if it has a ui file it must surely depend on widgets on the calling side, so just add it there?

krop added a subscriber: krop.Mar 24 2019, 8:42 AM

That not ideal, ki18n should be usable for projects that don't use widgets too.

I'd say the bug is on the calling cmake side, if it has a ui file it must surely depend on widgets on the calling side, so just add it there?

Well, KF5I18nConfig.cmake includes KF5I18nMacros.cmake that requires Qt5Widgets.

For a better visibility, I think adding this to KF5I18nConfig.cmake.in is better:

include(CMakeFindDependencyMacro)
find_dependency(Qt5Widgets @REQUIRED_QT_VERSION@)
krop added a comment.Mar 24 2019, 8:44 AM
In D20005#437029, @cgiboudeaux wrote:

That not ideal, ki18n should be usable for projects that don't use widgets too.

I'd say the bug is on the calling cmake side, if it has a ui file it must surely depend on widgets on the calling side, so just add it there?

Well, KF5I18nConfig.cmake includes KF5I18nMacros.cmake that requires Qt5Widgets.

For a better visibility, I think adding this to KF5I18nConfig.cmake.in is better:

include(CMakeFindDependencyMacro)
find_dependency(Qt5Widgets @REQUIRED_QT_VERSION@)

and in a different commit add

find_dependency(Qt5Core @REQUIRED_QT_VERSION@)

which is a public link target of ki18n

But does the code *really* need qwidget? I

In D20005#437029, @cgiboudeaux wrote:

That not ideal, ki18n should be usable for projects that don't use widgets too.

I'd say the bug is on the calling cmake side, if it has a ui file it must surely depend on widgets on the calling side, so just add it there?

Well, KF5I18nConfig.cmake includes KF5I18nMacros.cmake that requires Qt5Widgets.

Does it? it doesn't here, or you mean "requires Qt5Widgets" because it tries to use Qt5::uic ?

krop added a comment.Mar 24 2019, 10:33 AM

Well, KF5I18nConfig.cmake includes KF5I18nMacros.cmake that requires Qt5Widgets.

Does it? it doesn't here, or you mean "requires Qt5Widgets" because it tries to use Qt5::uic ?

Qt5::uic is defined in Qt5WidgetsConfigExtras.cmake

In D20005#437053, @cgiboudeaux wrote:

Well, KF5I18nConfig.cmake includes KF5I18nMacros.cmake that requires Qt5Widgets.

Does it? it doesn't here, or you mean "requires Qt5Widgets" because it tries to use Qt5::uic ?

Qt5::uic is defined in Qt5WidgetsConfigExtras.cmake

Yes, but Qt5::uic is only used if you call KI18N_WRAP_UI, if you call KI18N_WRAP_UI is because you have .ui files in your project, if you have .ui files in your project, your project should be depending on Qt5Widgets, if it's not, it's a bug because you are directly using Qt5Widgets, so just add it there.

Making ki18n depend on Qt5Widgets unconditionally because a function that you may call if you use Qt5Widgets needs Qt5Widgets doesn't seem the best of the ideas to me, there's valid use cases for ki18n to not use Qt5Widgets and in those cases it'll never go thorough KI18N_WRAP_UI, so it will just work.

aspotashev updated this revision to Diff 54695.Mar 24 2019, 5:30 PM
aspotashev retitled this revision from WIP: Find Qt5Widgets, required for Qt5::uic to Report human-readable error if Qt5Widgets is required but is not found.

Implement probably the most lightweight behaviour.

Makes sense to me

apol accepted this revision.Mar 24 2019, 10:38 PM
apol added a subscriber: apol.

LGTM

This revision is now accepted and ready to land.Mar 24 2019, 10:38 PM
This revision was automatically updated to reflect the committed changes.