Skip to content
Permalink
Browse files

CMake:

- added possibility to explicitly disable building of bindings
- added version checks for SIP (min. 4.5) and PyQt (min. 4.1)


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6428 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Jan 13, 2007
1 parent d969ca1 commit 66a2685b0be015bc06ddafae4ebaf4d1d0cce188
Showing with 118 additions and 58 deletions.
  1. +14 −53 CMakeLists.txt
  2. +5 −5 cmake/FindGRASS.cmake
  3. +99 −0 cmake/Python.cmake
@@ -24,6 +24,14 @@ SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
SET (PLUGINS_ALSO_BINARIES FALSE)


# try to configure and build GRASS plugin by default
SET (WITH_GRASS TRE CACHE BOOL "Determines whether GRASS plugin should be built")
SET (GRASS_PREFIX "" CACHE PATH "Path to GRASS base directory")

# try to configure and build python bindings by default
SET (WITH_BINDINGS TRUE CACHE BOOL "Determines whether python bindings should be built")


#############################################################
# check if lexer and parser are not missing
# http://www.mail-archive.com/cmake@cmake.org/msg02861.html
@@ -58,8 +66,12 @@ FIND_PACKAGE(Postgres) # PostgreSQL provider, SPIT plugin
FIND_PACKAGE(Expat) # GPS importer plugin
FIND_PACKAGE(GSL) # Georeferencer
FIND_PACKAGE(GRASS) # GRASS plugin
FIND_PACKAGE(PythonLibs) # MapServer export tool
FIND_PACKAGE(PythonInterp) # test for sip and PyQt4

# python support:
# - mapserver export tool
# - bindings
INCLUDE (Python) # file cmake/Python.cmake


IF (NOT PROJ_FOUND OR NOT SQLITE3_FOUND OR NOT GEOS_FOUND OR NOT GDAL_FOUND)
MESSAGE (SEND_ERROR "Some dependencies were not found!")
@@ -71,57 +83,6 @@ IF (POSTGRES_FOUND)
ENDIF (POSTGRES_FOUND)


#############################################################
# python support

MACRO (TRY_RUN_PYTHON RESULT CMD)
IF (PYTHONINTERP_FOUND)

EXEC_PROGRAM(${PYTHON_EXECUTABLE} ARGS -c "\"${CMD}\""
OUTPUT_VARIABLE out
RETURN_VALUE retval)
IF (retval EQUAL 0)
SET (${RESULT} TRUE)
ELSE (retval EQUAL 0)
SET (${RESULT} FALSE)
ENDIF (retval EQUAL 0)

ELSE (PYTHONINTERP_FOUND)
SET (${${RESULT}} FALSE)
ENDIF (PYTHONINTERP_FOUND)
ENDMACRO (TRY_RUN_PYTHON)


# enable/disable python support (mapserver export tool and bindings)
IF (PYTHON_LIBRARIES AND PYTHON_INCLUDE_PATH)
SET (PYTHON_FOUND TRUE)
MESSAGE(STATUS "Python libraries found")

# TODO: should not be needed, report it to CMake devs
IF (UNIX AND NOT APPLE)
SET (PYTHON_LIBRARIES ${PYTHON_LIBRARIES} util)
ENDIF (UNIX AND NOT APPLE)

# check for SIP
TRY_RUN_PYTHON (HAVE_SIP_MODULE "from sip import wrapinstance")
FIND_PROGRAM (SIP_BINARY_PATH sip)

# check for PyQt4
TRY_RUN_PYTHON (HAVE_PYQT4 "from PyQt4 import QtCore, QtGui")

# if SIP and PyQt4 are found, enable bindings
IF (HAVE_SIP_MODULE AND SIP_BINARY_PATH AND HAVE_PYQT4)
SET (HAVE_PYTHON TRUE)
MESSAGE(STATUS "Python bindings enabled")
ELSE (HAVE_SIP_MODULE AND SIP_BINARY_PATH AND HAVE_PYQT4)
SET (HAVE_PYTHON FALSE)
MESSAGE(STATUS "Python bindings disabled")
ENDIF (HAVE_SIP_MODULE AND SIP_BINARY_PATH AND HAVE_PYQT4)

ENDIF (PYTHON_LIBRARIES AND PYTHON_INCLUDE_PATH)



#############################################################
# search for Qt4

@@ -27,17 +27,17 @@ MACRO (CHECK_GRASS G_PREFIX)
SET (GRASS_FOUND TRUE)
SET (GRASS_PREFIX ${G_PREFIX})
ENDIF (GRASS_INCLUDE_DIR AND GRASS_LIBRARIES)

MARK_AS_ADVANCED (
GRASS_INCLUDE_DIR
GRASS_LIBRARIES
)

ENDMACRO (CHECK_GRASS)

###################################
# search for grass installations

# try to build with GRASS by default
SET (WITH_GRASS "ON" CACHE BOOL "Determines whether GRASS plugin should be built")

SET (GRASS_PREFIX "" CACHE PATH "Path to GRASS base directory")

# list of paths which to search - user's choice as first
SET (GRASS_PATHS ${GRASS_PREFIX} /usr/lib/grass)

@@ -0,0 +1,99 @@

# CMake module which checks for python and some its modules
# there is a two-stage support for python:
# -


FIND_PACKAGE(PythonLibs) # MapServer export tool
FIND_PACKAGE(PythonInterp) # test for sip and PyQt4


MACRO (TRY_RUN_PYTHON RESULT CMD)
IF (PYTHONINTERP_FOUND)

EXEC_PROGRAM(${PYTHON_EXECUTABLE} ARGS -c "\"${CMD}\""
OUTPUT_VARIABLE out
RETURN_VALUE retval)

# optional last parameter to save the output
SET (OUTPUT ${ARGV2})
IF (OUTPUT)
SET(${OUTPUT} ${out})
ENDIF (OUTPUT)

IF (retval EQUAL 0)
SET (${RESULT} TRUE)
ELSE (retval EQUAL 0)
SET (${RESULT} FALSE)
ENDIF (retval EQUAL 0)

ELSE (PYTHONINTERP_FOUND)
SET (${RESULT} FALSE)
ENDIF (PYTHONINTERP_FOUND)
ENDMACRO (TRY_RUN_PYTHON)

# enable/disable python support (mapserver export tool and bindings)
IF (PYTHON_LIBRARIES AND PYTHON_INCLUDE_PATH)
SET (PYTHON_FOUND TRUE)
MESSAGE(STATUS "Python libraries found")

# TODO: should not be needed, report it to CMake devs
IF (UNIX AND NOT APPLE)
SET (PYTHON_LIBRARIES ${PYTHON_LIBRARIES} util)
ENDIF (UNIX AND NOT APPLE)

IF (WITH_BINDINGS)

# check for SIP
TRY_RUN_PYTHON (HAVE_SIP_MODULE "from sip import wrapinstance")
FIND_PROGRAM (SIP_BINARY_PATH sip)

IF (HAVE_SIP_MODULE AND SIP_BINARY_PATH)
# check for SIP version
# minimal version is 4.5
SET (SIP_MIN_VERSION 040500)
TRY_RUN_PYTHON (RES "import sip\nprint '%x' % sip.SIP_VERSION" SIP_VERSION)
IF (SIP_VERSION EQUAL "${SIP_MIN_VERSION}" OR SIP_VERSION GREATER "${SIP_MIN_VERSION}")
SET (SIP_IS_GOOD TRUE)
ENDIF (SIP_VERSION EQUAL "${SIP_MIN_VERSION}" OR SIP_VERSION GREATER "${SIP_MIN_VERSION}")

IF (NOT SIP_IS_GOOD)
MESSAGE (STATUS "SIP is required in version 4.5 or later!")
ENDIF (NOT SIP_IS_GOOD)
ELSE (HAVE_SIP_MODULE AND SIP_BINARY_PATH)
MESSAGE (STATUS "SIP not found!")
ENDIF (HAVE_SIP_MODULE AND SIP_BINARY_PATH)

# check for PyQt4
TRY_RUN_PYTHON (HAVE_PYQT4 "from PyQt4 import QtCore, QtGui, QtNetwork, QtSvg, QtXml")

IF (HAVE_PYQT4)
# check for PyQt4 version
# minimal version is 4.1
SET (PYQT_MIN_VERSION 040100)
TRY_RUN_PYTHON (RES "from PyQt4 import QtCore\nprint '%x' % QtCore.PYQT_VERSION" PYQT_VERSION)
IF (PYQT_VERSION EQUAL "${PYQT_MIN_VERSION}" OR PYQT_VERSION GREATER "${PYQT_MIN_VERSION}")
SET (PYQT_IS_GOOD TRUE)
ENDIF (PYQT_VERSION EQUAL "${PYQT_MIN_VERSION}" OR PYQT_VERSION GREATER "${PYQT_MIN_VERSION}")

IF (NOT PYQT_IS_GOOD)
MESSAGE (STATUS "PyQt4 is needed in version 4.1 or later!")
ENDIF (NOT PYQT_IS_GOOD)
ELSE (HAVE_PYQT4)
MESSAGE (STATUS "PyQt4 not found!")
ENDIF (HAVE_PYQT4)

# if SIP and PyQt4 are found, enable bindings
IF (SIP_IS_GOOD AND PYQT_IS_GOOD)
SET (HAVE_PYTHON TRUE)
MESSAGE(STATUS "Python bindings enabled")
ELSE (SIP_IS_GOOD AND PYQT_IS_GOOD)
SET (HAVE_PYTHON FALSE)
MESSAGE(STATUS "Python bindings disabled due dependency problems!")
ENDIF (SIP_IS_GOOD AND PYQT_IS_GOOD)

ELSE (WITH_BINDINGS)
MESSAGE(STATUS "Python bindings disabled")
ENDIF (WITH_BINDINGS)

ENDIF (PYTHON_LIBRARIES AND PYTHON_INCLUDE_PATH)

0 comments on commit 66a2685

Please sign in to comment.
You can’t perform that action at this time.