Skip to content

Commit 9ce91e3

Browse files
committed
Fix GeosLibrary wrapper to work with GEOS >= 3.8.0
1 parent 673cf47 commit 9ce91e3

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

packages/basemap/utils/GeosLibrary.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,24 @@ def extract(self, overwrite=True):
138138
os.chmod(path, 0o755)
139139

140140
# Patch CMakeLists so that libgeos_c.so does not depend on libgeos.so.
141-
cmakefile = os.path.join(zipfold, "capi", "CMakeLists.txt")
141+
if self.version_tuple < (3, 8, 0):
142+
cmakefile = os.path.join(zipfold, "capi", "CMakeLists.txt")
143+
oldtext = "target_link_libraries(geos_c geos)"
144+
newtext = "target_link_libraries(geos_c geos-static)"
145+
else:
146+
cmakefile = os.path.join(zipfold, "CMakeLists.txt")
147+
oldtext = 'add_library(geos "")'
148+
newtext = 'add_library(geos STATIC "")'
142149
with io.open(cmakefile, "r", encoding="utf-8") as fd:
143150
lines = fd.readlines()
144151
with io.open(cmakefile, "wb") as fd:
145-
oldtext = "target_link_libraries(geos_c geos)"
146-
newtext = "target_link_libraries(geos_c geos-static)"
152+
found_sharedline = False
153+
shared_oldtext = "if(BUILD_SHARED_LIBS)"
154+
shared_newtext = "if(FALSE)"
147155
for line in lines:
156+
if not found_sharedline and shared_oldtext in line:
157+
line = line.replace(shared_oldtext, shared_newtext)
158+
found_sharedline = True
148159
fd.write(line.replace(oldtext, newtext).encode())
149160

150161
# Apply specific patches for GEOS < 3.6.0.
@@ -184,9 +195,12 @@ def build(self, installdir=None, njobs=1):
184195
# Define configure options.
185196
config_opts = [
186197
"-DCMAKE_INSTALL_PREFIX={0}".format(installdir),
187-
"-DGEOS_ENABLE_TESTS=OFF",
188198
"-DCMAKE_BUILD_TYPE=Release",
189199
]
200+
if self.version_tuple < (3, 8, 0):
201+
config_opts += ["-DGEOS_ENABLE_TESTS=OFF"]
202+
else:
203+
config_opts += ["-DBUILD_TESTING=OFF"]
190204
if os.name == "nt" and self.version_tuple < (3, 6, 0):
191205
config_opts = ["-G", "NMake Makefiles"] + config_opts
192206

0 commit comments

Comments
 (0)