Skip to content

Commit 9fef5a1

Browse files
committedSep 21, 2015
Make GEOS CPP optional
1 parent e9e638f commit 9fef5a1

File tree

5 files changed

+46
-7
lines changed

5 files changed

+46
-7
lines changed
 

‎CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ ENDIF(NOT WIN32 AND NOT ANDROID)
191191
# required
192192
FIND_PACKAGE(Proj)
193193
FIND_PACKAGE(GEOS)
194-
SET(GEOS_CPP_LIBRARY -lgeos CACHE STRING "Path to the geos CPP library")
195194
FIND_PACKAGE(GDAL)
196195
FIND_PACKAGE(Expat REQUIRED)
197196
FIND_PACKAGE(Spatialindex REQUIRED)

‎cmake/FindGEOS.cmake

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@ IF(WIN32)
2323
IF (MINGW)
2424
FIND_PATH(GEOS_INCLUDE_DIR geos_c.h /usr/local/include /usr/include c:/msys/local/include)
2525
FIND_LIBRARY(GEOS_LIBRARY NAMES geos_c PATHS /usr/local/lib /usr/lib c:/msys/local/lib)
26+
FIND_LIBRARY(GEOS_CPP_LIBRARY NAMES geos PATHS /usr/local/lib /usr/lib c:/msys/local/lib)
2627
ENDIF (MINGW)
2728

2829
IF (MSVC)
2930
FIND_PATH(GEOS_INCLUDE_DIR geos_c.h $ENV{LIB_DIR}/include $ENV{INCLUDE})
30-
FIND_LIBRARY(GEOS_LIBRARY NAMES geos geos_c_i geos_c PATHS
31+
FIND_LIBRARY(GEOS_LIBRARY NAMES geos_c_i geos_c PATHS
32+
"$ENV{LIB_DIR}/lib"
33+
$ENV{LIB}
34+
)
35+
FIND_LIBRARY(GEOS_CPP_LIBRARY NAMES geos PATHS
3136
"$ENV{LIB_DIR}/lib"
3237
$ENV{LIB}
3338
)
@@ -67,6 +72,7 @@ ELSE(WIN32)
6772

6873
IF(CYGWIN)
6974
FIND_LIBRARY(GEOS_LIBRARY NAMES geos_c PATHS /usr/lib /usr/local/lib)
75+
FIND_LIBRARY(GEOS_CPP_LIBRARY NAMES geos PATHS /usr/lib /usr/local/lib)
7076
ENDIF(CYGWIN)
7177

7278
IF (NOT GEOS_INCLUDE_DIR OR NOT GEOS_LIBRARY OR NOT GEOS_CONFIG)
@@ -132,12 +138,16 @@ ELSE(WIN32)
132138
#MESSAGE("DBG GEOS_CONFIG_LIBS=${GEOS_CONFIG_LIBS}")
133139
#MESSAGE("DBG GEOS_LIB_NAME_WITH_PREFIX=${GEOS_LIB_NAME_WITH_PREFIX}")
134140
SET(GEOS_LIB_NAME_WITH_PREFIX -lgeos_c CACHE STRING INTERNAL)
141+
SET(GEOS_CPP_LIB_NAME_WITH_PREFIX -lgeos CACHE STRING INTERNAL)
135142

136143
## remove prefix -l because we need the pure name
137144

138145
IF (GEOS_LIB_NAME_WITH_PREFIX)
139146
STRING(REGEX REPLACE "[-][l]" "" GEOS_LIB_NAME ${GEOS_LIB_NAME_WITH_PREFIX} )
140147
ENDIF (GEOS_LIB_NAME_WITH_PREFIX)
148+
IF (GEOS_CPP_LIB_NAME_WITH_PREFIX)
149+
STRING(REGEX REPLACE "[-][l]" "" GEOS_CPP_LIB_NAME ${GEOS_CPP_LIB_NAME_WITH_PREFIX} )
150+
ENDIF (GEOS_CPP_LIB_NAME_WITH_PREFIX)
141151
#MESSAGE("DBG GEOS_LIB_NAME=${GEOS_LIB_NAME}")
142152

143153
IF (APPLE)
@@ -146,9 +156,11 @@ ELSE(WIN32)
146156
# while still preserving user setting if given
147157
# ***FIXME*** need to improve framework check so below not needed
148158
SET(GEOS_LIBRARY ${GEOS_LINK_DIRECTORIES}/lib${GEOS_LIB_NAME}.dylib CACHE STRING INTERNAL FORCE)
159+
SET(GEOS_CPP_LIBRARY ${GEOS_LINK_DIRECTORIES}/lib${GEOS_CPP_LIB_NAME}.dylib CACHE STRING INTERNAL FORCE)
149160
ENDIF (NOT GEOS_LIBRARY)
150161
ELSE (APPLE)
151162
SET(GEOS_LIBRARY ${GEOS_LINK_DIRECTORIES}/lib${GEOS_LIB_NAME}.so CACHE STRING INTERNAL)
163+
SET(GEOS_CPP_LIBRARY ${GEOS_LINK_DIRECTORIES}/lib${GEOS_CPP_LIB_NAME}.so CACHE STRING INTERNAL)
152164
ENDIF (APPLE)
153165
#MESSAGE("DBG GEOS_LIBRARY=${GEOS_LIBRARY}")
154166

‎src/core/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,6 @@ SET(QGIS_CORE_HDRS
523523
${CMAKE_BINARY_DIR}/qgsconfig.h
524524
../plugins/qgisplugin.h
525525

526-
geosextra/geos_c_extra.h
527-
528526
qgis.h
529527
qgsattributeaction.h
530528
qgscachedfeatureiterator.h
@@ -737,6 +735,12 @@ SET(QGIS_CORE_HDRS
737735
geometry/qgspointv2.h
738736
)
739737

738+
IF(GEOS_CPP_LIBRARY)
739+
SET(QGIS_CORE_SRCS ${QGIS_CORE_SRCS} geosextra/geos_c_extra.cpp)
740+
SET(QGIS_CORE_HDRS ${QGIS_CORE_HDRS} geosextra/geos_c_extra.h)
741+
ADD_DEFINITIONS("-DHAVE_GEOS_CPP")
742+
ENDIF(GEOS_CPP_LIBRARY)
743+
740744
IF (QT_MOBILITY_LOCATION_FOUND OR Qt5Positioning_FOUND)
741745
SET(QGIS_CORE_HDRS ${QGIS_CORE_HDRS}
742746
gps/qgsqtlocationconnection.h

‎src/core/geometry/qgsgeos.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,24 @@ class GEOSGeomScopedPtr
117117

118118
QgsGeos::QgsGeos( const QgsAbstractGeometryV2* geometry, int precision ): QgsGeometryEngine( geometry ), mGeos( 0 ), mGeosPrepared( 0 )
119119
{
120+
#ifdef HAVE_GEOS_CPP
120121
double prec = qPow( 10, -precision );
121122
mPrecisionModel = GEOSPrecisionModel_createFixed( 1.f / prec );
122123
mPrecisionReducer = GEOSGeometryPrecisionReducer_create( mPrecisionModel );
124+
#else
125+
Q_UNUSED( precision )
126+
#endif
123127
cacheGeos();
124128
}
125129

126130
QgsGeos::~QgsGeos()
127131
{
132+
#ifdef HAVE_GEOS_CPP
128133
GEOSGeom_destroy_r( geosinit.ctxt, mGeos );
129134
GEOSPreparedGeom_destroy_r( geosinit.ctxt, mGeosPrepared );
130135
GEOSGeometryPrecisionReducer_destroy( mPrecisionReducer );
131136
GEOSPrecisionModel_destroy( mPrecisionModel );
137+
#endif
132138
}
133139

134140
void QgsGeos::geometryChanged()
@@ -158,11 +164,15 @@ void QgsGeos::cacheGeos() const
158164
}
159165

160166
GEOSGeometry* g = asGeos( mGeometry );
167+
#ifdef HAVE_GEOS_CPP
161168
if ( g )
162169
{
163170
mGeos = GEOSGeometryPrecisionReducer_reduce( mPrecisionReducer, g );
164171
GEOSGeom_destroy_r( geosinit.ctxt, g );
165172
}
173+
#else
174+
mGeos = g;
175+
#endif
166176
}
167177

168178
QgsAbstractGeometryV2* QgsGeos::intersection( const QgsAbstractGeometryV2& geom, QString* errorMsg ) const
@@ -1047,12 +1057,18 @@ QgsAbstractGeometryV2* QgsGeos::overlay( const QgsAbstractGeometryV2& geom, Over
10471057
{
10481058
return 0;
10491059
}
1060+
1061+
#ifdef HAVE_GEOS_CPP
10501062
GEOSGeomScopedPtr geosGeom;
10511063
geosGeom.reset( gG );
10521064

10531065
//reduce precision
10541066
GEOSGeomScopedPtr pg2;
10551067
pg2.reset( GEOSGeometryPrecisionReducer_reduce( mPrecisionReducer, geosGeom.get() ) );
1068+
#else
1069+
GEOSGeomScopedPtr pg2;
1070+
pg2.reset( gG );
1071+
#endif
10561072

10571073
try
10581074
{
@@ -1099,14 +1115,18 @@ bool QgsGeos::relation( const QgsAbstractGeometryV2& geom, Relation r, QString*
10991115
{
11001116
return false;
11011117
}
1118+
#ifdef HAVE_GEOS_CPP
11021119
GEOSGeomScopedPtr geosGeom;
11031120
geosGeom.reset( gG );
11041121

1105-
bool result = false;
1106-
11071122
GEOSGeomScopedPtr pg2;
11081123
pg2.reset( GEOSGeometryPrecisionReducer_reduce( mPrecisionReducer, geosGeom.get() ) );
1124+
#else
1125+
GEOSGeomScopedPtr pg2;
1126+
pg2.reset( gG );
1127+
#endif
11091128

1129+
bool result = false;
11101130
try
11111131
{
11121132
if ( mGeosPrepared ) //use faster version with prepared geometry

‎src/core/geometry/qgsgeos.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ email : marco.hugentobler at sourcepole dot com
1818

1919
#include "qgsgeometryengine.h"
2020
#include "qgspointv2.h"
21-
#include "geosextra/geos_c_extra.h"
2221
#include <geos_c.h>
22+
#ifdef HAVE_GEOS_CPP
23+
#include "geosextra/geos_c_extra.h"
24+
#endif
2325

2426
class QgsLineStringV2;
2527
class QgsPolygonV2;
@@ -89,9 +91,11 @@ class CORE_EXPORT QgsGeos: public QgsGeometryEngine
8991
private:
9092
mutable GEOSGeometry* mGeos;
9193
const GEOSPreparedGeometry* mGeosPrepared;
94+
#ifdef HAVE_GEOS_CPP
9295
//precision reducer
9396
GEOSPrecisionModel* mPrecisionModel;
9497
GEOSGeometryPrecisionReducer* mPrecisionReducer;
98+
#endif
9599

96100
enum Overlay
97101
{

0 commit comments

Comments
 (0)
Please sign in to comment.