PythonQt.cmake 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. set(qtlibs core gui network opengl sql svg uitools webkit xml)
  26. foreach(qtlib All ${qtlibs})
  27. string(TOUPPER ${qtlib} qtlib_uppercase)
  28. list(APPEND ep_PythonQt_args -DPythonQt_Wrap_Qt${qtlib}:BOOL=${CTK_LIB_Scripting/Python/Core_PYTHONQT_WRAP_QT${qtlib_uppercase}})
  29. endforeach()
  30. # Force wrap option to ON if WRAP_QTALL was set to ON
  31. if(${CTK_LIB_Scripting/Python/Core_PYTHONQT_WRAP_QTALL})
  32. foreach(qtlib ${qtlibs})
  33. string(TOUPPER ${qtlib} qtlib_uppercase)
  34. 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)
  35. endforeach()
  36. endif()
  37. # Python is required
  38. find_package(PythonLibs)
  39. if(NOT PYTHONLIBS_FOUND)
  40. message(FATAL_ERROR "error: Python is required to build ${PROJECT_NAME}")
  41. endif()
  42. set(revision_tag e1f1c77d9675c3c5fb1cba19d2a32ace483eda2c)
  43. if(${proj}_REVISION_TAG)
  44. set(revision_tag ${${proj}_REVISION_TAG})
  45. endif()
  46. set(location_args )
  47. if(${proj}_URL)
  48. set(location_args URL ${${proj}_URL})
  49. elseif(${proj}_GIT_REPOSITORY)
  50. set(location_args GIT_REPOSITORY ${${proj}_GIT_REPOSITORY}
  51. GIT_TAG ${revision_tag})
  52. else()
  53. set(location_args GIT_REPOSITORY "${git_protocol}://github.com/commontk/PythonQt.git"
  54. GIT_TAG ${revision_tag})
  55. endif()
  56. ExternalProject_Add(${proj}
  57. SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
  58. BINARY_DIR ${proj}-build
  59. PREFIX ${proj}${ep_suffix}
  60. ${location_args}
  61. CMAKE_GENERATOR ${gen}
  62. UPDATE_COMMAND ""
  63. BUILD_COMMAND ""
  64. CMAKE_CACHE_ARGS
  65. ${ep_common_cache_args}
  66. -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
  67. -DPYTHON_INCLUDE_DIR:PATH=${PYTHON_INCLUDE_DIR}
  68. -DPYTHON_LIBRARY:FILEPATH=${PYTHON_LIBRARY}
  69. ${ep_PythonQt_args}
  70. DEPENDS
  71. ${proj_DEPENDENCIES}
  72. )
  73. set(PYTHONQT_INSTALL_DIR ${ep_install_dir})
  74. # Since the full path of PythonQt library is used, there is not need to add
  75. # its corresponding library output directory to CTK_EXTERNAL_LIBRARY_DIRS
  76. else()
  77. ctkMacroEmptyExternalproject(${proj} "${proj_DEPENDENCIES}")
  78. endif()
  79. list(APPEND CTK_SUPERBUILD_EP_VARS
  80. PYTHONQT_INSTALL_DIR:PATH
  81. PYTHON_EXECUTABLE:FILEPATH # FindPythonInterp expects PYTHON_EXECUTABLE variable to be defined
  82. PYTHON_INCLUDE_DIR:PATH # FindPythonQt expects PYTHON_INCLUDE_DIR variable to be defined
  83. PYTHON_LIBRARY:FILEPATH # FindPythonQt expects PYTHON_LIBRARY variable to be defined
  84. )
  85. endif()
  86. endif()