Skip to content

Commit 4f4d70a

Browse files
authored
gtest discovery improvement (#169)
Improve gtest discovery to include common locations
1 parent cc078d9 commit 4f4d70a

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

common.gradle

+26-5
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,32 @@ def static isMusl() {
110110

111111
ext.hasGtest = false
112112

113-
// This is hardcoded - we could have some discovery mechanism here but it would mean forking to shell
114-
if (os().isMacOsX() && file('/opt/homebrew/opt/googletest').exists()) {
115-
ext.hasGtest = true
116-
} else if (os().isLinux() && file('/usr/include/gtest').exists()) {
117-
ext.hasGtest = true
113+
// Define potential GTest locations for MacOS and Linux
114+
def gtestLocations = [
115+
macos: ['/opt/homebrew/opt/googletest', '/usr/local/opt/googletest'],
116+
linux: ['/usr/include/gtest', '/usr/local/include/gtest']
117+
]
118+
119+
// Function to check if any of the specified paths exist
120+
def checkGtestPaths(paths) {
121+
for (path in paths) {
122+
if (file(path).exists()) {
123+
return true
124+
}
125+
}
126+
return false
127+
}
128+
129+
// Determine OS and check for GTest
130+
if (os().isMacOsX()) {
131+
ext.hasGtest = checkGtestPaths(gtestLocations.macos)
132+
} else if (os().isLinux()) {
133+
ext.hasGtest = checkGtestPaths(gtestLocations.linux)
134+
}
135+
136+
// Log a message for debugging
137+
if (!ext.hasGtest) {
138+
println "GTest not found. Please install GTest or configure paths."
118139
}
119140

120141
ext {

0 commit comments

Comments
 (0)