Skip to content

Commit 2fde0d7

Browse files
committed
ENH: Improve Qt include path resolution macOS
Add specific framework path handling Refactor include directory parsing to support multiple candidate paths for headers and introduce macOS-specific logic for resolving framework-relative header paths. Enhance generator flexibility and robustness for cross-platform usage. Push upstream fix via: danmar/simplecpp#448
1 parent 7e51b05 commit 2fde0d7

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

generator/main.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,20 @@ namespace
229229
QRegularExpression::CaseInsensitiveOption);
230230
for (const QString &includeDir: getIncludeDirectories(commandLineIncludes, qtIncludPrefix))
231231
{
232-
QFileInfo fi(QDir(includeDir), "qtcoreversion.h");
232+
std::list<std::string> candiate_paths;
233+
candiate_paths.emplace_back("qtcoreversion.h");
234+
candiate_paths.emplace_back("QtCore/qtcoreversion.h");
235+
candiate_paths.emplace_back("QtCore.framework/Headers/qtcoreversion.h");
236+
QFileInfo fi(QDir(includeDir), QString("qtcoreversion.h"));
237+
for (const std::string &candidate : candiate_paths)
238+
{
239+
QFileInfo candidate_fi(QDir(includeDir), candidate.c_str());
240+
if (candidate_fi.exists() && candidate_fi.isFile())
241+
{
242+
fi = candidate_fi;
243+
break;
244+
}
245+
}
233246
if (fi.exists())
234247
{
235248
QString filePath = fi.absoluteFilePath();

generator/simplecpp/simplecpp.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3116,13 +3116,40 @@ static std::string getIncludePathFileName(const std::string &includePath, const
31163116
return path + header;
31173117
}
31183118

3119+
#ifdef __APPLE__
3120+
static std::string get_apple_framework_relative_path(const std::string& header)
3121+
{
3122+
std::string appleFrameworkHeader = {header};
3123+
// try the Framework path on Mac, if there is a path in front
3124+
// ### what about escaped slashes?
3125+
size_t slashPos = appleFrameworkHeader.find('/');
3126+
if (slashPos != std::string::npos)
3127+
{
3128+
constexpr auto framework_separator{ ".framework/Headers" };
3129+
appleFrameworkHeader.insert(slashPos, framework_separator);
3130+
}
3131+
return appleFrameworkHeader;
3132+
}
3133+
#endif // __APPLE__
3134+
31193135
static std::string openHeaderIncludePath(std::ifstream &f, const simplecpp::DUI &dui, const std::string &header)
31203136
{
31213137
for (std::list<std::string>::const_iterator it = dui.includePaths.begin(); it != dui.includePaths.end(); ++it) {
31223138
std::string simplePath = openHeader(f, getIncludePathFileName(*it, header));
31233139
if (!simplePath.empty())
31243140
return simplePath;
31253141
}
3142+
#ifdef __APPLE__
3143+
std::string appleFrameworkHeader = get_apple_framework_relative_path(header);
3144+
if (appleFrameworkHeader != header)
3145+
{
3146+
for (std::list<std::string>::const_iterator it = dui.includePaths.begin(); it != dui.includePaths.end(); ++it) {
3147+
std::string simplePath = openHeader(f, getIncludePathFileName(*it, appleFrameworkHeader));
3148+
if (!simplePath.empty())
3149+
return simplePath;
3150+
}
3151+
}
3152+
#endif // __APPLE__
31263153
return "";
31273154
}
31283155

generator/simplecpp/simplecpp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
#endif
4040

4141
namespace simplecpp {
42+
43+
std::string get_apple_framework_relative_path(const std::string& header);
44+
4245
/** C code standard */
4346
enum cstd_t { CUnknown=-1, C89, C99, C11, C17, C23 };
4447

0 commit comments

Comments
 (0)