@@ -137,7 +137,26 @@ def extract(self, overwrite=True):
137
137
for path in sorted (glob .glob (os .path .join (zipfold , "tools" , "*.sh" ))):
138
138
os .chmod (path , 0o755 )
139
139
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.
141
160
if self .version_tuple < (3 , 8 , 0 ):
142
161
cmakefile = os .path .join (zipfold , "capi" , "CMakeLists.txt" )
143
162
oldtext = "target_link_libraries(geos_c geos)"
@@ -158,24 +177,20 @@ def extract(self, overwrite=True):
158
177
found_sharedline = True
159
178
fd .write (line .replace (oldtext , newtext ).encode ())
160
179
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 ())
179
194
180
195
def build (self , installdir = None , njobs = 1 ):
181
196
"""Build and install GEOS from source."""
@@ -205,18 +220,21 @@ def build(self, installdir=None, njobs=1):
205
220
build_env = os .environ .copy ()
206
221
207
222
# 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
218
234
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" ]
220
238
221
239
# Call cmake configure after ensuring that the build directory exists.
222
240
try :
0 commit comments