Skip to content

Commit 16cf366

Browse files
committedMar 17, 2017
Add version parsing to FindQGIS CMake module
1 parent 24e3214 commit 16cf366

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed
 

‎cmake/FindQGIS.cmake

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Once run this will define:
22
##
3-
## QGIS_FOUND = system has QGIS lib
3+
## QGIS_FOUND = system has QGIS lib
44
##
55
## QGIS_CORE_LIBRARY = full path to the CORE library
66
## QGIS_GUI_LIBRARY = full path to the GUI library
@@ -9,6 +9,8 @@
99
## QGIS_INCLUDE_DIR = where to find headers
1010
## QGIS_UI_INCLUDE_DIR = where to find ui_* generated headers
1111
##
12+
## QGIS_VERSION = version as defined in qgsconfig.h, as major.minor.patch
13+
##
1214
## Definitions or ENV variables affecting search locations
1315
##
1416
## OSGEO4W_ROOT = [A-Z]:/path/to/OSGeo4W/install/root
@@ -205,12 +207,35 @@ ELSE(WIN32)
205207
ENDIF(UNIX)
206208
ENDIF(WIN32)
207209

210+
IF (QGIS_INCLUDE_DIR)
211+
SET(QGIS_VERSION QGIS_VERSION-NOTFOUND)
212+
FIND_FILE(_qgsconfig_h qgsconfig.h PATHS ${QGIS_INCLUDE_DIR})
213+
IF (_qgsconfig_h)
214+
FILE(READ ${_qgsconfig_h} _qgsconfig)
215+
IF (_qgsconfig)
216+
# version defined like #define VERSION "2.14.8-Essen"
217+
FILE(STRINGS "${_qgsconfig_h}" _qgsversion_str REGEX "^#define VERSION .*$")
218+
STRING(REGEX REPLACE "^#define VERSION +\"([0-9]+\\.[0-9]+\\.[0-9]+).*$" "\\1" _qgsversion "${_qgsversion_str}")
219+
IF (_qgsversion)
220+
SET(QGIS_VERSION ${_qgsversion})
221+
ELSE ()
222+
MESSAGE(WARNING "No QGIS version determined: failed to parse qgsconfig.h")
223+
ENDIF ()
224+
ELSE()
225+
MESSAGE(WARNING "No QGIS version determined: failed to read qgsconfig.h")
226+
ENDIF ()
227+
ELSE ()
228+
MESSAGE(WARNING "No QGIS version determined: failed to find qgsconfig.h")
229+
ENDIF ()
230+
ENDIF ()
231+
208232
IF (QGIS_INCLUDE_DIR AND QGIS_CORE_LIBRARY AND QGIS_GUI_LIBRARY AND QGIS_ANALYSIS_LIBRARY)
209233
SET(QGIS_FOUND TRUE)
210234
ENDIF ()
211235

212236
IF (QGIS_FOUND)
213237
IF (NOT QGIS_FIND_QUIETLY)
238+
MESSAGE(STATUS "Found QGIS: ${QGIS_VERSION}")
214239
MESSAGE(STATUS "Found QGIS core: ${QGIS_CORE_LIBRARY}")
215240
MESSAGE(STATUS "Found QGIS gui: ${QGIS_GUI_LIBRARY}")
216241
MESSAGE(STATUS "Found QGIS analysis: ${QGIS_ANALYSIS_LIBRARY}")

0 commit comments

Comments
 (0)
Please sign in to comment.