FindPythonQt.cmake 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. # Find PythonQt
  2. #
  3. # Sets PYTHONQT_FOUND, PYTHONQT_INCLUDE_DIR, PYTHONQT_LIBRARY, PYTHONQT_LIBRARIES
  4. #
  5. # Also sets PYTHONQT_INCLUDE_DIRS to add whatever directories
  6. # that are needed for extensions.
  7. #
  8. # Python is required
  9. find_package(PythonLibs)
  10. if(NOT PYTHONLIBS_FOUND)
  11. message(FATAL_ERROR "error: Python is required to build PythonQt")
  12. endif()
  13. # Cut X.Y[.Z] down to just X.Y
  14. string(REGEX REPLACE
  15. "^([0-9][0-9]*)\.([0-9][0-9]*)"
  16. "\\1.\\2@"
  17. _PYTHONLIBS_MAJMIN
  18. ${PYTHONLIBS_VERSION_STRING}
  19. )
  20. string(REGEX REPLACE
  21. "@.*"
  22. ""
  23. PYTHONLIBS_MAJMIN
  24. ${_PYTHONLIBS_MAJMIN}
  25. )
  26. if(NOT EXISTS "${PYTHONQT_INSTALL_DIR}")
  27. find_path(PYTHONQT_INSTALL_DIR
  28. NAMES
  29. include/PythonQt/PythonQt.h
  30. include/PythonQt5/PythonQt.h
  31. DOC "Directory where PythonQt was installed.")
  32. endif()
  33. # XXX Since PythonQt 3.0 is not yet cmakeified, depending
  34. # on how PythonQt is built, headers will not always be
  35. # installed in "include/PythonQt". That is why "src"
  36. # is added as an option. See [1] for more details.
  37. # [1] https://github.com/commontk/CTK/pull/538#issuecomment-86106367
  38. find_path(PYTHONQT_INCLUDE_DIR PythonQt.h
  39. PATHS
  40. "${PYTHONQT_INSTALL_DIR}/include/PythonQt"
  41. "${PYTHONQT_INSTALL_DIR}/include/PythonQt5"
  42. "${PYTHONQT_INSTALL_DIR}/src"
  43. DOC "Path to the PythonQt include directory")
  44. find_path(PYTHONQT_ALL_INCLUDE_DIR PythonQt_QtAll.h
  45. PATHS
  46. "${PYTHONQT_INCLUDE_DIR}"
  47. "${PYTHONQT_INSTALL_DIR}"
  48. PATH_SUFFIXES
  49. "extensions/PythonQt_QtAll"
  50. "src"
  51. DOC "Path to the PythonQt 'all' header")
  52. if ( NOT PythonQt_FIND_QUIETLY )
  53. message( STATUS "Searching for PythonQt (PythonLibs ${PYTHONLIBS_MAJMIN}) .." )
  54. if ( PYTHONQT_INCLUDE_DIR )
  55. message( STATUS " .. found include ${PYTHONQT_INCLUDE_DIR}" )
  56. message( STATUS " .. found all include ${PYTHONQT_ALL_INCLUDE_DIR}" )
  57. endif()
  58. endif()
  59. # Minimum v3.1 is needed
  60. find_library(PYTHONQT_LIBRARY_RELEASE
  61. NAMES
  62. PythonQt-Qt5-Python${PYTHONLIBS_MAJMIN}
  63. PythonQt-Qt5-Python3
  64. PythonQt
  65. PATHS "${PYTHONQT_INSTALL_DIR}/lib"
  66. DOC "The PythonQt library."
  67. )
  68. find_library(PYTHONQT_LIBRARY_DEBUG
  69. NAMES
  70. PythonQt-Qt5-Python${PYTHONLIBS_MAJMIN}JMIN${CTK_CMAKE_DEBUG_POSTFIX}
  71. PythonQt-Qt5-Python${PYTHONLIBS_MAJMIN}${CMAKE_DEBUG_POSTFIX}
  72. PythonQt-Qt5-Python${PYTHONLIBS_MAJMIN}
  73. PythonQt-Qt5-Python3${CTK_CMAKE_DEBUG_POSTFIX}
  74. PythonQt-Qt5-Python3${CMAKE_DEBUG_POSTFIX}
  75. PythonQt-Qt5-Python3
  76. PythonQt${CTK_CMAKE_DEBUG_POSTFIX}
  77. PythonQt${CMAKE_DEBUG_POSTFIX}
  78. PythonQt
  79. PATHS "${PYTHONQT_INSTALL_DIR}/lib"
  80. DOC "The PythonQt library (debug build)."
  81. )
  82. find_library(PYTHONQT_QTALL_LIBRARY_RELEASE
  83. NAMES
  84. PythonQt_QtAll-Qt5-Python${PYTHONLIBS_MAJMIN}
  85. PythonQt_QtAll-Qt5-Python3
  86. PythonQt_QtAll
  87. PATHS "${PYTHONQT_INSTALL_DIR}/lib"
  88. DOC "Full Qt bindings for the PythonQt library."
  89. )
  90. find_library(PYTHONQT_QTALL_LIBRARY_DEBUG
  91. NAMES
  92. PythonQt_QtAll-Qt5-Python${PYTHONLIBS_MAJMIN}${CTK_CMAKE_DEBUG_POSTFIX}
  93. PythonQt_QtAll-Qt5-Python${PYTHONLIBS_MAJMIN}${CMAKE_DEBUG_POSTFIX}
  94. PythonQt_QtAll-Qt5-Python${PYTHONLIBS_MAJMIN}
  95. PythonQt_QtAll-Qt5-Python3${CTK_CMAKE_DEBUG_POSTFIX}
  96. PythonQt_QtAll-Qt5-Python3${CMAKE_DEBUG_POSTFIX}
  97. PythonQt_QtAll-Qt5-Python3
  98. PythonQt_QtAll${CTK_CMAKE_DEBUG_POSTFIX}
  99. PythonQt_QtAll${CMAKE_DEBUG_POSTFIX}
  100. PythonQt_QtAll
  101. PATHS "${PYTHONQT_INSTALL_DIR}/lib"
  102. DOC "Full Qt bindings for the PythonQt library (debug build)."
  103. )
  104. set(PYTHONQT_LIBRARY)
  105. if(PYTHONQT_LIBRARY_RELEASE)
  106. list(APPEND PYTHONQT_LIBRARY optimized ${PYTHONQT_LIBRARY_RELEASE})
  107. endif()
  108. if(PYTHONQT_LIBRARY_DEBUG)
  109. list(APPEND PYTHONQT_LIBRARY debug ${PYTHONQT_LIBRARY_DEBUG})
  110. endif()
  111. set(PYTHONQT_QTALL_LIBRARY)
  112. if(PYTHONQT_QTALL_LIBRARY_RELEASE)
  113. list(APPEND PYTHONQT_QTALL_LIBRARY optimized ${PYTHONQT_QTALL_LIBRARY_RELEASE})
  114. endif()
  115. if(PYTHONQT_QTALL_LIBRARY_DEBUG)
  116. list(APPEND PYTHONQT_QTALL_LIBRARY debug ${PYTHONQT_QTALL_LIBRARY_DEBUG})
  117. endif()
  118. if ( NOT PythonQt_FIND_QUIETLY )
  119. if ( PYTHONQT_LIBRARY )
  120. message( STATUS " .. found library ${PYTHONQT_LIBRARY}" )
  121. endif()
  122. if ( PYTHONQT_QTALL_LIBRARY )
  123. message( STATUS " .. found qtall ${PYTHONQT_QTALL_LIBRARY}" )
  124. endif()
  125. endif()
  126. mark_as_advanced(PYTHONQT_INSTALL_DIR)
  127. mark_as_advanced(PYTHONQT_INCLUDE_DIR)
  128. mark_as_advanced(PYTHONQT_LIBRARY_RELEASE)
  129. mark_as_advanced(PYTHONQT_LIBRARY_DEBUG)
  130. mark_as_advanced(PYTHONQT_QTALL_LIBRARY_RELEASE)
  131. mark_as_advanced(PYTHONQT_QTALL_LIBRARY_DEBUG)
  132. # On linux, also find libutil
  133. if(UNIX AND NOT APPLE)
  134. find_library(PYTHONQT_LIBUTIL util)
  135. mark_as_advanced(PYTHONQT_LIBUTIL)
  136. endif()
  137. # All upper case _FOUND variable is maintained for backwards compatibility.
  138. set(PYTHONQT_FOUND 0)
  139. set(PythonQt_FOUND 0)
  140. if(PYTHONQT_INCLUDE_DIR AND PYTHONQT_LIBRARY AND PYTHONQT_QTALL_LIBRARY)
  141. # Currently CMake'ified PythonQt only supports building against a python Release build.
  142. # This applies independently of CTK build type (Release, Debug, ...)
  143. add_definitions(-DPYTHONQT_USE_RELEASE_PYTHON_FALLBACK)
  144. set(PYTHONQT_FOUND 1)
  145. set(PythonQt_FOUND ${PYTHONQT_FOUND})
  146. set(PYTHONQT_LIBRARIES ${PYTHONQT_LIBRARY} ${PYTHONQT_LIBUTIL} ${PYTHONQT_QTALL_LIBRARY})
  147. set(PYTHONQT_INCLUDE_DIRS ${PYTHONQT_INCLUDE_DIR})
  148. if(PYTHONQT_ALL_INCLUDE_DIR)
  149. list(APPEND PYTHONQT_INCLUDE_DIRS ${PYTHONQT_ALL_INCLUDE_DIR})
  150. endif()
  151. elseif(NOT PythonQt_FIND_QUIETLY)
  152. set(_missing "")
  153. if (NOT PYTHONQT_INCLUDE_DIR)
  154. list(APPEND _missing "includes")
  155. endif()
  156. if (NOT PYTHONQT_LIBRARY)
  157. list(APPEND _missing "library")
  158. endif()
  159. if (NOT PYTHONQT_QTALL_LIBRARY)
  160. list(APPEND _missing "qtall")
  161. endif()
  162. message(STATUS "PythonQt not found, missing components ${_missing}")
  163. endif()