FindPythonQt.cmake 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # Find PythonQt
  2. #
  3. # Sets PYTHONQT_FOUND, PYTHONQT_INCLUDE_DIR, PYTHONQT_LIBRARY, PYTHONQT_LIBRARIES
  4. #
  5. # Python is required
  6. find_package(PythonLibs)
  7. if(NOT PYTHONLIBS_FOUND)
  8. message(FATAL_ERROR "error: Python is required to build PythonQt")
  9. endif()
  10. if(NOT EXISTS "${PYTHONQT_INSTALL_DIR}")
  11. find_path(PYTHONQT_INSTALL_DIR include/PythonQt/PythonQt.h DOC "Directory where PythonQt was installed.")
  12. endif()
  13. # XXX Since PythonQt 3.0 is not yet cmakeified, depending
  14. # on how PythonQt is built, headers will not always be
  15. # installed in "include/PythonQt". That is why "src"
  16. # is added as an option. See [1] for more details.
  17. # [1] https://github.com/commontk/CTK/pull/538#issuecomment-86106367
  18. find_path(PYTHONQT_INCLUDE_DIR PythonQt.h
  19. PATHS "${PYTHONQT_INSTALL_DIR}/include/PythonQt"
  20. "${PYTHONQT_INSTALL_DIR}/src"
  21. DOC "Path to the PythonQt include directory")
  22. # Minimum v3.1 is needed
  23. find_library(PYTHONQT_LIBRARY_RELEASE PythonQt PATHS "${PYTHONQT_INSTALL_DIR}/lib" DOC "The PythonQt library.")
  24. find_library(PYTHONQT_LIBRARY_DEBUG NAMES PythonQt${CTK_CMAKE_DEBUG_POSTFIX} PythonQt${CMAKE_DEBUG_POSTFIX} PythonQt PATHS "${PYTHONQT_INSTALL_DIR}/lib" DOC "The PythonQt library.")
  25. find_library(PYTHONQT_QTALL_LIBRARY_RELEASE PythonQt_QtAll PATHS "${PYTHONQT_INSTALL_DIR}/lib" DOC "Full Qt bindings for the PythonQt library.")
  26. find_library(PYTHONQT_QTALL_LIBRARY_DEBUG NAMES PythonQt_QtAll${CTK_CMAKE_DEBUG_POSTFIX} PythonQt_QtAll${CMAKE_DEBUG_POSTFIX} PythonQt_QtAll PATHS "${PYTHONQT_INSTALL_DIR}/lib" DOC "Full Qt bindings for the PythonQt library.")
  27. # Also check for v3.2+
  28. find_library(PYTHONQT_LIBRARY_RELEASE PythonQt-Qt5-Python3 PATHS "${PYTHONQT_INSTALL_DIR}/lib" DOC "The PythonQt library.")
  29. find_library(PYTHONQT_LIBRARY_DEBUG NAMES PythonQt-Qt5-Python3${CTK_CMAKE_DEBUG_POSTFIX} PythonQt-Qt5-Python3${CMAKE_DEBUG_POSTFIX} PythonQt-Qt5-Python3 PATHS "${PYTHONQT_INSTALL_DIR}/lib" DOC "The PythonQt library.")
  30. find_library(PYTHONQT_QTALL_LIBRARY_RELEASE PythonQt_QtAll-Qt5-Python3 PATHS "${PYTHONQT_INSTALL_DIR}/lib" DOC "Full Qt bindings for the PythonQt library.")
  31. find_library(PYTHONQT_QTALL_LIBRARY_DEBUG NAMES PythonQt_QtAll-Qt5-Python3${CTK_CMAKE_DEBUG_POSTFIX} PythonQt_QtAll-Qt5-Python3${CMAKE_DEBUG_POSTFIX} PythonQt_QtAll-Qt5-Python3 PATHS "${PYTHONQT_INSTALL_DIR}/lib" DOC "Full Qt bindings for the PythonQt library.")
  32. set(PYTHONQT_LIBRARY)
  33. if(PYTHONQT_LIBRARY_RELEASE)
  34. list(APPEND PYTHONQT_LIBRARY optimized ${PYTHONQT_LIBRARY_RELEASE})
  35. endif()
  36. if(PYTHONQT_LIBRARY_DEBUG)
  37. list(APPEND PYTHONQT_LIBRARY debug ${PYTHONQT_LIBRARY_DEBUG})
  38. endif()
  39. set(PYTHONQT_QTALL_LIBRARY)
  40. if(PYTHONQT_QTALL_LIBRARY_RELEASE)
  41. list(APPEND PYTHONQT_QTALL_LIBRARY optimized ${PYTHONQT_QTALL_LIBRARY_RELEASE})
  42. endif()
  43. if(PYTHONQT_QTALL_LIBRARY_DEBUG)
  44. list(APPEND PYTHONQT_QTALL_LIBRARY debug ${PYTHONQT_QTALL_LIBRARY_DEBUG})
  45. endif()
  46. mark_as_advanced(PYTHONQT_INSTALL_DIR)
  47. mark_as_advanced(PYTHONQT_INCLUDE_DIR)
  48. mark_as_advanced(PYTHONQT_LIBRARY_RELEASE)
  49. mark_as_advanced(PYTHONQT_LIBRARY_DEBUG)
  50. mark_as_advanced(PYTHONQT_QTALL_LIBRARY_RELEASE)
  51. mark_as_advanced(PYTHONQT_QTALL_LIBRARY_DEBUG)
  52. # On linux, also find libutil
  53. if(UNIX AND NOT APPLE)
  54. find_library(PYTHONQT_LIBUTIL util)
  55. mark_as_advanced(PYTHONQT_LIBUTIL)
  56. endif()
  57. # All upper case _FOUND variable is maintained for backwards compatibility.
  58. set(PYTHONQT_FOUND 0)
  59. set(PythonQt_FOUND 0)
  60. if(PYTHONQT_INCLUDE_DIR AND PYTHONQT_LIBRARY AND PYTHONQT_QTALL_LIBRARY)
  61. # Currently CMake'ified PythonQt only supports building against a python Release build.
  62. # This applies independently of CTK build type (Release, Debug, ...)
  63. add_definitions(-DPYTHONQT_USE_RELEASE_PYTHON_FALLBACK)
  64. set(PYTHONQT_FOUND 1)
  65. set(PythonQt_FOUND ${PYTHONQT_FOUND})
  66. set(PYTHONQT_LIBRARIES ${PYTHONQT_LIBRARY} ${PYTHONQT_LIBUTIL} ${PYTHONQT_QTALL_LIBRARY})
  67. endif()