1
1
using System . Collections . Generic ;
2
2
using System . Linq ;
3
+ using System . Text . RegularExpressions ;
3
4
4
5
namespace Silk . NET . SilkTouch . Clang ;
5
6
6
7
/// <summary>
7
- /// Resolver for the C standard include paths on UNIX-like systems. On UNIX this is remarkably simple, it's just
8
- /// /usr/include and /usr/include/local.
8
+ /// Resolver for the C standard include paths on UNIX-like systems.
9
9
/// </summary>
10
- public class UnixStdIncludeResolver : IStdIncludeResolver
10
+ public partial class UnixStdIncludeResolver : IStdIncludeResolver
11
11
{
12
12
private string [ ] ? _ret = null ;
13
13
@@ -18,7 +18,29 @@ public IEnumerable<string> GetStandardIncludes() =>
18
18
/// <inheritdoc cref="GetStandardIncludes" />
19
19
protected virtual IEnumerable < string > CoreGetStandardIncludes ( )
20
20
{
21
+ // Add standard include directories
21
22
yield return "-I/usr/include" ;
22
23
yield return "-I/usr/local/include" ;
24
+
25
+ // Attempt to find and add clang include folder
26
+ if ( Directory . Exists ( "/usr/lib/clang/" ) )
27
+ {
28
+ var clangIncludeFolder = Directory . GetDirectories ( "/usr/lib/clang/" , "*" , SearchOption . AllDirectories )
29
+ . Select ( path => ClangIncludeFolderRegex ( ) . Match ( path ) )
30
+ . Where ( match => match . Success )
31
+ // Select the latest version
32
+ . OrderByDescending ( match => int . Parse ( match . Groups [ "Version" ] . Value ) )
33
+ . FirstOrDefault ( )
34
+ ? . Value ;
35
+
36
+ if ( clangIncludeFolder != null )
37
+ {
38
+ yield return $ "-I{ clangIncludeFolder } ";
39
+ }
40
+ }
41
+
23
42
}
43
+
44
+ [ GeneratedRegex ( "^/usr/lib/clang/(?<Version>\\ d+)/include$" ) ]
45
+ private static partial Regex ClangIncludeFolderRegex ( ) ;
24
46
}
0 commit comments