2323import ssl
2424import glob
2525import shutil
26+ import struct
2627import tempfile
2728import contextlib
2829import subprocess
@@ -44,7 +45,8 @@ class GeosLibrary(object):
4445 def __init__ (self , version , root = None ):
4546 """Initialise a new :class:`GeosLibrary` instance."""
4647
47- self .version = version
48+ self .version_tuple = tuple (map (int , version .split ("." )))
49+
4850 if root is None :
4951 self .temp = True
5052 self .root = tempfile .mkdtemp (prefix = "tmp_geoslibrary_" )
@@ -65,6 +67,12 @@ def __del__(self):
6567 except OSError :
6668 pass
6769
70+ @property
71+ def version (self ):
72+ """GEOS library version in string format."""
73+
74+ return "." .join (map (str , self .version_tuple ))
75+
6876 def download (self ):
6977 """Download GEOS zip source code into :class:`GeosLibrary` root."""
7078
@@ -141,7 +149,7 @@ def extract(self, overwrite=True):
141149
142150 # The SVN revision file is not created on the fly before 3.6.0.
143151 svn_hfile = os .path .join (zipfold , "geos_svn_revision.h" )
144- if not os .path .exists (svn_hfile ):
152+ if self . version_tuple < ( 3 , 6 , 0 ) and not os .path .exists (svn_hfile ):
145153 with io .open (svn_hfile , "wb" ) as fd :
146154 text = "#define GEOS_SVN_REVISION 0"
147155 fd .write (text .encode ())
@@ -168,17 +176,26 @@ def build(self, installdir=None, njobs=1):
168176 ]
169177 if os .name != "nt" :
170178 config_opts .append ("-DCMAKE_BUILD_TYPE=Release" )
179+ elif self .version_tuple < (3 , 6 , 0 ):
180+ config_opts = ["-G" , "NMake Makefiles" ] + config_opts
171181
172182 # Define build options.
173183 build_env = os .environ .copy ()
174184 build_opts = [
175185 "--config" , "Release" ,
176186 "--target" , "install" ,
177187 ]
178- if os .name == "nt" :
179- build_opts = ["-j" , "{0:d}" .format (njobs )] + build_opts
180- else :
188+ if os .name != "nt" :
181189 build_env ["MAKEFLAGS" ] = "-j {0:d}" .format (njobs )
190+ elif self .version_tuple < (3 , 6 , 0 ):
191+ win64 = (8 * struct .calcsize ("P" ) == 64 )
192+ build_opts .extend ([
193+ "--" ,
194+ "WIN64={0}" .format ("YES" if win64 else "NO" ),
195+ "BUILD_BATCH={0}" .format ("YES" if njobs > 1 else "NO" )
196+ ])
197+ else :
198+ build_opts = ["-j" , "{0:d}" .format (njobs )] + build_opts
182199
183200 # Now move to the GEOS source code folder and build with CMake.
184201 cwd = os .getcwd ()
0 commit comments