Skip to content

Commit 4a6e8be

Browse files
committed
Autodetect Qt version
1 parent 2898217 commit 4a6e8be

File tree

1 file changed

+44
-42
lines changed

1 file changed

+44
-42
lines changed

src/main.cpp

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,53 @@ int main(const int argc, const char *const *const argv) {
6969
ldLog() << LD_ERROR << "No such directory:" << appDirPath.Get() << std::endl;
7070
return 1;
7171
}
72+
73+
auto qmakePath = findQmake();
74+
75+
if (qmakePath.empty()) {
76+
ldLog() << LD_ERROR << "Could not find qmake, please install or provide path using $QMAKE" << std::endl;
77+
return 1;
78+
}
79+
80+
if (!bf::exists(qmakePath)) {
81+
ldLog() << LD_ERROR << "No such file or directory:" << qmakePath << std::endl;
82+
return 1;
83+
}
7284

73-
int qtMajorVersion = 5;
74-
auto qtMajorVersionStr = getenv("QT_MAJOR_VERSION");
75-
if (qtMajorVersionStr != nullptr) {
76-
qtMajorVersion = atoi(qtMajorVersionStr);
77-
if (qtMajorVersion < 5) {
78-
ldLog() << std::endl << LD_WARNING << "Minimum Qt version supported is 5" << std::endl;
79-
qtMajorVersion = 5;
80-
}
81-
else if (qtMajorVersion > 6) {
82-
ldLog() << std::endl << LD_WARNING << "Maximum Qt version supported is 6" << std::endl;
83-
qtMajorVersion = 6;
84-
}
85+
ldLog() << "Using qmake:" << qmakePath << std::endl;
86+
87+
auto qmakeVars = queryQmake(qmakePath);
88+
89+
if (qmakeVars.empty()) {
90+
ldLog() << LD_ERROR << "Failed to query Qt paths using qmake -query" << std::endl;
91+
return 1;
92+
}
93+
94+
const bf::path qtPluginsPath = qmakeVars["QT_INSTALL_PLUGINS"];
95+
const bf::path qtLibexecsPath = qmakeVars["QT_INSTALL_LIBEXECS"];
96+
const bf::path qtDataPath = qmakeVars["QT_INSTALL_DATA"];
97+
const bf::path qtTranslationsPath = qmakeVars["QT_INSTALL_TRANSLATIONS"];
98+
const bf::path qtBinsPath = qmakeVars["QT_INSTALL_BINS"];
99+
const bf::path qtLibsPath = qmakeVars["QT_INSTALL_LIBS"];
100+
const bf::path qtInstallQmlPath = qmakeVars["QT_INSTALL_QML"];
101+
const std::string qtVersion = qmakeVars["QT_VERSION"];
102+
103+
if (qtVersion.empty()) {
104+
ldLog() << LD_ERROR << "Failed to query QT_VERSION using qmake -query" << std::endl;
105+
return 1;
85106
}
86107

87-
ldLog() << std::endl << "Using Qt" << qtMajorVersion << std::endl;
108+
int qtMajorVersion = atoi(qtVersion.c_str());
109+
if (qtMajorVersion < 5) {
110+
ldLog() << std::endl << LD_WARNING << "Minimum Qt version supported is 5" << std::endl;
111+
qtMajorVersion = 5;
112+
}
113+
else if (qtMajorVersion > 6) {
114+
ldLog() << std::endl << LD_WARNING << "Maximum Qt version supported is 6" << std::endl;
115+
qtMajorVersion = 6;
116+
}
117+
118+
ldLog() << std::endl << "Using Qt version: " << qtVersion << " (" << qtMajorVersion << ")" << std::endl;
88119

89120
appdir::AppDir appDir(appDirPath.Get());
90121

@@ -188,35 +219,6 @@ int main(const int argc, const char *const *const argv) {
188219
return 1;
189220
}
190221

191-
auto qmakePath = findQmake();
192-
193-
if (qmakePath.empty()) {
194-
ldLog() << LD_ERROR << "Could not find qmake, please install or provide path using $QMAKE" << std::endl;
195-
return 1;
196-
}
197-
198-
if (!bf::exists(qmakePath)) {
199-
ldLog() << LD_ERROR << "No such file or directory:" << qmakePath << std::endl;
200-
return 1;
201-
}
202-
203-
ldLog() << "Using qmake:" << qmakePath << std::endl;
204-
205-
auto qmakeVars = queryQmake(qmakePath);
206-
207-
if (qmakeVars.empty()) {
208-
ldLog() << LD_ERROR << "Failed to query Qt paths using qmake -query" << std::endl;
209-
return 1;
210-
}
211-
212-
const bf::path qtPluginsPath = qmakeVars["QT_INSTALL_PLUGINS"];
213-
const bf::path qtLibexecsPath = qmakeVars["QT_INSTALL_LIBEXECS"];
214-
const bf::path qtDataPath = qmakeVars["QT_INSTALL_DATA"];
215-
const bf::path qtTranslationsPath = qmakeVars["QT_INSTALL_TRANSLATIONS"];
216-
const bf::path qtBinsPath = qmakeVars["QT_INSTALL_BINS"];
217-
const bf::path qtLibsPath = qmakeVars["QT_INSTALL_LIBS"];
218-
const bf::path qtInstallQmlPath = qmakeVars["QT_INSTALL_QML"];
219-
220222
ldLog() << std::endl;
221223
ldLog() << "QT_INSTALL_LIBS:" << qtLibsPath << std::endl;
222224
std::ostringstream newLibraryPath;

0 commit comments

Comments
 (0)