Skip to content
Permalink
Browse files
Add version parsing to FindQGIS CMake module
  • Loading branch information
dakcarto committed Mar 17, 2017
1 parent 24e3214 commit 16cf3665e13657cfa265ed5121fbd618b59a6cc9
Showing with 26 additions and 1 deletion.
  1. +26 −1 cmake/FindQGIS.cmake
@@ -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
@@ -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
@@ -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}")

0 comments on commit 16cf366

Please sign in to comment.