Skip to content

Commit 9f074be

Browse files
jcfrusiems
authored andcommitted
chore(generator): Prefer QTDIR for Qt headers/frameworks; fallback to QLibraryInfo
- Headers: if QTDIR/include exists, use it; otherwise treat QTDIR as the include root. This conditional append avoids re-introducing the /usr/include/qt5ln symlink workaround removed in previous commit. - Frameworks (macOS): prefer QTDIR/lib; fallback to QLibraryInfo::LibrariesPath. - Retains existing CLI/env include and framework overrides.
1 parent 4b8c2ea commit 9f074be

File tree

1 file changed

+32
-28
lines changed

1 file changed

+32
-28
lines changed

generator/main.cpp

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,23 @@ namespace
120120
}
121121
}
122122

123-
// Prefer QLibraryInfo (works without QTDIR)
124-
QString qtInclude = QLibraryInfo::location(QLibraryInfo::HeadersPath);
125-
if (!isDir(qtInclude)) {
126-
// Fallback to QTDIR/include
127-
const QString qtDir = qEnvironmentVariable("QTDIR");
128-
if (qtDir.isEmpty() || !isDir(qtDir)) {
129-
const QString reason = QStringLiteral("The QTDIR environment variable ")
130-
+ (qtDir.isEmpty()
131-
? "is not set."
132-
: "points to a non-existing directory.");
133-
qWarning() << reason << "This may cause problems with finding the necessary include files.";
134-
} else {
135-
qtInclude = joinPath(qtDir, QStringLiteral("include"));
136-
}
123+
// Prefer QTDIR first (allows targeting a different Qt).
124+
// If QTDIR/include exists use it, otherwise treat QTDIR as the include root
125+
QString qtInclude;
126+
const QString qtDir = qEnvironmentVariable("QTDIR");
127+
if (!qtDir.isEmpty() && isDir(qtDir)) {
128+
const QString qtIncludeUnder = joinPath(qtDir, QStringLiteral("include"));
129+
qtInclude = isDir(qtIncludeUnder) ? qtIncludeUnder : qtDir;
130+
} else {
131+
const QString reason = QStringLiteral("The QTDIR environment variable ")
132+
+ (qtDir.isEmpty()
133+
? "is not set."
134+
: "points to a non-existing directory.");
135+
qWarning().noquote() << reason << "Falling back to QLibraryInfo includes path.";
136+
}
137+
// Fallback to QLibraryInfo (works without QTDIR or when QTDIR unusable)
138+
if (qtInclude.isEmpty()) {
139+
qtInclude = QLibraryInfo::location(QLibraryInfo::HeadersPath);
137140
}
138141
if (!qtInclude.isEmpty() && isDir(qtInclude)) {
139142
qInfo() << "Using Qt headers at:" << qtInclude;
@@ -184,20 +187,21 @@ namespace
184187
}
185188
}
186189

187-
// Prefer QLibraryInfo (works without QTDIR)
188-
QString qtLib = QLibraryInfo::location(QLibraryInfo::LibrariesPath);
189-
if (!isDir(qtLib)) {
190-
// Fallback to QTDIR/include
191-
const QString qtDir = qEnvironmentVariable("QTDIR");
192-
if (qtDir.isEmpty() || !isDir(qtDir)) {
193-
const QString reason = QStringLiteral("The QTDIR environment variable ")
194-
+ (qtDir.isEmpty()
195-
? "is not set."
196-
: "points to a non-existing directory.");
197-
qWarning() << reason << "This may cause problems with finding the necessary framework files.";
198-
} else {
199-
qtLib = joinPath(qtDir, QStringLiteral("lib"));
200-
}
190+
// Prefer QTDIR/lib first (allows targeting a different Qt)
191+
QString qtLib;
192+
const QString qtDir = qEnvironmentVariable("QTDIR");
193+
if (!qtDir.isEmpty() && isDir(qtDir)) {
194+
qtLib = joinPath(qtDir, QStringLiteral("lib"));
195+
} else {
196+
const QString reason = QStringLiteral("The QTDIR environment variable ")
197+
+ (qtDir.isEmpty()
198+
? "is not set."
199+
: "points to a non-existing directory.");
200+
qWarning().noquote() << reason << "Falling back to QLibraryInfo libraries path.";
201+
}
202+
// Fallback to QLibraryInfo (works without QTDIR or when QTDIR unusable)
203+
if(qtLib.isEmpty()) {
204+
qtLib = QLibraryInfo::location(QLibraryInfo::LibrariesPath);
201205
}
202206
if (!qtLib.isEmpty() && isDir(qtLib)) {
203207
qInfo() << "Using Qt frameworks at:" << qtLib;

0 commit comments

Comments
 (0)