CMakeLists.txt 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # Build Python bindings
  2. cmake_minimum_required(VERSION 2.8)
  3. PROJECT(pyfresh)
  4. set(CMAKE_MODULE_PATH
  5. ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
  6. find_package(PythonInterp REQUIRED)
  7. find_package(PythonLibrary REQUIRED)
  8. include(PythonMacros)
  9. find_package (Qt4 REQUIRED)
  10. set(QT_USE_QTXML true)
  11. set(QT_USE_QTNETWORK true)
  12. include (${QT_USE_FILE})
  13. find_package(PyQt4 REQUIRED)
  14. if (NOT EXISTS ${PYQT4_SIP_DIR}/QtCore/QtCoremod.sip)
  15. message(FATAL_ERROR "PyQt4 development files not found. Install it from python-qt4-dev package, or find other way, and share it to the fresh authors for update this message")
  16. endif (NOT EXISTS ${PYQT4_SIP_DIR}/QtCore/QtCoremod.sip)
  17. find_package(SIP REQUIRED)
  18. include(SIPMacros)
  19. # Set a a PYTHON_3 flag.
  20. if(${PYTHON_SHORT_VERSION} MATCHES "^3")
  21. set(PYTHON_3 TRUE)
  22. else(${PYTHON_SHORT_VERSION} MATCHES "^3")
  23. set(PYTHON_3 FALSE)
  24. endif(${PYTHON_SHORT_VERSION} MATCHES "^3")
  25. include_directories(
  26. ${PYTHON_INCLUDE_PATH}
  27. ${SIP_INCLUDE_DIR}
  28. ${CMAKE_SOURCE_DIR}/../src
  29. ${CMAKE_SOURCE_DIR}/../build
  30. )
  31. set(SIP_INCLUDES ${PYQT4_SIP_DIR} sip)
  32. if(WIN32)
  33. set(SIP_TAGS ALL WS_WIN ${PYQT4_VERSION_TAG})
  34. else(WIN32)
  35. set(SIP_TAGS ALL WS_X11 ${PYQT4_VERSION_TAG})
  36. endif(WIN32)
  37. set(SIP_DISABLE_FEATURES VendorID PyQt_NoPrintRangeBug)
  38. # Use an extra option when compiling on Python 3.
  39. if(PYTHON_3)
  40. set(SIP_EXTRA_OPTIONS -g -x Py_v3)
  41. else(PYTHON_3)
  42. set(SIP_EXTRA_OPTIONS -g)
  43. endif(PYTHON_3)
  44. file(GLOB_RECURSE ALL_SIP_FILES *.sip)
  45. set(SIP_EXTRA_FILES_DEPEND ${ALL_SIP_FILES})
  46. # SIP macros installs module to the PYTHON_SITE_PACKAGES_INSTALL_DIR
  47. # We need redefine this variable to install fresh to PyQt4 module
  48. execute_process(COMMAND ${PYTHON_EXECUTABLE}
  49. "-c"
  50. "import os; import PyQt4; print os.path.dirname(PyQt4.__file__)"
  51. OUTPUT_VARIABLE PYTHON_SITE_PACKAGES_INSTALL_DIR
  52. OUTPUT_STRIP_TRAILING_WHITESPACE)
  53. add_sip_python_module(fresh fresh.sip
  54. fresh
  55. ${QT_CORE_LIBRARY}
  56. ${QT_GUI_LIBRARY}
  57. ${QT_XML_LIBRARY}
  58. ${QT_NETWORK_LIBRARY})
  59. message(STATUS
  60. "PYTHON_SITE_PACKAGES_INSTALL_DIR:${PYTHON_SITE_PACKAGES_INSTALL_DIR}")
  61. # Install the .sip files for anyone that wants to build bindings on top of fresh
  62. file(GLOB_RECURSE SIP_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.sip)
  63. install(FILES ${SIP_FILES}
  64. DESTINATION ${SIP_DEFAULT_SIP_DIR}/PyQt4/fresh)