@@ -150,14 +150,81 @@ namespace
150150 return includes;
151151 }
152152
153+ QStringList getFrameworkDirectories (const QString &commandLineFrameworks)
154+ {
155+ QStringList frameworks;
156+ frameworks << QStringLiteral (" ." );
157+
158+ const QChar pathSplitter = QDir::listSeparator ();
159+
160+ // From env var PYTHONQT_FRAMEWORK
161+ const QString envFramework = qEnvironmentVariable (" PYTHONQT_FRAMEWORK" );
162+ if (!envFramework.isEmpty ()) {
163+ QStringList envFrameworks = envFramework.split (pathSplitter, Qt::SkipEmptyParts);
164+ for (const QString& framework: qAsConst (envFrameworks)) {
165+ if (isDir (framework)) {
166+ frameworks << framework;
167+ }
168+ else {
169+ qWarning () << " Framework path" << framework << " does not exist, ignoring." ;
170+ }
171+ }
172+ }
173+
174+ // CLI-provided framework paths
175+ if (!commandLineFrameworks.isEmpty ()) {
176+ const QStringList cliFrameworks = commandLineFrameworks.split (QDir::listSeparator (), Qt::SkipEmptyParts);
177+ for (const QString& framework : cliFrameworks) {
178+ if (isDir (framework)) {
179+ frameworks << QDir::cleanPath (framework);
180+ }
181+ else {
182+ qWarning () << " Framework path" << framework << " does not exist, ignoring." ;
183+ }
184+ }
185+ }
186+
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+ }
201+ }
202+ if (!qtLib.isEmpty () && isDir (qtLib)) {
203+ qInfo () << " Using Qt frameworks at:" << qtLib;
204+ // Check for <lib>/<Module>.framework bundles
205+ for (const QString& qtModule : std::as_const (candidatesQtModules)) {
206+ const QString qtModuleFramework = QDir (qtLib).filePath (qtModule + " .framework" );
207+ if (QDir (qtModuleFramework).exists ()) {
208+ frameworks << qtModuleFramework;
209+ }
210+ }
211+ frameworks << qtLib;
212+ }
213+
214+ return frameworks;
215+ }
216+
153217 bool
154- preprocess (const QString& sourceFile, const QString& targetFile, const QStringList& includePaths)
218+ preprocess (const QString& sourceFile, const QString& targetFile, const QStringList& includePaths, const QStringList& frameworkPaths )
155219 {
156220 simplecpp::DUI dui; // settings
157221
158222 for (const QString& include : includePaths) {
159223 dui.addIncludePath (QDir::toNativeSeparators (include).toStdString ());
160224 }
225+ for (const QString& framework : frameworkPaths) {
226+ dui.addFrameworkPath (QDir::toNativeSeparators (framework).toStdString ());
227+ }
161228 dui.defines .push_back (" __cplusplus=1" );
162229 dui.defines .push_back (" __STDC__" );
163230 dui.std = " c++20" ;
@@ -383,6 +450,7 @@ int main(int argc, char *argv[])
383450 }
384451 printf (" Determined Qt version is %d.%d.%d\n " , qtVersion >> 16 , (qtVersion >> 8 ) & 0xFF , qtVersion & 0xFF );
385452 }
453+ QStringList frameworkPaths = getFrameworkDirectories (args.value (" framework-paths" ));
386454
387455 printf (" Parsing typesystem file [%s]\n " , qPrintable (typesystemFileName));
388456 fflush (stdout);
@@ -398,7 +466,7 @@ int main(int argc, char *argv[])
398466 qPrintable (pp_file), qPrintable (fileName), qPrintable (args.value (" include-paths" )));
399467 ReportHandler::setContext (" Preprocess" );
400468
401- if (!preprocess (fileName, pp_file, includePaths)) {
469+ if (!preprocess (fileName, pp_file, includePaths, frameworkPaths )) {
402470 fprintf (stderr, " Preprocessor failed on file: '%s'\n " , qPrintable (fileName));
403471 return 1 ;
404472 }
@@ -439,6 +507,9 @@ void displayHelp(GeneratorSet* generatorSet) {
439507 " --no-suppress-warnings \n "
440508 " --output-directory=[dir] \n "
441509 " --include-paths=<path>[%c<path>%c...] \n "
510+ #ifdef Q_OS_MACOS
511+ " --framework-paths=<path>[%c<path>%c...] \n "
512+ #endif
442513 " --qt-version=x.y.z \n "
443514 " --print-stdout \n " ,
444515 path_splitter, path_splitter);
0 commit comments