Skip to content

Commit ae98755

Browse files
committed
ENH: Add support to find Headers in Apple Frameworks
The header locations in apple frameworks require manipulation of the directory name in a '<pkg/myhdr.h>' include defintion. The header file is located at <pkg.framework/Headers/myhdr.h> in a framework.
1 parent 29abbc6 commit ae98755

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

simplecpp.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3006,6 +3006,34 @@ static std::string openHeader(std::ifstream &f, const simplecpp::DUI &dui, const
30063006
if (!path.empty())
30073007
return path;
30083008
}
3009+
#ifdef __APPLE__
3010+
// a named lambda function to insert the ".framework/Headers" part for apple frameworks
3011+
auto get_apple_framework_relative_path= [](std::string appleFrameworkHeader) -> std::string
3012+
{
3013+
// try the Framework path on apple OS, if there is a path in front
3014+
const size_t slashPos = appleFrameworkHeader.find('/');
3015+
if (slashPos != std::string::npos)
3016+
{
3017+
constexpr auto framework_separator{ ".framework/Headers" };
3018+
appleFrameworkHeader.insert(slashPos, framework_separator);
3019+
}
3020+
return appleFrameworkHeader;
3021+
};
3022+
3023+
// on Apple, try to find the header in the framework path
3024+
// Convert <includePath>/PKGNAME/myHeader -> <includePath>/PKGNAME.framework/Headers/myHeader
3025+
const std::string appleFrameworkHeader = get_apple_framework_relative_path(header);
3026+
if (appleFrameworkHeader != header)
3027+
{
3028+
for (const auto & includePath: dui.includePaths)
3029+
{
3030+
const std::string frameworkCandidatePath = includePath + '/' + appleFrameworkHeader;
3031+
std::string simplePath = openHeaderDirect(f, simplecpp::simplifyPath(frameworkCandidatePath ));
3032+
if (!simplePath.empty())
3033+
return simplePath;
3034+
}
3035+
}
3036+
#endif // __APPLE__
30093037
return "";
30103038
}
30113039

0 commit comments

Comments
 (0)