Skip to content

Commit

Permalink
Add version parsing to FindQGIS CMake module
Browse files Browse the repository at this point in the history
  • Loading branch information
dakcarto committed Mar 17, 2017
1 parent 24e3214 commit 16cf366
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion cmake/FindQGIS.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Once run this will define:
##
## QGIS_FOUND = system has QGIS lib
## QGIS_FOUND = system has QGIS lib
##
## QGIS_CORE_LIBRARY = full path to the CORE library
## QGIS_GUI_LIBRARY = full path to the GUI library
Expand All @@ -9,6 +9,8 @@
## QGIS_INCLUDE_DIR = where to find headers
## QGIS_UI_INCLUDE_DIR = where to find ui_* generated headers
##
## QGIS_VERSION = version as defined in qgsconfig.h, as major.minor.patch
##
## Definitions or ENV variables affecting search locations
##
## OSGEO4W_ROOT = [A-Z]:/path/to/OSGeo4W/install/root
Expand Down Expand Up @@ -205,12 +207,35 @@ ELSE(WIN32)
ENDIF(UNIX)
ENDIF(WIN32)

IF (QGIS_INCLUDE_DIR)
SET(QGIS_VERSION QGIS_VERSION-NOTFOUND)
FIND_FILE(_qgsconfig_h qgsconfig.h PATHS ${QGIS_INCLUDE_DIR})
IF (_qgsconfig_h)
FILE(READ ${_qgsconfig_h} _qgsconfig)
IF (_qgsconfig)
# version defined like #define VERSION "2.14.8-Essen"
FILE(STRINGS "${_qgsconfig_h}" _qgsversion_str REGEX "^#define VERSION .*$")
STRING(REGEX REPLACE "^#define VERSION +\"([0-9]+\\.[0-9]+\\.[0-9]+).*$" "\\1" _qgsversion "${_qgsversion_str}")
IF (_qgsversion)
SET(QGIS_VERSION ${_qgsversion})
ELSE ()
MESSAGE(WARNING "No QGIS version determined: failed to parse qgsconfig.h")
ENDIF ()
ELSE()
MESSAGE(WARNING "No QGIS version determined: failed to read qgsconfig.h")
ENDIF ()
ELSE ()
MESSAGE(WARNING "No QGIS version determined: failed to find qgsconfig.h")
ENDIF ()
ENDIF ()

IF (QGIS_INCLUDE_DIR AND QGIS_CORE_LIBRARY AND QGIS_GUI_LIBRARY AND QGIS_ANALYSIS_LIBRARY)
SET(QGIS_FOUND TRUE)
ENDIF ()

IF (QGIS_FOUND)
IF (NOT QGIS_FIND_QUIETLY)
MESSAGE(STATUS "Found QGIS: ${QGIS_VERSION}")
MESSAGE(STATUS "Found QGIS core: ${QGIS_CORE_LIBRARY}")
MESSAGE(STATUS "Found QGIS gui: ${QGIS_GUI_LIBRARY}")
MESSAGE(STATUS "Found QGIS analysis: ${QGIS_ANALYSIS_LIBRARY}")
Expand Down

0 comments on commit 16cf366

Please sign in to comment.