@@ -137,7 +137,26 @@ def extract(self, overwrite=True):
137137 for path in sorted (glob .glob (os .path .join (zipfold , "tools" , "*.sh" ))):
138138 os .chmod (path , 0o755 )
139139
140- # Patch CMakeLists so that libgeos_c.so does not depend on libgeos.so.
140+ # Apply specific patches for GEOS < 3.6.0.
141+ if self .version_tuple < (3 , 6 , 0 ):
142+ # The SVN revision file is not created on the fly before 3.6.0.
143+ svn_hfile = os .path .join (zipfold , "geos_svn_revision.h" )
144+ if not os .path .exists (svn_hfile ):
145+ with io .open (svn_hfile , "wb" ) as fd :
146+ text = "#define GEOS_SVN_REVISION 0"
147+ fd .write (text .encode ())
148+ # Reduce warnings when compiling with `nmake` on Windows.
149+ cmakefile = os .path .join (zipfold , "CMakeLists.txt" )
150+ if os .path .exists (cmakefile ):
151+ with io .open (cmakefile , "r" , encoding = "utf-8" ) as fd :
152+ lines = fd .readlines ()
153+ with io .open (cmakefile , "wb" ) as fd :
154+ oldtext = 'string(REGEX REPLACE "/W[0-9]" "/W4"'
155+ newtext = oldtext .replace ("W4" , "W1" )
156+ for line in lines :
157+ fd .write (line .replace (oldtext , newtext ).encode ())
158+
159+ # Patch CMakeLists to link shared geos_c with static geos.
141160 if self .version_tuple < (3 , 8 , 0 ):
142161 cmakefile = os .path .join (zipfold , "capi" , "CMakeLists.txt" )
143162 oldtext = "target_link_libraries(geos_c geos)"
@@ -158,24 +177,20 @@ def extract(self, overwrite=True):
158177 found_sharedline = True
159178 fd .write (line .replace (oldtext , newtext ).encode ())
160179
161- # Apply specific patches for GEOS < 3.6.0.
162- if self .version_tuple < (3 , 6 , 0 ):
163- # The SVN revision file is not created on the fly before 3.6.0.
164- svn_hfile = os .path .join (zipfold , "geos_svn_revision.h" )
165- if not os .path .exists (svn_hfile ):
166- with io .open (svn_hfile , "wb" ) as fd :
167- text = "#define GEOS_SVN_REVISION 0"
168- fd .write (text .encode ())
169- # Reduce warnings when compiling with `nmake` on Windows.
170- cmakefile = os .path .join (zipfold , "CMakeLists.txt" )
171- if os .path .exists (cmakefile ):
172- with io .open (cmakefile , "r" , encoding = "utf-8" ) as fd :
173- lines = fd .readlines ()
174- with io .open (cmakefile , "wb" ) as fd :
175- oldtext = 'string(REGEX REPLACE "/W[0-9]" "/W4"'
176- newtext = oldtext .replace ("W4" , "W1" )
177- for line in lines :
178- fd .write (line .replace (oldtext , newtext ).encode ())
180+ # Patch doc CMakeLists in GEOS 3.8.x series.
181+ if (3 , 8 , 0 ) <= self .version_tuple < (3 , 9 , 0 ):
182+ cmakefile = os .path .join (zipfold , "doc" , "CMakeLists.txt" )
183+ oldtext1 = "target_include_directories(test_geos_unit\n "
184+ newtext1 = "if(BUILD_TESTING)\n {0}" .format (oldtext1 )
185+ oldtext2 = "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>)\n "
186+ newtext2 = "{0}endif()\n " .format (oldtext2 )
187+ with io .open (cmakefile , "r" , encoding = "utf-8" ) as fd :
188+ lines = fd .readlines ()
189+ with io .open (cmakefile , "wb" ) as fd :
190+ for line in lines :
191+ line = line .replace (oldtext1 , newtext1 )
192+ line = line .replace (oldtext2 , newtext2 )
193+ fd .write (line .encode ())
179194
180195 def build (self , installdir = None , njobs = 1 ):
181196 """Build and install GEOS from source."""
@@ -205,18 +220,21 @@ def build(self, installdir=None, njobs=1):
205220 build_env = os .environ .copy ()
206221
207222 # Define custom configure and build options.
208- if os .name != "nt" :
209- build_env ["MAKEFLAGS" ] = "-j {0:d}" .format (njobs )
210- elif version < (3 , 6 , 0 ):
211- win64 = (8 * struct .calcsize ("P" ) == 64 )
212- config_opts = ["-G" , "NMake Makefiles" ] + config_opts
213- build_opts .extend ([
214- "--" ,
215- "WIN64={0}" .format ("YES" if win64 else "NO" ),
216- "BUILD_BATCH={0}" .format ("YES" if njobs > 1 else "NO" ),
217- ])
223+ if os .name == "nt" :
224+ if version < (3 , 6 , 0 ):
225+ win64 = (8 * struct .calcsize ("P" ) == 64 )
226+ config_opts = ["-G" , "NMake Makefiles" ] + config_opts
227+ build_opts .extend ([
228+ "--" ,
229+ "WIN64={0}" .format ("YES" if win64 else "NO" ),
230+ "BUILD_BATCH={0}" .format ("YES" if njobs > 1 else "NO" ),
231+ ])
232+ else :
233+ build_opts = ["-j" , "{0:d}" .format (njobs )] + build_opts
218234 else :
219- build_opts = ["-j" , "{0:d}" .format (njobs )] + build_opts
235+ build_env ["MAKEFLAGS" ] = "-j {0:d}" .format (njobs )
236+ if version >= (3 , 7 , 0 ):
237+ config_opts += ["-DCMAKE_CXX_FLAGS=-fPIC" ]
220238
221239 # Call cmake configure after ensuring that the build directory exists.
222240 try :
0 commit comments