PythonQt.cmake 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #
  2. # PythonQt
  3. #
  4. set(proj PythonQt)
  5. set(${proj}_DEPENDENCIES "")
  6. ExternalProject_Include_Dependencies(${proj}
  7. PROJECT_VAR proj
  8. DEPENDS_VAR ${proj}_DEPENDENCIES
  9. EP_ARGS_VAR ${proj}_EXTERNAL_PROJECT_ARGS
  10. USE_SYSTEM_VAR ${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj}
  11. )
  12. if(${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj})
  13. message(FATAL_ERROR "Enabling ${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj} is not supported !")
  14. endif()
  15. # Sanity checks
  16. if(DEFINED PYTHONQT_INSTALL_DIR AND NOT EXISTS ${PYTHONQT_INSTALL_DIR})
  17. message(FATAL_ERROR "PYTHONQT_INSTALL_DIR variable is defined but corresponds to non-existing directory")
  18. endif()
  19. if(NOT DEFINED PYTHONQT_INSTALL_DIR)
  20. set(ep_PythonQt_args)
  21. # Should PythonQt use VTK
  22. if(CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
  23. list(APPEND proj_DEPENDENCIES VTK)
  24. endif()
  25. # Enable Qt libraries PythonQt wrapping if required
  26. if (CTK_QT_VERSION VERSION_GREATER "4")
  27. set(qtlibs Core Gui Widgets Network OpenGL PrintSupport Sql Svg UiTools WebKit WebKitWidgets Xml)
  28. list(APPEND ep_PythonQt_args
  29. -DQt5_DIR:PATH=${Qt5_DIR}
  30. )
  31. else()
  32. list(APPEND ep_PythonQt_args
  33. -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
  34. )
  35. set(qtlibs core gui network opengl sql svg uitools webkit xml)
  36. endif()
  37. # Set desired qt version for PythonQt
  38. list(APPEND ep_PythonQt_args -DPythonQt_QT_VERSION:STRING=${CTK_QT_VERSION})
  39. foreach(qtlib All ${qtlibs})
  40. string(TOUPPER ${qtlib} qtlib_uppercase)
  41. list(APPEND ep_PythonQt_args -DPythonQt_Wrap_Qt${qtlib}:BOOL=${CTK_LIB_Scripting/Python/Core_PYTHONQT_WRAP_QT${qtlib_uppercase}})
  42. endforeach()
  43. # Force wrap option to ON if WRAP_QTALL was set to ON
  44. if(${CTK_LIB_Scripting/Python/Core_PYTHONQT_WRAP_QTALL})
  45. foreach(qtlib ${qtlibs})
  46. string(TOUPPER ${qtlib} qtlib_uppercase)
  47. set(CTK_LIB_Scripting/Python/Core_PYTHONQT_WRAP_QT${qtlib_uppercase} ON CACHE BOOL "Enable Scripting/Python/Core Library PYTHONQT_WRAP_QT${qtlib_uppercase} option" FORCE)
  48. endforeach()
  49. endif()
  50. # Python is required
  51. find_package(PythonLibs)
  52. if(NOT PYTHONLIBS_FOUND)
  53. message(FATAL_ERROR "error: Python is required to build ${PROJECT_NAME}")
  54. endif()
  55. set(revision_tag 1afe4f8906345063b25047652e8962f641010a55)
  56. if(${proj}_REVISION_TAG)
  57. set(revision_tag ${${proj}_REVISION_TAG})
  58. endif()
  59. set(location_args )
  60. if(${proj}_URL)
  61. set(location_args URL ${${proj}_URL})
  62. elseif(${proj}_GIT_REPOSITORY)
  63. set(location_args GIT_REPOSITORY ${${proj}_GIT_REPOSITORY}
  64. GIT_TAG ${revision_tag})
  65. else()
  66. set(location_args GIT_REPOSITORY "${git_protocol}://github.com/commontk/PythonQt.git"
  67. GIT_TAG ${revision_tag})
  68. endif()
  69. ExternalProject_Add(${proj}
  70. ${${proj}_EXTERNAL_PROJECT_ARGS}
  71. SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
  72. BINARY_DIR ${proj}-build
  73. PREFIX ${proj}${ep_suffix}
  74. ${location_args}
  75. BUILD_COMMAND ""
  76. CMAKE_CACHE_ARGS
  77. ${ep_common_cache_args}
  78. -DPythonQt_QT_VERSION:STRING=${CTK_QT_VERSION}
  79. -DPYTHON_INCLUDE_DIR:PATH=${PYTHON_INCLUDE_DIR}
  80. -DPYTHON_INCLUDE_DIR2:PATH=${PYTHON_INCLUDE_DIR2}
  81. -DPYTHON_LIBRARY:FILEPATH=${PYTHON_LIBRARY}
  82. ${ep_PythonQt_args}
  83. DEPENDS
  84. ${${proj}_DEPENDENCIES}
  85. )
  86. set(PYTHONQT_INSTALL_DIR ${ep_install_dir})
  87. else()
  88. ExternalProject_Add_Empty(${proj} DEPENDS ${${proj}_DEPENDENCIES})
  89. endif()
  90. set(PythonQt_DIR ${PYTHONQT_INSTALL_DIR})
  91. mark_as_superbuild(
  92. VARS
  93. PYTHONQT_INSTALL_DIR:PATH
  94. PYTHON_EXECUTABLE:FILEPATH # FindPythonInterp expects PYTHON_EXECUTABLE variable to be defined
  95. PYTHON_INCLUDE_DIR:PATH # FindPythonQt expects PYTHON_INCLUDE_DIR variable to be defined
  96. PYTHON_INCLUDE_DIR2:PATH
  97. PYTHON_LIBRARY:FILEPATH # FindPythonQt expects PYTHON_LIBRARY variable to be defined
  98. LABELS "FIND_PACKAGE_VARS"
  99. )
  100. mark_as_superbuild(
  101. VARS PythonQt_DIR:PATH
  102. LABELS "FIND_PACKAGE"
  103. )