Skip to content

Commit 2a434f4

Browse files
committed
Add all search paths for pkg config
1 parent dac4e12 commit 2a434f4

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

Sources/Build/PkgConfig.swift

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,21 @@
99
*/
1010

1111
import Utility
12+
import func POSIX.getenv
1213

1314
enum PkgConfigError: ErrorProtocol {
1415
case CouldNotFindConfigFile
1516
}
1617

1718
struct PkgConfig {
18-
static let searchPaths = ["/usr/local/lib/pkgconfig"]
19+
static let searchPaths = ["/usr/local/lib/pkgconfig",
20+
"/usr/local/share/pkgconfig",
21+
"/usr/lib/pkgconfig",
22+
"/usr/share/pkgconfig",
23+
// FIXME: These should only be searched for linux?
24+
"/usr/lib/x86_64-linux-gnu/pkgconfig",
25+
"/usr/local/lib/x86_64-linux-gnu/pkgconfig",
26+
]
1927

2028
let name: String
2129
let pcFile: String
@@ -29,8 +37,15 @@ struct PkgConfig {
2937
parser = PkgConfigParser(pcFile: pcFile)
3038
}
3139

40+
static var envSearchPaths: [String] {
41+
if let configPath = getenv("PKG_CONFIG_PATH") {
42+
return configPath.characters.split(separator: ":").map(String.init)
43+
}
44+
return []
45+
}
46+
3247
static func locatePCFile(name: String) throws -> String {
33-
for path in searchPaths {
48+
for path in (searchPaths + envSearchPaths) {
3449
let pcFile = Path.join(path, "\(name).pc")
3550
if pcFile.isFile {
3651
return pcFile

0 commit comments

Comments
 (0)