PythonQt.cmake 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #
  2. # PythonQt
  3. #
  4. ctkMacroShouldAddExternalproject(PYTHONQT_LIBRARIES add_project)
  5. if(${add_project})
  6. # Sanity checks
  7. if(DEFINED PYTHONQT_INSTALL_DIR AND NOT EXISTS ${PYTHONQT_INSTALL_DIR})
  8. message(FATAL_ERROR "PYTHONQT_INSTALL_DIR variable is defined but corresponds to non-existing directory")
  9. endif()
  10. set(PythonQt_enabling_variable PYTHONQT_LIBRARIES)
  11. set(proj PythonQt)
  12. set(proj_DEPENDENCIES)
  13. list(APPEND CTK_DEPENDENCIES ${proj})
  14. set(${PythonQt_enabling_variable}_INCLUDE_DIRS PYTHONQT_INCLUDE_DIR PYTHON_INCLUDE_DIRS)
  15. set(${PythonQt_enabling_variable}_FIND_PACKAGE_CMD PythonQt)
  16. if(CTK_SUPERBUILD)
  17. if(NOT DEFINED PYTHONQT_INSTALL_DIR)
  18. # message(STATUS "Adding project:${proj}")
  19. set(ep_PythonQt_args)
  20. # Should PythonQt use VTK
  21. if(CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
  22. list(APPEND proj_DEPENDENCIES VTK)
  23. endif()
  24. # Enable Qt libraries PythonQt wrapping if required
  25. if (CTK_QT_VERSION VERSION_GREATER "4")
  26. list(APPEND ep_PythonQt_args
  27. -DPythonQt_QT_VERSION:STRING=${CTK_QT_VERSION}
  28. -DCMAKE_PREFIX_PATH:STRING=${CMAKE_PREFIX_PATH}
  29. )
  30. set(qtlibs Core Gui Widgets Network OpenGL PrintSupport Sql Svg UiTools WebKit WebKitWidgets Xml)
  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. foreach(qtlib All ${qtlibs})
  38. string(TOUPPER ${qtlib} qtlib_uppercase)
  39. list(APPEND ep_PythonQt_args -DPythonQt_Wrap_Qt${qtlib}:BOOL=${CTK_LIB_Scripting/Python/Core_PYTHONQT_WRAP_QT${qtlib_uppercase}})
  40. endforeach()
  41. # Force wrap option to ON if WRAP_QTALL was set to ON
  42. if(${CTK_LIB_Scripting/Python/Core_PYTHONQT_WRAP_QTALL})
  43. foreach(qtlib ${qtlibs})
  44. string(TOUPPER ${qtlib} qtlib_uppercase)
  45. 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)
  46. endforeach()
  47. endif()
  48. # Python is required
  49. find_package(PythonLibs)
  50. if(NOT PYTHONLIBS_FOUND)
  51. message(FATAL_ERROR "error: Python is required to build ${PROJECT_NAME}")
  52. endif()
  53. set(revision_tag 42864bb4747ea1442429a6bc4c2a665bcb011cc9)
  54. if(${proj}_REVISION_TAG)
  55. set(revision_tag ${${proj}_REVISION_TAG})
  56. endif()
  57. set(location_args )
  58. if(${proj}_URL)
  59. set(location_args URL ${${proj}_URL})
  60. elseif(${proj}_GIT_REPOSITORY)
  61. set(location_args GIT_REPOSITORY ${${proj}_GIT_REPOSITORY}
  62. GIT_TAG ${revision_tag})
  63. else()
  64. set(location_args GIT_REPOSITORY "${git_protocol}://github.com/commontk/PythonQt.git"
  65. GIT_TAG ${revision_tag})
  66. endif()
  67. ExternalProject_Add(${proj}
  68. SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
  69. BINARY_DIR ${proj}-build
  70. PREFIX ${proj}${ep_suffix}
  71. ${location_args}
  72. CMAKE_GENERATOR ${gen}
  73. UPDATE_COMMAND ""
  74. BUILD_COMMAND ""
  75. CMAKE_CACHE_ARGS
  76. ${ep_common_cache_args}
  77. -DPYTHON_INCLUDE_DIR:PATH=${PYTHON_INCLUDE_DIR}
  78. -DPYTHON_LIBRARY:FILEPATH=${PYTHON_LIBRARY}
  79. ${ep_PythonQt_args}
  80. DEPENDS
  81. ${proj_DEPENDENCIES}
  82. )
  83. set(PYTHONQT_INSTALL_DIR ${ep_install_dir})
  84. # Since the full path of PythonQt library is used, there is not need to add
  85. # its corresponding library output directory to CTK_EXTERNAL_LIBRARY_DIRS
  86. else()
  87. ctkMacroEmptyExternalproject(${proj} "${proj_DEPENDENCIES}")
  88. endif()
  89. list(APPEND CTK_SUPERBUILD_EP_VARS
  90. PYTHONQT_INSTALL_DIR:PATH
  91. PYTHON_EXECUTABLE:FILEPATH # FindPythonInterp expects PYTHON_EXECUTABLE variable to be defined
  92. PYTHON_INCLUDE_DIR:PATH # FindPythonQt expects PYTHON_INCLUDE_DIR variable to be defined
  93. PYTHON_LIBRARY:FILEPATH # FindPythonQt expects PYTHON_LIBRARY variable to be defined
  94. )
  95. endif()
  96. endif()